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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Hacl.Chacha20.Vec256.fst | Hacl.Chacha20.Vec256.chacha20_decrypt_256 | val chacha20_decrypt_256 : Hacl.Meta.Chacha20.Vec.vec_chacha20_decrypt_higher_t Prims.l_True | let chacha20_decrypt_256 = vec_chacha20_decrypt_higher #8 True chacha20_init_256 chacha20_core_256 | {
"file_name": "code/chacha20/Hacl.Chacha20.Vec256.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 98,
"end_line": 16,
"start_col": 0,
"start_line": 16
} | module Hacl.Chacha20.Vec256
open Hacl.Meta.Chacha20.Vec
[@CInline]
private
let double_round_256 = Hacl.Impl.Chacha20.Core32xN.double_round #8
[@CInline]
private
let chacha20_core_256 = vec_chacha20_core_higher #8 True double_round_256
[@CInline]
private
let chacha20_init_256 = Hacl.Impl.Chacha20.Vec.chacha20_init #8 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Vec.fst.checked",
"Hacl.Impl.Chacha20.Core32xN.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Chacha20.Vec256.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Meta.Chacha20.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Meta.Chacha20.Vec.vec_chacha20_decrypt_higher_t Prims.l_True | Prims.Tot | [
"total"
] | [] | [
"Hacl.Meta.Chacha20.Vec.vec_chacha20_decrypt_higher",
"Prims.l_True",
"Hacl.Chacha20.Vec256.chacha20_init_256",
"Hacl.Chacha20.Vec256.chacha20_core_256"
] | [] | false | false | false | false | false | let chacha20_decrypt_256 =
| vec_chacha20_decrypt_higher #8 True chacha20_init_256 chacha20_core_256 | false |
|
Vale.Stdcalls.X64.Fsqr.fsti | Vale.Stdcalls.X64.Fsqr.as_t | val as_t (#a: Type) (x: normal a) : a | val as_t (#a: Type) (x: normal a) : a | let as_t (#a:Type) (x:normal a) : a = x | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fsqr.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 34,
"start_col": 0,
"start_line": 34
} | module Vale.Stdcalls.X64.Fsqr
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fsqr.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Vale.Interop.Base.normal a -> a | Prims.Tot | [
"total"
] | [] | [
"Vale.Interop.Base.normal"
] | [] | false | false | false | true | false | let as_t (#a: Type) (x: normal a) : a =
| x | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.both | val both : x: (Vale.Transformers.Locations.locations * Vale.Transformers.Locations.locations)
-> Prims.list Vale.Transformers.Locations.location | let both (x: locations & locations) =
let a, b = x in
a `L.append` b | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 54,
"start_col": 0,
"start_line": 52
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf] | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: (Vale.Transformers.Locations.locations * Vale.Transformers.Locations.locations)
-> Prims.list Vale.Transformers.Locations.location | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Vale.Transformers.Locations.locations",
"FStar.List.Tot.Base.append",
"Vale.Transformers.Locations.location",
"Prims.list"
] | [] | false | false | false | true | false | let both (x: locations & locations) =
| let a, b = x in
a `L.append` b | false |
|
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.read_set | val read_set (i: instr_t_record) (oprs: instr_operands_t i.outs i.args) : locations | val read_set (i: instr_t_record) (oprs: instr_operands_t i.outs i.args) : locations | let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 81,
"start_col": 0,
"start_line": 80
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
i: Vale.X64.Instruction_s.instr_t_record ->
oprs:
Vale.X64.Instruction_s.instr_operands_t (InstrTypeRecord?.outs i) (InstrTypeRecord?.args i)
-> Vale.Transformers.Locations.locations | Prims.Tot | [
"total"
] | [] | [
"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.Transformers.BoundedInstructionEffects.aux_read_set1",
"Vale.Transformers.Locations.locations"
] | [] | false | false | false | false | false | let read_set (i: instr_t_record) (oprs: instr_operands_t i.outs i.args) : locations =
| aux_read_set1 i.outs i.args oprs | false |
Hacl.Impl.Curve25519.Generic.fst | Hacl.Impl.Curve25519.Generic.ladder4_ | val ladder4_:
#s:field_spec
-> k:scalar
-> q:point s
-> p01_tmp1_swap:lbuffer (limb s) (8ul *! nlimb s +! 1ul)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 q /\ live h0 p01_tmp1_swap /\ live h0 tmp2 /\
LowStar.Monotonic.Buffer.all_disjoint [loc k; loc q; loc p01_tmp1_swap; loc tmp2] /\
fget_z h0 q == 1 /\ state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
fget_xz h1 nq == S.montgomery_ladder (fget_x h0 q) (as_seq h0 k))) | val ladder4_:
#s:field_spec
-> k:scalar
-> q:point s
-> p01_tmp1_swap:lbuffer (limb s) (8ul *! nlimb s +! 1ul)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 q /\ live h0 p01_tmp1_swap /\ live h0 tmp2 /\
LowStar.Monotonic.Buffer.all_disjoint [loc k; loc q; loc p01_tmp1_swap; loc tmp2] /\
fget_z h0 q == 1 /\ state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
fget_xz h1 nq == S.montgomery_ladder (fget_x h0 q) (as_seq h0 k))) | let ladder4_ #s k q p01_tmp1_swap tmp2 =
let h0 = ST.get () in
let p01 = sub p01_tmp1_swap 0ul (4ul *! nlimb s) in
let p0 : point s = sub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let p1 : point s = sub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
assert (gsub p01_tmp1_swap 0ul (4ul *! nlimb s) == p01);
assert (gsub p01 0ul (2ul *! nlimb s) == p0);
assert (gsub p01 (2ul *! nlimb s) (2ul *! nlimb s) == p1);
ladder3_ #s q p01;
ladder2_ #s k q p01_tmp1_swap tmp2;
let h1 = ST.get () in
assert (fget_xz h1 p0 == M.montgomery_ladder1 (fget_x h0 q) (as_seq h0 k));
M.lemma_montgomery_ladder (fget_x h0 q) (as_seq h0 k) | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Generic.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 436,
"start_col": 0,
"start_line": 422
} | module Hacl.Impl.Curve25519.Generic
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Curve25519.Fields
include Hacl.Impl.Curve25519.Finv
include Hacl.Impl.Curve25519.AddAndDouble
module ST = FStar.HyperStack.ST
module BSeq = Lib.ByteSequence
module LSeq = Lib.Sequence
module C = Hacl.Impl.Curve25519.Fields.Core
module S = Spec.Curve25519
module M = Hacl.Spec.Curve25519.AddAndDouble
module Lemmas = Hacl.Spec.Curve25519.Field64.Lemmas
friend Lib.LoopCombinators
#set-options "--z3rlimit 30 --fuel 0 --ifuel 1 --using_facts_from '* -FStar.Seq -Hacl.Spec.*' --record_options"
//#set-options "--debug Hacl.Impl.Curve25519.Generic --debug_level ExtractNorm"
inline_for_extraction noextract
let scalar = lbuffer uint8 32ul
inline_for_extraction noextract
val scalar_bit:
s:scalar
-> n:size_t{v n < 256}
-> Stack uint64
(requires fun h0 -> live h0 s)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.ith_bit (as_seq h0 s) (v n) /\ v r <= 1)
let scalar_bit s n =
let h0 = ST.get () in
mod_mask_lemma ((LSeq.index (as_seq h0 s) (v n / 8)) >>. (n %. 8ul)) 1ul;
assert_norm (1 = pow2 1 - 1);
assert (v (mod_mask #U8 #SEC 1ul) == v (u8 1));
to_u64 ((s.(n /. 8ul) >>. (n %. 8ul)) &. u8 1)
inline_for_extraction noextract
val decode_point:
#s:field_spec
-> o:point s
-> i:lbuffer uint8 32ul
-> Stack unit
(requires fun h0 -> live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
state_inv_t h1 (get_x o) /\ state_inv_t h1 (get_z o) /\
fget_x h1 o == S.decodePoint (as_seq h0 i) /\ fget_z h1 o == 1)
[@ Meta.Attribute.specialize ]
let decode_point #s o i =
push_frame();
let tmp = create 4ul (u64 0) in
let h0 = ST.get () in
uints_from_bytes_le #U64 tmp i;
let h1 = ST.get () in
BSeq.uints_from_bytes_le_nat_lemma #U64 #SEC #4 (as_seq h0 i);
assert (BSeq.nat_from_intseq_le (as_seq h1 tmp) == BSeq.nat_from_bytes_le (as_seq h0 i));
let tmp3 = tmp.(3ul) in
tmp.(3ul) <- tmp3 &. u64 0x7fffffffffffffff;
mod_mask_lemma tmp3 63ul;
assert_norm (0x7fffffffffffffff = pow2 63 - 1);
assert (v (mod_mask #U64 #SEC 63ul) == v (u64 0x7fffffffffffffff));
let h2 = ST.get () in
assert (v (LSeq.index (as_seq h2 tmp) 3) < pow2 63);
Lemmas.lemma_felem64_mod255 (as_seq h1 tmp);
assert (BSeq.nat_from_intseq_le (as_seq h2 tmp) == BSeq.nat_from_bytes_le (as_seq h0 i) % pow2 255);
let x : felem s = sub o 0ul (nlimb s) in
let z : felem s = sub o (nlimb s) (nlimb s) in
set_one z;
load_felem x tmp;
pop_frame()
val encode_point:
#s:field_spec
-> o:lbuffer uint8 32ul
-> i:point s
-> Stack unit
(requires fun h0 ->
live h0 o /\ live h0 i /\ disjoint o i /\
state_inv_t h0 (get_x i) /\ state_inv_t h0 (get_z i))
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == S.encodePoint (fget_x h0 i, fget_z h0 i))
[@ Meta.Attribute.specialize ]
let encode_point #s o i =
push_frame();
let x : felem s = sub i 0ul (nlimb s) in
let z : felem s = sub i (nlimb s) (nlimb s) in
let tmp = create_felem s in
let u64s = create 4ul (u64 0) in
let tmp_w = create (2ul `FStar.UInt32.mul` ((nwide s) <: FStar.UInt32.t)) (wide_zero s) in
let h0 = ST.get () in
finv tmp z tmp_w;
fmul tmp tmp x tmp_w;
let h1 = ST.get () in
assert (feval h1 tmp == S.fmul (S.fpow (feval h0 z) (pow2 255 - 21)) (feval h0 x));
assert (feval h1 tmp == S.fmul (feval h0 x) (S.fpow (feval h0 z) (pow2 255 - 21)));
store_felem u64s tmp;
let h2 = ST.get () in
assert (as_seq h2 u64s == BSeq.nat_to_intseq_le 4 (feval h1 tmp));
uints_to_bytes_le #U64 4ul o u64s;
let h3 = ST.get () in
BSeq.uints_to_bytes_le_nat_lemma #U64 #SEC 4 (feval h1 tmp);
assert (as_seq h3 o == BSeq.nat_to_bytes_le 32 (feval h1 tmp));
pop_frame()
// TODO: why re-define the signature here?
val cswap2:
#s:field_spec
-> bit:uint64{v bit <= 1}
-> p1:felem2 s
-> p2:felem2 s
-> Stack unit
(requires fun h0 ->
live h0 p1 /\ live h0 p2 /\ disjoint p1 p2)
(ensures fun h0 _ h1 ->
modifies (loc p1 |+| loc p2) h0 h1 /\
(v bit == 1 ==> as_seq h1 p1 == as_seq h0 p2 /\ as_seq h1 p2 == as_seq h0 p1) /\
(v bit == 0 ==> as_seq h1 p1 == as_seq h0 p1 /\ as_seq h1 p2 == as_seq h0 p2) /\
(fget_xz h1 p1, fget_xz h1 p2) == S.cswap2 bit (fget_xz h0 p1) (fget_xz h0 p2))
[@ Meta.Attribute.inline_ ]
let cswap2 #s bit p0 p1 =
C.cswap2 #s bit p0 p1
val ladder_step:
#s:field_spec
-> k:scalar
-> q:point s
-> i:size_t{v i < 251}
-> p01_tmp1_swap:lbuffer (limb s) (8ul *! nlimb s +! 1ul)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 q /\ live h0 p01_tmp1_swap /\ live h0 tmp2 /\
LowStar.Monotonic.Buffer.all_disjoint [loc k; loc q; loc p01_tmp1_swap; loc tmp2] /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
v (LSeq.index (as_seq h0 bit) 0) <= 1 /\
state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q) /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
state_inv_t h0 (get_x nq_p1) /\ state_inv_t h0 (get_z nq_p1)))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
let (p0, p1, b) = S.ladder_step (as_seq h0 k) (fget_xz h0 q) (v i)
(fget_xz h0 nq, fget_xz h0 nq_p1, LSeq.index (as_seq h0 bit) 0) in
p0 == fget_xz h1 nq /\ p1 == fget_xz h1 nq_p1 /\
b == LSeq.index (as_seq h1 bit) 0 /\
v (LSeq.index (as_seq h1 bit) 0) <= 1 /\
state_inv_t h1 (get_x q) /\ state_inv_t h1 (get_z q) /\
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
state_inv_t h1 (get_x nq_p1) /\ state_inv_t h1 (get_z nq_p1)))
#push-options "--z3rlimit 200 --fuel 0 --ifuel 1"
[@ Meta.Attribute.inline_ ]
let ladder_step #s k q i p01_tmp1_swap tmp2 =
let p01_tmp1 = sub p01_tmp1_swap 0ul (8ul *! nlimb s) in
let swap : lbuffer uint64 1ul = sub p01_tmp1_swap (8ul *! nlimb s) 1ul in
let nq = sub p01_tmp1 0ul (2ul *! nlimb s) in
let nq_p1 = sub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) in
assert (gsub p01_tmp1_swap 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) == nq_p1);
assert (gsub p01_tmp1 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) == nq_p1);
assert (gsub p01_tmp1_swap 0ul (8ul *! nlimb s) == p01_tmp1);
assert (gsub p01_tmp1_swap (8ul *! nlimb s) 1ul == swap);
let h0 = ST.get () in
let bit = scalar_bit k (253ul -. i) in
assert (v bit == v (S.ith_bit (as_seq h0 k) (253 - v i)));
let sw = swap.(0ul) ^. bit in
logxor_lemma1 (LSeq.index (as_seq h0 swap) 0) bit;
cswap2 #s sw nq nq_p1;
point_add_and_double #s q p01_tmp1 tmp2;
swap.(0ul) <- bit
#pop-options
#push-options "--z3rlimit 300 --fuel 1 --ifuel 1"
val ladder_step_loop:
#s:field_spec
-> k:scalar
-> q:point s
-> p01_tmp1_swap:lbuffer (limb s) (8ul *! nlimb s +! 1ul)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 q /\ live h0 p01_tmp1_swap /\ live h0 tmp2 /\
LowStar.Monotonic.Buffer.all_disjoint [loc k; loc q; loc p01_tmp1_swap; loc tmp2] /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
v (LSeq.index (as_seq h0 bit) 0) <= 1 /\
state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q) /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
state_inv_t h0 (get_x nq_p1) /\ state_inv_t h0 (get_z nq_p1)))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
let (p0, p1, b) =
Lib.LoopCombinators.repeati 251
(S.ladder_step (as_seq h0 k) (fget_xz h0 q))
(fget_xz h0 nq, fget_xz h0 nq_p1, LSeq.index (as_seq h0 bit) 0) in
p0 == fget_xz h1 nq /\ p1 == fget_xz h1 nq_p1 /\ b == LSeq.index (as_seq h1 bit) 0 /\
v (LSeq.index (as_seq h1 bit) 0) <= 1 /\
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
state_inv_t h1 (get_x nq_p1) /\ state_inv_t h1 (get_z nq_p1)))
[@ Meta.Attribute.inline_ ]
let ladder_step_loop #s k q p01_tmp1_swap tmp2 =
let h0 = ST.get () in
[@ inline_let]
let spec_fh h0 =
S.ladder_step (as_seq h0 k) (fget_x h0 q, fget_z h0 q) in
[@ inline_let]
let acc h : GTot (tuple3 S.proj_point S.proj_point uint64) =
let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
(fget_xz h nq, fget_xz h nq_p1, LSeq.index (as_seq h bit) 0) in
[@ inline_let]
let inv h (i:nat{i <= 251}) =
let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h /\
v (LSeq.index (as_seq h bit) 0) <= 1 /\
state_inv_t h (get_x q) /\ state_inv_t h (get_z q) /\
state_inv_t h (get_x nq) /\ state_inv_t h (get_z nq) /\
state_inv_t h (get_x nq_p1) /\ state_inv_t h (get_z nq_p1) /\
acc h == Lib.LoopCombinators.repeati i (spec_fh h0) (acc h0) in
Lib.Loops.for 0ul 251ul inv
(fun i ->
Lib.LoopCombinators.unfold_repeati 251 (spec_fh h0) (acc h0) (v i);
ladder_step #s k q i p01_tmp1_swap tmp2)
#pop-options
#push-options "--z3refresh --fuel 0 --ifuel 1 --z3rlimit 800"
val ladder0_:
#s:field_spec
-> k:scalar
-> q:point s
-> p01_tmp1_swap:lbuffer (limb s) (8ul *! nlimb s +! 1ul)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 q /\ live h0 p01_tmp1_swap /\ live h0 tmp2 /\
LowStar.Monotonic.Buffer.all_disjoint [loc k; loc q; loc p01_tmp1_swap; loc tmp2] /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q) /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
state_inv_t h0 (get_x nq_p1) /\ state_inv_t h0 (get_z nq_p1)))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
fget_xz h1 nq ==
M.montgomery_ladder1_0 (as_seq h0 k) (fget_xz h0 q) (fget_xz h0 nq) (fget_xz h0 nq_p1)))
[@ Meta.Attribute.inline_ ]
let ladder0_ #s k q p01_tmp1_swap tmp2 =
let p01_tmp1 = sub p01_tmp1_swap 0ul (8ul *! nlimb s) in
let nq : point s = sub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 : point s = sub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let swap:lbuffer uint64 1ul = sub p01_tmp1_swap (8ul *! nlimb s) 1ul in
assert (gsub p01_tmp1_swap 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) == nq_p1);
assert (gsub p01_tmp1 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) == nq_p1);
assert (gsub p01_tmp1_swap 0ul (8ul *! nlimb s) == p01_tmp1);
assert (gsub p01_tmp1_swap (8ul *! nlimb s) 1ul == swap);
// bit 255 is 0 and bit 254 is 1
cswap2 #s (u64 1) nq nq_p1;
point_add_and_double #s q p01_tmp1 tmp2;
swap.(0ul) <- u64 1;
//Got about 1K speedup by removing 4 iterations here.
//First iteration can be skipped because top bit of scalar is 0
ladder_step_loop #s k q p01_tmp1_swap tmp2;
let sw = swap.(0ul) in
cswap2 #s sw nq nq_p1
val ladder1_:
#s:field_spec
-> p01_tmp1:lbuffer (limb s) (8ul *! nlimb s)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 p01_tmp1 /\ live h0 tmp2 /\ disjoint p01_tmp1 tmp2 /\
(let nq = gsub p01_tmp1 0ul (2ul *! nlimb s) in
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq)))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1 |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1 0ul (2ul *! nlimb s) in
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
fget_xz h1 nq == M.montgomery_ladder1_1 (fget_xz h0 nq)))
[@ Meta.Attribute.inline_ ]
let ladder1_ #s p01_tmp1 tmp2 =
let nq : point s = sub p01_tmp1 0ul (2ul *! nlimb s) in
let tmp1 = sub p01_tmp1 (4ul *! nlimb s) (4ul *! nlimb s) in
assert (gsub p01_tmp1 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1 (4ul *! nlimb s) (4ul *! nlimb s) == tmp1);
point_double nq tmp1 tmp2;
point_double nq tmp1 tmp2;
point_double nq tmp1 tmp2
val ladder2_:
#s:field_spec
-> k:scalar
-> q:point s
-> p01_tmp1_swap:lbuffer (limb s) (8ul *! nlimb s +! 1ul)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 q /\ live h0 p01_tmp1_swap /\ live h0 tmp2 /\
LowStar.Monotonic.Buffer.all_disjoint [loc k; loc q; loc p01_tmp1_swap; loc tmp2] /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q) /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
state_inv_t h0 (get_x nq_p1) /\ state_inv_t h0 (get_z nq_p1)))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
(let nq' = M.montgomery_ladder1_0 (as_seq h0 k) (fget_xz h0 q) (fget_xz h0 nq) (fget_xz h0 nq_p1) in
fget_xz h1 nq == M.montgomery_ladder1_1 nq')))
[@ Meta.Attribute.inline_ ]
let ladder2_ #s k q p01_tmp1_swap tmp2 =
let p01_tmp1 = sub p01_tmp1_swap 0ul (8ul *! nlimb s) in
let nq : point s = sub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 : point s = sub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
assert (gsub p01_tmp1_swap 0ul (8ul *! nlimb s) == p01_tmp1);
assert (gsub p01_tmp1_swap 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) == nq_p1);
assert (gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) == nq_p1);
ladder0_ #s k q p01_tmp1_swap tmp2;
ladder1_ #s p01_tmp1 tmp2
inline_for_extraction noextract
val ladder3_:
#s:field_spec
-> q:point s
-> p01:lbuffer (limb s) (4ul *! nlimb s)
-> Stack unit
(requires fun h0 ->
live h0 q /\ live h0 p01 /\ disjoint q p01 /\
fget_z h0 q == 1 /\ state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q))
(ensures fun h0 _ h1 ->
modifies (loc p01) h0 h1 /\
(let nq = gsub p01 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01 (2ul *! nlimb s) (2ul *! nlimb s) in
state_inv_t h1 (get_x q) /\ state_inv_t h1 (get_z q) /\
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
state_inv_t h1 (get_x nq_p1) /\ state_inv_t h1 (get_z nq_p1) /\
(fget_xz h1 q, fget_xz h1 nq, fget_xz h1 nq_p1) == M.montgomery_ladder1_2 (fget_x h0 q)))
let ladder3_ #s q p01 =
let p0 : point s = sub p01 0ul (2ul *! nlimb s) in
let p1 : point s = sub p01 (2ul *! nlimb s) (2ul *! nlimb s) in
copy p1 q;
let x0 : felem s = sub p0 0ul (nlimb s) in
let z0 : felem s = sub p0 (nlimb s) (nlimb s) in
set_one x0;
set_zero z0;
let h0 = ST.get () in
assert (gsub p01 0ul (2ul *! nlimb s) == p0);
assert (gsub p01 (2ul *! nlimb s) (2ul *! nlimb s) == p1);
assert (gsub p0 0ul (nlimb s) == x0);
assert (gsub p0 (nlimb s) (nlimb s) == z0);
assert (fget_x h0 p1 == fget_x h0 q);
assert (fget_z h0 p1 == 1);
assert (fget_x h0 p0 == 1);
assert (fget_z h0 p0 == 0);
assert (
state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q) /\
state_inv_t h0 (get_x p0) /\ state_inv_t h0 (get_z p0) /\
state_inv_t h0 (get_x p1) /\ state_inv_t h0 (get_z p1))
val ladder4_:
#s:field_spec
-> k:scalar
-> q:point s
-> p01_tmp1_swap:lbuffer (limb s) (8ul *! nlimb s +! 1ul)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 q /\ live h0 p01_tmp1_swap /\ live h0 tmp2 /\
LowStar.Monotonic.Buffer.all_disjoint [loc k; loc q; loc p01_tmp1_swap; loc tmp2] /\
fget_z h0 q == 1 /\ state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
fget_xz h1 nq == S.montgomery_ladder (fget_x h0 q) (as_seq h0 k))) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.AddAndDouble.fst.checked",
"Hacl.Impl.Curve25519.Finv.fst.checked",
"Hacl.Impl.Curve25519.Fields.Core.fsti.checked",
"Hacl.Impl.Curve25519.Fields.fst.checked",
"Hacl.Impl.Curve25519.AddAndDouble.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Curve25519.Generic.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.AddAndDouble",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.AddAndDouble",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Finv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"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.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": true,
"z3rlimit": 800,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Hacl.Impl.Curve25519.Generic.scalar ->
q: Hacl.Impl.Curve25519.AddAndDouble.point s ->
p01_tmp1_swap:
Lib.Buffer.lbuffer (Hacl.Impl.Curve25519.Fields.Core.limb s)
(8ul *! Hacl.Impl.Curve25519.Fields.Core.nlimb s +! 1ul) ->
tmp2: Hacl.Impl.Curve25519.Fields.Core.felem_wide2 s
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Curve25519.Fields.Core.field_spec",
"Hacl.Impl.Curve25519.Generic.scalar",
"Hacl.Impl.Curve25519.AddAndDouble.point",
"Lib.Buffer.lbuffer",
"Hacl.Impl.Curve25519.Fields.Core.limb",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.op_Star_Bang",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Curve25519.Fields.Core.nlimb",
"Hacl.Impl.Curve25519.Fields.Core.felem_wide2",
"Hacl.Spec.Curve25519.AddAndDouble.lemma_montgomery_ladder",
"Hacl.Impl.Curve25519.AddAndDouble.fget_x",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint8",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"FStar.Pervasives.Native.tuple2",
"Spec.Curve25519.elem",
"Hacl.Impl.Curve25519.AddAndDouble.fget_xz",
"Hacl.Spec.Curve25519.AddAndDouble.montgomery_ladder1",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.Curve25519.Generic.ladder2_",
"Hacl.Impl.Curve25519.Generic.ladder3_",
"Lib.Buffer.buffer_t",
"Prims.l_or",
"Prims.int",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.Buffer.length",
"Lib.IntTypes.v",
"Lib.Buffer.gsub",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.sub",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Lib.IntTypes.mul",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t"
] | [] | false | true | false | false | false | let ladder4_ #s k q p01_tmp1_swap tmp2 =
| let h0 = ST.get () in
let p01 = sub p01_tmp1_swap 0ul (4ul *! nlimb s) in
let p0:point s = sub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let p1:point s = sub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
assert (gsub p01_tmp1_swap 0ul (4ul *! nlimb s) == p01);
assert (gsub p01 0ul (2ul *! nlimb s) == p0);
assert (gsub p01 (2ul *! nlimb s) (2ul *! nlimb s) == p1);
ladder3_ #s q p01;
ladder2_ #s k q p01_tmp1_swap tmp2;
let h1 = ST.get () in
assert (fget_xz h1 p0 == M.montgomery_ladder1 (fget_x h0 q) (as_seq h0 k));
M.lemma_montgomery_ladder (fget_x h0 q) (as_seq h0 k) | false |
Vale.Stdcalls.X64.Fsqr.fsti | Vale.Stdcalls.X64.Fsqr.fsqr_dom | val fsqr_dom:IX64.arity_ok_stdcall td | val fsqr_dom:IX64.arity_ok_stdcall td | let fsqr_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; t64_mod] in
assert_norm (List.length y = 3);
y | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fsqr.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 51,
"start_col": 0,
"start_line": 48
} | module Vale.Stdcalls.X64.Fsqr
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fsqr.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Vale.Interop.X64.arity_ok_stdcall Vale.Interop.Base.td | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.List.Tot.Base.length",
"Vale.Interop.Base.td",
"Prims.list",
"Prims.Cons",
"Vale.Stdcalls.X64.Fsqr.t64_mod",
"Vale.Stdcalls.X64.Fsqr.t64_no_mod",
"Prims.Nil"
] | [] | false | false | false | true | false | let fsqr_dom:IX64.arity_ok_stdcall td =
| let y = [t64_mod; t64_no_mod; t64_mod] in
assert_norm (List.length y = 3);
y | false |
EverParse3d.Actions.All.fst | EverParse3d.Actions.All.___PUINT8 | val ___PUINT8: Type0 | val ___PUINT8: Type0 | let ___PUINT8 = (b:LowStar.Buffer.buffer FStar.UInt8.t { ~ (LowStar.Buffer.g_is_null b) }) | {
"file_name": "src/3d/prelude/extern/EverParse3d.Actions.All.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 90,
"end_line": 7,
"start_col": 0,
"start_line": 7
} | module EverParse3d.Actions.All
friend EverParse3d.Actions.Base
friend EverParse3d.InputStream.All
let _ = EverParse3d.Actions.BackendFlagValue.backend_flag_value | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"EverParse3d.InputStream.Extern.fst.checked",
"EverParse3d.InputStream.All.fst.checked",
"EverParse3d.Actions.Base.fst.checked",
"EverParse3d.Actions.BackendFlagValue.fsti.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Actions.All.fst"
} | [
{
"abbrev": true,
"full_module": "EverParse3d.Prelude",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 8,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"LowStar.Buffer.buffer",
"FStar.UInt8.t",
"Prims.l_not",
"Prims.b2t",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.Buffer.trivial_preorder"
] | [] | false | false | false | true | true | let ___PUINT8 =
| (b: LowStar.Buffer.buffer FStar.UInt8.t {~(LowStar.Buffer.g_is_null b)}) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.locations_of_operand128 | val locations_of_operand128 (o: operand128) : locations & locations | val locations_of_operand128 (o: operand128) : locations & locations | let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack] | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 90,
"end_line": 38,
"start_col": 0,
"start_line": 33
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack] | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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.Transformers.Locations.locations * Vale.Transformers.Locations.locations | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.operand128",
"Vale.X64.Machine_s.quad32",
"FStar.Pervasives.Native.Mktuple2",
"Vale.Transformers.Locations.locations",
"Prims.Nil",
"Vale.Transformers.Locations.location",
"Vale.X64.Machine_s.reg_xmm",
"Prims.Cons",
"Vale.Transformers.Locations.ALocReg",
"Vale.X64.Machine_s.Reg",
"Vale.X64.Machine_s.maddr",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Transformers.BoundedInstructionEffects.locations_of_maddr",
"Vale.Transformers.Locations.ALocMem",
"Vale.X64.Machine_s.rRsp",
"Vale.Transformers.Locations.ALocStack",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | true | false | let locations_of_operand128 (o: operand128) : locations & locations =
| match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack] | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.locations_of_maddr | val locations_of_maddr (m: maddr) (mem: location) : locations | val locations_of_maddr (m: maddr) (mem: location) : locations | let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 24,
"start_col": 0,
"start_line": 18
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | m: Vale.X64.Machine_s.maddr -> mem: Vale.Transformers.Locations.location
-> Vale.Transformers.Locations.locations | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.maddr",
"Vale.Transformers.Locations.location",
"Prims.Cons",
"Prims.int",
"Prims.Nil",
"Vale.X64.Machine_s.reg",
"Vale.Transformers.Locations.ALocReg",
"Prims.list",
"Vale.Transformers.Locations.locations"
] | [] | false | false | false | true | false | let locations_of_maddr (m: maddr) (mem: location) : locations =
| mem ::
(match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]) | false |
Vale.Stdcalls.X64.Fsqr.fsti | Vale.Stdcalls.X64.Fsqr.lowstar_Fsqr_t | val lowstar_Fsqr_t : Type0 | let lowstar_Fsqr_t =
assert_norm (List.length fsqr_dom + List.length ([]<:list arg) <= 4);
IX64.as_lowstar_sig_t_weak_stdcall
code_Fsqr
fsqr_dom
[]
_
_
(W.mk_prediction code_Fsqr fsqr_dom [] (fsqr_lemma code_Fsqr IA.win)) | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fsqr.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 73,
"end_line": 124,
"start_col": 0,
"start_line": 116
} | module Vale.Stdcalls.X64.Fsqr
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let fsqr_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; t64_mod] in
assert_norm (List.length y = 3);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fsqr_pre : VSig.vale_pre fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state) ->
FW.va_req_Fsqr_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out)
[@__reduce__] noextract
let fsqr_post : VSig.vale_post fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fsqr_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) va_s1 f
#set-options "--z3rlimit 200"
[@__reduce__] noextract
let fsqr_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fsqr_pre code tmp f1 out va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fsqr_post code tmp f1 out va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fsqr_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f)
(* Prove that fsqr_lemma' has the required type *)
noextract
let fsqr_lemma = as_t #(VSig.vale_sig_stdcall fsqr_pre fsqr_post) fsqr_lemma'
noextract
let code_Fsqr = FW.va_code_Fsqr_stdcall IA.win
(* Here's the type expected for the fsqr wrapper *) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fsqr.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.Interop.X64.as_lowstar_sig_t_weak_stdcall",
"Vale.Stdcalls.X64.Fsqr.code_Fsqr",
"Vale.Stdcalls.X64.Fsqr.fsqr_dom",
"Prims.Nil",
"Vale.Interop.Base.arg",
"Vale.AsLowStar.Wrapper.pre_rel_generic",
"Vale.Interop.X64.max_stdcall",
"Vale.Interop.X64.arg_reg_stdcall",
"Vale.Stdcalls.X64.Fsqr.fsqr_pre",
"Vale.AsLowStar.Wrapper.post_rel_generic",
"Vale.Stdcalls.X64.Fsqr.fsqr_post",
"Vale.AsLowStar.Wrapper.mk_prediction",
"Vale.Interop.X64.regs_modified_stdcall",
"Vale.Interop.X64.xmms_modified_stdcall",
"Vale.Stdcalls.X64.Fsqr.fsqr_lemma",
"Vale.Interop.Assumptions.win",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.List.Tot.Base.length",
"Vale.Interop.Base.td",
"Prims.list"
] | [] | false | false | false | true | true | let lowstar_Fsqr_t =
| assert_norm (List.length fsqr_dom + List.length ([] <: list arg) <= 4);
IX64.as_lowstar_sig_t_weak_stdcall code_Fsqr
fsqr_dom
[]
_
_
(W.mk_prediction code_Fsqr fsqr_dom [] (fsqr_lemma code_Fsqr IA.win)) | false |
|
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.locations_of_operand64 | val locations_of_operand64 (o: operand64) : locations & locations | val locations_of_operand64 (o: operand64) : locations & locations | let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack] | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 90,
"end_line": 31,
"start_col": 0,
"start_line": 26
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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.Transformers.Locations.locations * Vale.Transformers.Locations.locations | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_s.operand64",
"Vale.X64.Machine_s.nat64",
"FStar.Pervasives.Native.Mktuple2",
"Vale.Transformers.Locations.locations",
"Prims.Nil",
"Vale.Transformers.Locations.location",
"Vale.X64.Machine_s.reg_64",
"Prims.Cons",
"Vale.Transformers.Locations.ALocReg",
"Vale.X64.Machine_s.Reg",
"Vale.X64.Machine_s.maddr",
"Vale.Arch.HeapTypes_s.taint",
"Vale.Transformers.BoundedInstructionEffects.locations_of_maddr",
"Vale.Transformers.Locations.ALocMem",
"Vale.X64.Machine_s.rRsp",
"Vale.Transformers.Locations.ALocStack",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | true | false | let locations_of_operand64 (o: operand64) : locations & locations =
| match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack] | false |
Vale.Stdcalls.X64.Fsqr.fsti | Vale.Stdcalls.X64.Fsqr.fsqr_lemma | val fsqr_lemma : Vale.AsLowStar.ValeSig.vale_sig_stdcall Vale.Stdcalls.X64.Fsqr.fsqr_pre
Vale.Stdcalls.X64.Fsqr.fsqr_post | let fsqr_lemma = as_t #(VSig.vale_sig_stdcall fsqr_pre fsqr_post) fsqr_lemma' | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fsqr.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 77,
"end_line": 110,
"start_col": 0,
"start_line": 110
} | module Vale.Stdcalls.X64.Fsqr
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let fsqr_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; t64_mod] in
assert_norm (List.length y = 3);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fsqr_pre : VSig.vale_pre fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state) ->
FW.va_req_Fsqr_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out)
[@__reduce__] noextract
let fsqr_post : VSig.vale_post fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fsqr_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) va_s1 f
#set-options "--z3rlimit 200"
[@__reduce__] noextract
let fsqr_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fsqr_pre code tmp f1 out va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fsqr_post code tmp f1 out va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fsqr_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f)
(* Prove that fsqr_lemma' has the required type *) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fsqr.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Vale.AsLowStar.ValeSig.vale_sig_stdcall Vale.Stdcalls.X64.Fsqr.fsqr_pre
Vale.Stdcalls.X64.Fsqr.fsqr_post | Prims.Tot | [
"total"
] | [] | [
"Vale.Stdcalls.X64.Fsqr.as_t",
"Vale.AsLowStar.ValeSig.vale_sig_stdcall",
"Vale.Stdcalls.X64.Fsqr.fsqr_dom",
"Vale.Stdcalls.X64.Fsqr.fsqr_pre",
"Vale.Stdcalls.X64.Fsqr.fsqr_post",
"Vale.Stdcalls.X64.Fsqr.fsqr_lemma'"
] | [] | false | false | false | true | false | let fsqr_lemma =
| as_t #(VSig.vale_sig_stdcall fsqr_pre fsqr_post) fsqr_lemma' | false |
|
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.aux_read_set0 | val aux_read_set0 (args: list instr_operand) (oprs: instr_operands_t_args args) : locations | val aux_read_set0 (args: list instr_operand) (oprs: instr_operands_t_args args) : locations | let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 108,
"end_line": 63,
"start_col": 0,
"start_line": 56
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 ->
oprs: Vale.X64.Instruction_s.instr_operands_t_args args
-> Vale.Transformers.Locations.locations | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_operands_t_args",
"Prims.Nil",
"Vale.Transformers.Locations.location",
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Instruction_s.instr_operand_t",
"FStar.List.Tot.Base.append",
"Vale.Transformers.BoundedInstructionEffects.both",
"Vale.Transformers.BoundedInstructionEffects.locations_of_explicit",
"Vale.Transformers.BoundedInstructionEffects.aux_read_set0",
"Vale.Transformers.Locations.locations",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.coerce",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.Transformers.BoundedInstructionEffects.locations_of_implicit"
] | [
"recursion"
] | false | false | false | false | false | let rec aux_read_set0 (args: list instr_operand) (oprs: instr_operands_t_args args) : locations =
| match args with
| [] -> []
| IOpEx i :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
(both (locations_of_explicit i l)) `L.append` (aux_read_set0 args r)
| IOpIm i :: args ->
(both (locations_of_implicit i))
`L.append`
(aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)) | false |
Vale.Stdcalls.X64.Fsqr.fsti | Vale.Stdcalls.X64.Fsqr.lowstar_Fsqr2_t | val lowstar_Fsqr2_t : Type0 | let lowstar_Fsqr2_t =
assert_norm (List.length fsqr_dom + List.length ([]<:list arg) <= 4);
IX64.as_lowstar_sig_t_weak_stdcall
code_Fsqr2
fsqr_dom
[]
_
_
(W.mk_prediction code_Fsqr2 fsqr_dom [] (fsqr2_lemma code_Fsqr2 IA.win)) | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fsqr.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 76,
"end_line": 197,
"start_col": 0,
"start_line": 189
} | module Vale.Stdcalls.X64.Fsqr
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let fsqr_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; t64_mod] in
assert_norm (List.length y = 3);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fsqr_pre : VSig.vale_pre fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state) ->
FW.va_req_Fsqr_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out)
[@__reduce__] noextract
let fsqr_post : VSig.vale_post fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fsqr_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) va_s1 f
#set-options "--z3rlimit 200"
[@__reduce__] noextract
let fsqr_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fsqr_pre code tmp f1 out va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fsqr_post code tmp f1 out va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fsqr_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f)
(* Prove that fsqr_lemma' has the required type *)
noextract
let fsqr_lemma = as_t #(VSig.vale_sig_stdcall fsqr_pre fsqr_post) fsqr_lemma'
noextract
let code_Fsqr = FW.va_code_Fsqr_stdcall IA.win
(* Here's the type expected for the fsqr wrapper *)
[@__reduce__] noextract
let lowstar_Fsqr_t =
assert_norm (List.length fsqr_dom + List.length ([]<:list arg) <= 4);
IX64.as_lowstar_sig_t_weak_stdcall
code_Fsqr
fsqr_dom
[]
_
_
(W.mk_prediction code_Fsqr fsqr_dom [] (fsqr_lemma code_Fsqr IA.win))
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fsqr2_pre : VSig.vale_pre fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state) ->
FW.va_req_Fsqr2_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out)
[@__reduce__] noextract
let fsqr2_post : VSig.vale_post fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fsqr2_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) va_s1 f
#set-options "--z3rlimit 200"
[@__reduce__] noextract
let fsqr2_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fsqr2_pre code tmp f1 out va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fsqr2_post code tmp f1 out va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fsqr2_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f)
(* Prove that fsqr2_lemma' has the required type *)
noextract
let fsqr2_lemma = as_t #(VSig.vale_sig_stdcall fsqr2_pre fsqr2_post) fsqr2_lemma'
noextract
let code_Fsqr2 = FW.va_code_Fsqr2_stdcall IA.win
(* Here's the type expected for the fsqr2 wrapper *) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fsqr.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.Interop.X64.as_lowstar_sig_t_weak_stdcall",
"Vale.Stdcalls.X64.Fsqr.code_Fsqr2",
"Vale.Stdcalls.X64.Fsqr.fsqr_dom",
"Prims.Nil",
"Vale.Interop.Base.arg",
"Vale.AsLowStar.Wrapper.pre_rel_generic",
"Vale.Interop.X64.max_stdcall",
"Vale.Interop.X64.arg_reg_stdcall",
"Vale.Stdcalls.X64.Fsqr.fsqr2_pre",
"Vale.AsLowStar.Wrapper.post_rel_generic",
"Vale.Stdcalls.X64.Fsqr.fsqr2_post",
"Vale.AsLowStar.Wrapper.mk_prediction",
"Vale.Interop.X64.regs_modified_stdcall",
"Vale.Interop.X64.xmms_modified_stdcall",
"Vale.Stdcalls.X64.Fsqr.fsqr2_lemma",
"Vale.Interop.Assumptions.win",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.List.Tot.Base.length",
"Vale.Interop.Base.td",
"Prims.list"
] | [] | false | false | false | true | true | let lowstar_Fsqr2_t =
| assert_norm (List.length fsqr_dom + List.length ([] <: list arg) <= 4);
IX64.as_lowstar_sig_t_weak_stdcall code_Fsqr2
fsqr_dom
[]
_
_
(W.mk_prediction code_Fsqr2 fsqr_dom [] (fsqr2_lemma code_Fsqr2 IA.win)) | false |
|
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.locations_of_implicit | val locations_of_implicit (t: instr_operand_implicit) : locations & locations | val locations_of_implicit (t: instr_operand_implicit) : locations & locations | let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf] | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 50,
"start_col": 0,
"start_line": 45
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | t: Vale.X64.Instruction_s.instr_operand_implicit
-> Vale.Transformers.Locations.locations * Vale.Transformers.Locations.locations | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Machine_s.operand64",
"Vale.Transformers.BoundedInstructionEffects.locations_of_operand64",
"Vale.X64.Machine_s.operand128",
"Vale.Transformers.BoundedInstructionEffects.locations_of_operand128",
"FStar.Pervasives.Native.Mktuple2",
"Vale.Transformers.Locations.locations",
"Prims.Nil",
"Vale.Transformers.Locations.location",
"Prims.Cons",
"Vale.Transformers.Locations.ALocCf",
"Vale.Transformers.Locations.ALocOf",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | true | false | let locations_of_implicit (t: instr_operand_implicit) : locations & locations =
| match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf] | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.locations_of_explicit | val locations_of_explicit (t: instr_operand_explicit) (i: instr_operand_t t) : locations & locations | val locations_of_explicit (t: instr_operand_explicit) (i: instr_operand_t t) : locations & locations | let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 43,
"start_col": 0,
"start_line": 40
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack] | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | t: Vale.X64.Instruction_s.instr_operand_explicit -> i: Vale.X64.Instruction_s.instr_operand_t t
-> Vale.Transformers.Locations.locations * Vale.Transformers.Locations.locations | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Instruction_s.instr_operand_t",
"Vale.Transformers.BoundedInstructionEffects.locations_of_operand64",
"Vale.Transformers.BoundedInstructionEffects.locations_of_operand128",
"FStar.Pervasives.Native.tuple2",
"Vale.Transformers.Locations.locations"
] | [] | false | false | false | false | false | let locations_of_explicit (t: instr_operand_explicit) (i: instr_operand_t t) : locations & locations =
| match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.aux_read_set1 | val aux_read_set1
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
: locations | val aux_read_set1
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
: locations | let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 113,
"end_line": 78,
"start_col": 0,
"start_line": 65
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 ->
oprs: Vale.X64.Instruction_s.instr_operands_t outs args
-> Vale.Transformers.Locations.locations | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.Transformers.BoundedInstructionEffects.aux_read_set0",
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Instruction_s.instr_operand_t",
"FStar.List.Tot.Base.append",
"Vale.Transformers.Locations.location",
"FStar.Pervasives.Native.fst",
"Vale.Transformers.Locations.locations",
"Vale.Transformers.BoundedInstructionEffects.locations_of_explicit",
"Vale.Transformers.BoundedInstructionEffects.aux_read_set1",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.coerce",
"Vale.Transformers.BoundedInstructionEffects.both",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.Transformers.BoundedInstructionEffects.locations_of_implicit"
] | [
"recursion"
] | false | false | false | false | false | let rec aux_read_set1
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
: locations =
| match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
(fst (locations_of_explicit i l)) `L.append` (aux_read_set1 outs args r)
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
(both (locations_of_explicit i l)) `L.append` (aux_read_set1 outs args r)
| (Out, IOpIm i) :: outs ->
(fst (locations_of_implicit i))
`L.append`
(aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs))
| (InOut, IOpIm i) :: outs ->
(both (locations_of_implicit i))
`L.append`
(aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.write_set | val write_set (i: instr_t_record) (oprs: instr_operands_t i.outs i.args) : list location | val write_set (i: instr_t_record) (oprs: instr_operands_t i.outs i.args) : list location | let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 98,
"start_col": 0,
"start_line": 93
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
i: Vale.X64.Instruction_s.instr_t_record ->
oprs:
Vale.X64.Instruction_s.instr_operands_t (InstrTypeRecord?.outs i) (InstrTypeRecord?.args i)
-> Prims.list Vale.Transformers.Locations.location | Prims.Tot | [
"total"
] | [] | [
"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",
"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",
"Prims.Cons",
"Vale.Transformers.Locations.location",
"Vale.Transformers.Locations.ALocCf",
"Vale.Transformers.Locations.ALocOf",
"Vale.Transformers.BoundedInstructionEffects.aux_write_set"
] | [] | false | false | false | false | false | let write_set (i: instr_t_record) (oprs: instr_operands_t i.outs i.args) : list location =
| let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.unchanged_at' | val unchanged_at' : l: Vale.Transformers.Locations.locations ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 364,
"start_col": 0,
"start_line": 361
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
l: Vale.Transformers.Locations.locations ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.l_and",
"Prims.b2t",
"Prims.op_Equality",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Prims.l_imp",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Prims.logical"
] | [] | false | false | false | true | true | let unchanged_at' (l: locations) (s1 s2: machine_state) =
| (s1.ms_ok = s2.ms_ok) /\ (s1.ms_ok /\ s2.ms_ok ==> unchanged_at l s1 s2) | false |
|
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.locations_of_ocmp | val locations_of_ocmp : o:ocmp -> locations | val locations_of_ocmp : o:ocmp -> locations | let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 80,
"end_line": 155,
"start_col": 0,
"start_line": 147
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
} | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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_Semantics_s.ocmp -> Vale.Transformers.Locations.locations | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.ocmp",
"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.List.Tot.Base.append",
"Vale.Transformers.Locations.location",
"Vale.Transformers.BoundedInstructionEffects.both",
"Vale.Transformers.BoundedInstructionEffects.locations_of_operand64",
"Vale.Transformers.Locations.locations"
] | [] | false | false | false | true | false | let locations_of_ocmp o =
| match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 -> (both (locations_of_operand64 o1)) `L.append` (both (locations_of_operand64 o2)) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.aux_write_set | val aux_write_set
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
: locations | val aux_write_set
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
: locations | let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 112,
"end_line": 91,
"start_col": 0,
"start_line": 83
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 ->
oprs: Vale.X64.Instruction_s.instr_operands_t outs args
-> Vale.Transformers.Locations.locations | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_operands_t",
"Prims.Nil",
"Vale.Transformers.Locations.location",
"Vale.X64.Instruction_s.instr_operand_inout",
"Vale.X64.Instruction_s.instr_operand_explicit",
"Vale.X64.Instruction_s.instr_operand_t",
"FStar.List.Tot.Base.append",
"FStar.Pervasives.Native.snd",
"Vale.Transformers.Locations.locations",
"Vale.Transformers.BoundedInstructionEffects.locations_of_explicit",
"Vale.Transformers.BoundedInstructionEffects.aux_write_set",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.coerce",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.Transformers.BoundedInstructionEffects.locations_of_implicit"
] | [
"recursion"
] | false | false | false | false | false | let rec aux_write_set
(outs: list instr_out)
(args: list instr_operand)
(oprs: instr_operands_t outs args)
: locations =
| match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
(snd (locations_of_explicit i l)) `L.append` (aux_write_set outs args r)
| (_, IOpIm i) :: outs ->
(snd (locations_of_implicit i))
`L.append`
(aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.constant_writes | val constant_writes (i: instr_t_record) (oprs: instr_operands_t i.outs i.args)
: locations_with_values | val constant_writes (i: instr_t_record) (oprs: instr_operands_t i.outs i.args)
: locations_with_values | let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> [] | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 110,
"start_col": 0,
"start_line": 100
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
i: Vale.X64.Instruction_s.instr_t_record ->
oprs:
Vale.X64.Instruction_s.instr_operands_t (InstrTypeRecord?.outs i) (InstrTypeRecord?.args i)
-> Vale.Transformers.BoundedInstructionEffects.locations_with_values | Prims.Tot | [
"total"
] | [] | [
"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",
"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.Transformers.BoundedInstructionEffects.locations_with_values",
"FStar.List.Tot.Base.mem",
"Vale.Transformers.Locations.location",
"Vale.Transformers.Locations.ALocOf",
"Prims.bool",
"Prims.Cons",
"Vale.Transformers.BoundedInstructionEffects.location_with_value",
"Prims.Mkdtuple2",
"Vale.Transformers.Locations.location_eq",
"Vale.Transformers.Locations.location_val_eqt",
"FStar.Pervasives.Native.None",
"Vale.Transformers.Locations.ALocCf",
"Prims.Nil",
"Vale.Transformers.BoundedInstructionEffects.aux_write_set"
] | [] | false | false | false | false | false | let constant_writes (i: instr_t_record) (oprs: instr_operands_t i.outs i.args)
: locations_with_values =
| let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags ->
(let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr)
| PreserveFlags -> [] | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_only_affects_write | val lemma_machine_eval_ins_st_only_affects_write (i: ins{Instr? i}) (s: machine_state)
: Lemma
(ensures
((let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) | val lemma_machine_eval_ins_st_only_affects_write (i: ins{Instr? i}) (s: machine_state)
: Lemma
(ensures
((let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) | let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s)) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 89,
"end_line": 230,
"start_col": 0,
"start_line": 224
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> () | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | i: Vale.X64.Machine_Semantics_s.ins{Instr? i} -> s: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(ensures
(let w = Mkrw_set?.loc_writes (Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins i) in
Vale.Transformers.BoundedInstructionEffects.unchanged_except w
s
(Vale.X64.Machine_Semantics_s.run (Vale.X64.Machine_Semantics_s.machine_eval_ins_st i) s))
) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Classical.forall_intro",
"Vale.Transformers.Locations.location",
"Prims.l_imp",
"Vale.Def.PossiblyMonad.op_Bang_Bang",
"Vale.Transformers.Locations.disjoint_location_from_locations",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins",
"Prims.eq2",
"Vale.Transformers.Locations.location_val_t",
"Vale.Transformers.Locations.eval_location",
"Vale.X64.Machine_Semantics_s.run",
"Vale.X64.Machine_Semantics_s.machine_eval_ins_st",
"FStar.Classical.move_requires",
"Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_only_affects_write_aux",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Vale.Transformers.BoundedInstructionEffects.unchanged_except",
"Prims.list",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_machine_eval_ins_st_only_affects_write (i: ins{Instr? i}) (s: machine_state)
: Lemma
(ensures
((let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
| FStar.Classical.forall_intro (FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux
i
s)) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins | val rw_set_of_ins : i:ins -> rw_set | val rw_set_of_ins : i:ins -> rw_set | let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
} | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 144,
"start_col": 0,
"start_line": 113
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> [] | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | i: Vale.X64.Machine_Semantics_s.ins -> Vale.Transformers.BoundedInstructionEffects.rw_set | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"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.Transformers.BoundedInstructionEffects.Mkrw_set",
"Vale.Transformers.BoundedInstructionEffects.read_set",
"Vale.Transformers.BoundedInstructionEffects.write_set",
"Vale.Transformers.BoundedInstructionEffects.constant_writes",
"Vale.X64.Machine_s.operand64",
"Vale.Arch.HeapTypes_s.taint",
"Prims.Cons",
"Vale.Transformers.Locations.location",
"Vale.Transformers.Locations.ALocReg",
"Vale.X64.Machine_s.Reg",
"Vale.X64.Machine_s.rRsp",
"Vale.Transformers.Locations.ALocStack",
"Vale.Transformers.BoundedInstructionEffects.both",
"Vale.Transformers.BoundedInstructionEffects.locations_of_operand64",
"Prims.Nil",
"Vale.Transformers.BoundedInstructionEffects.location_with_value",
"FStar.Pervasives.Native.fst",
"Vale.Transformers.Locations.locations",
"FStar.Pervasives.Native.snd",
"Vale.X64.Machine_s.nat64",
"Vale.Transformers.BoundedInstructionEffects.rw_set"
] | [] | false | false | false | true | false | let rw_set_of_ins i =
| match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = []
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = []
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = []
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = []
} | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_only_affects_write_aux | val lemma_machine_eval_ins_st_only_affects_write_aux
(i: ins{Instr? i})
(s: machine_state)
(a: location)
: Lemma
(requires
(let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures ((eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) | val lemma_machine_eval_ins_st_only_affects_write_aux
(i: ins{Instr? i})
(s: machine_state)
(a: location)
: Lemma
(requires
(let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures ((eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) | let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> () | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 222,
"start_col": 0,
"start_line": 212
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
i: Vale.X64.Machine_Semantics_s.ins{Instr? i} ->
s: Vale.X64.Machine_Semantics_s.machine_state ->
a: Vale.Transformers.Locations.location
-> FStar.Pervasives.Lemma
(requires
(let w =
Mkrw_set?.loc_writes (Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins i)
in
!!(Vale.Transformers.Locations.disjoint_location_from_locations a w)))
(ensures
Vale.Transformers.Locations.eval_location a s ==
Vale.Transformers.Locations.eval_location a
(Vale.X64.Machine_Semantics_s.run (Vale.X64.Machine_Semantics_s.machine_eval_ins_st i) s)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.Locations.location",
"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.eval_instr",
"Vale.Transformers.BoundedInstructionEffects.lemma_eval_instr_only_affects_write",
"Prims.unit",
"Vale.Def.PossiblyMonad.op_Bang_Bang",
"Vale.Transformers.Locations.disjoint_location_from_locations",
"Prims.list",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins",
"Prims.squash",
"Prims.eq2",
"Vale.Transformers.Locations.location_val_t",
"Vale.Transformers.Locations.eval_location",
"Vale.X64.Machine_Semantics_s.run",
"Vale.X64.Machine_Semantics_s.machine_eval_ins_st",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_machine_eval_ins_st_only_affects_write_aux
(i: ins{Instr? i})
(s: machine_state)
(a: location)
: Lemma
(requires
(let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures ((eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
| let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> () | false |
Vale.Stdcalls.X64.Fsqr.fsti | Vale.Stdcalls.X64.Fsqr.fsqr2_lemma | val fsqr2_lemma : Vale.AsLowStar.ValeSig.vale_sig_stdcall Vale.Stdcalls.X64.Fsqr.fsqr2_pre
Vale.Stdcalls.X64.Fsqr.fsqr2_post | let fsqr2_lemma = as_t #(VSig.vale_sig_stdcall fsqr2_pre fsqr2_post) fsqr2_lemma' | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fsqr.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 81,
"end_line": 183,
"start_col": 0,
"start_line": 183
} | module Vale.Stdcalls.X64.Fsqr
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let fsqr_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; t64_mod] in
assert_norm (List.length y = 3);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fsqr_pre : VSig.vale_pre fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state) ->
FW.va_req_Fsqr_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out)
[@__reduce__] noextract
let fsqr_post : VSig.vale_post fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fsqr_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) va_s1 f
#set-options "--z3rlimit 200"
[@__reduce__] noextract
let fsqr_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fsqr_pre code tmp f1 out va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fsqr_post code tmp f1 out va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fsqr_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f)
(* Prove that fsqr_lemma' has the required type *)
noextract
let fsqr_lemma = as_t #(VSig.vale_sig_stdcall fsqr_pre fsqr_post) fsqr_lemma'
noextract
let code_Fsqr = FW.va_code_Fsqr_stdcall IA.win
(* Here's the type expected for the fsqr wrapper *)
[@__reduce__] noextract
let lowstar_Fsqr_t =
assert_norm (List.length fsqr_dom + List.length ([]<:list arg) <= 4);
IX64.as_lowstar_sig_t_weak_stdcall
code_Fsqr
fsqr_dom
[]
_
_
(W.mk_prediction code_Fsqr fsqr_dom [] (fsqr_lemma code_Fsqr IA.win))
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fsqr2_pre : VSig.vale_pre fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state) ->
FW.va_req_Fsqr2_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out)
[@__reduce__] noextract
let fsqr2_post : VSig.vale_post fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fsqr2_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) va_s1 f
#set-options "--z3rlimit 200"
[@__reduce__] noextract
let fsqr2_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fsqr2_pre code tmp f1 out va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fsqr2_post code tmp f1 out va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fsqr2_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f)
(* Prove that fsqr2_lemma' has the required type *) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fsqr.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Vale.AsLowStar.ValeSig.vale_sig_stdcall Vale.Stdcalls.X64.Fsqr.fsqr2_pre
Vale.Stdcalls.X64.Fsqr.fsqr2_post | Prims.Tot | [
"total"
] | [] | [
"Vale.Stdcalls.X64.Fsqr.as_t",
"Vale.AsLowStar.ValeSig.vale_sig_stdcall",
"Vale.Stdcalls.X64.Fsqr.fsqr_dom",
"Vale.Stdcalls.X64.Fsqr.fsqr2_pre",
"Vale.Stdcalls.X64.Fsqr.fsqr2_post",
"Vale.Stdcalls.X64.Fsqr.fsqr2_lemma'"
] | [] | false | false | false | true | false | let fsqr2_lemma =
| as_t #(VSig.vale_sig_stdcall fsqr2_pre fsqr2_post) fsqr2_lemma' | false |
|
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_append | val lemma_unchanged_at_append (l1 l2: locations) (s1 s2: machine_state)
: Lemma
(ensures
((unchanged_at (l1 `L.append` l2) s1 s2) <==> (unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2)
)) | val lemma_unchanged_at_append (l1 l2: locations) (s1 s2: machine_state)
: Lemma
(ensures
((unchanged_at (l1 `L.append` l2) s1 s2) <==> (unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2)
)) | let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 264,
"start_col": 0,
"start_line": 256
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
l1: Vale.Transformers.Locations.locations ->
l2: Vale.Transformers.Locations.locations ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(ensures
Vale.Transformers.BoundedInstructionEffects.unchanged_at (l1 @ l2) s1 s2 <==>
Vale.Transformers.BoundedInstructionEffects.unchanged_at l1 s1 s2 /\
Vale.Transformers.BoundedInstructionEffects.unchanged_at l2 s1 s2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.Locations.location",
"Prims.list",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_append",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_iff",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"FStar.List.Tot.Base.append",
"Prims.l_and",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_unchanged_at_append (l1 l2: locations) (s1 s2: machine_state)
: Lemma
(ensures
((unchanged_at (l1 `L.append` l2) s1 s2) <==> (unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2)
)) =
| match l1 with
| [] -> ()
| x :: xs -> lemma_unchanged_at_append xs l2 s1 s2 | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_eval_instr_only_affects_write | val lemma_eval_instr_only_affects_write
(it: instr_t_record)
(oprs: instr_operands_t it.outs it.args)
(ann: instr_annotation it)
(s0: machine_state)
(a: location)
: Lemma
(requires
((let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\ (Some? (eval_instr it oprs ann s0)))))
(ensures ((eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) | val lemma_eval_instr_only_affects_write
(it: instr_t_record)
(oprs: instr_operands_t it.outs it.args)
(ann: instr_annotation it)
(s0: machine_state)
(a: location)
: Lemma
(requires
((let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\ (Some? (eval_instr it oprs ann s0)))))
(ensures ((eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) | let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 72,
"end_line": 209,
"start_col": 0,
"start_line": 189
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 2,
"max_ifuel": 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 |
it: Vale.X64.Instruction_s.instr_t_record ->
oprs:
Vale.X64.Instruction_s.instr_operands_t (InstrTypeRecord?.outs it) (InstrTypeRecord?.args it) ->
ann: Vale.X64.Machine_Semantics_s.instr_annotation it ->
s0: Vale.X64.Machine_Semantics_s.machine_state ->
a: Vale.Transformers.Locations.location
-> FStar.Pervasives.Lemma
(requires
(let w =
Mkrw_set?.loc_writes (Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins (Vale.X64.Bytes_Code_s.Instr
it oprs ann))
in
!!(Vale.Transformers.Locations.disjoint_location_from_locations a w) /\
Some? (Vale.X64.Machine_Semantics_s.eval_instr it oprs ann s0)))
(ensures
Vale.Transformers.Locations.eval_location a s0 ==
Vale.Transformers.Locations.eval_location a
(Some?.v (Vale.X64.Machine_Semantics_s.eval_instr it oprs ann s0))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"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.Machine_Semantics_s.machine_state",
"Vale.Transformers.Locations.location",
"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.Transformers.BoundedInstructionEffects.lemma_instr_write_outputs_only_affects_write",
"Vale.X64.Machine_Semantics_s.instr_write_outputs",
"Prims.unit",
"FStar.Pervasives.Native.option",
"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",
"Vale.X64.Machine_Semantics_s.instr_apply_eval",
"Vale.X64.Instruction_s.instr_eval",
"Prims.l_and",
"Prims.b2t",
"Vale.Def.PossiblyMonad.op_Bang_Bang",
"Vale.Transformers.Locations.disjoint_location_from_locations",
"FStar.Pervasives.Native.uu___is_Some",
"Vale.X64.Machine_Semantics_s.eval_instr",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins",
"Vale.X64.Bytes_Code_s.Instr",
"Prims.squash",
"Prims.eq2",
"Vale.Transformers.Locations.location_val_t",
"Vale.Transformers.Locations.eval_location",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_eval_instr_only_affects_write
(it: instr_t_record)
(oprs: instr_operands_t it.outs it.args)
(ann: instr_annotation it)
(s0: machine_state)
(a: location)
: Lemma
(requires
((let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\ (Some? (eval_instr it oprs ann s0)))))
(ensures ((eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
| let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> { s0 with ms_flags = havoc_flags }
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a | false |
Steel.ST.GenArraySwap.fst | Steel.ST.GenArraySwap.elim_array_swap_inner_invariant | val elim_array_swap_inner_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(i: SZ.t)
(pj pidx: R.ref SZ.t)
(b: bool)
: STGhost (array_swap_inner_invariant_t t)
opened
(array_swap_inner_invariant pts_to n l bz s0 pi i pj pidx b)
(fun w -> array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b w.j w.idx w.s)
True
(fun w ->
array_swap_inner_invariant_prop (SZ.v n)
(SZ.v l)
bz
s0
w.s
(SZ.v i)
(SZ.v w.j)
(SZ.v w.idx)
b) | val elim_array_swap_inner_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(i: SZ.t)
(pj pidx: R.ref SZ.t)
(b: bool)
: STGhost (array_swap_inner_invariant_t t)
opened
(array_swap_inner_invariant pts_to n l bz s0 pi i pj pidx b)
(fun w -> array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b w.j w.idx w.s)
True
(fun w ->
array_swap_inner_invariant_prop (SZ.v n)
(SZ.v l)
bz
s0
w.s
(SZ.v i)
(SZ.v w.j)
(SZ.v w.idx)
b) | let elim_array_swap_inner_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(i: SZ.t)
(pj: R.ref SZ.t)
(pidx: R.ref SZ.t)
(b: bool)
: STGhost (array_swap_inner_invariant_t t) opened
(array_swap_inner_invariant pts_to n l bz s0 pi i pj pidx b)
(fun w -> array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b w.j w.idx w.s)
True
(fun w -> array_swap_inner_invariant_prop (SZ.v n) (SZ.v l) bz s0 w.s (SZ.v i) (SZ.v w.j) (SZ.v w.idx) b)
= let w = elim_exists () in
elim_pure _;
w | {
"file_name": "lib/steel/Steel.ST.GenArraySwap.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 374,
"start_col": 0,
"start_line": 354
} | module Steel.ST.GenArraySwap
open Steel.ST.GenElim
module Prf = Steel.ST.GenArraySwap.Proof
module R = Steel.ST.Reference
let gcd_inv_prop
(n0: nat)
(l0: nat)
(n: nat)
(l: nat)
(b: bool)
: Tot prop
= l0 < n0 /\
l < n /\
(Prf.mk_bezout n0 l0).d == (Prf.mk_bezout n l).d /\
b == (l > 0)
[@@__reduce__]
let gcd_inv0
(n0: SZ.t)
(l0: SZ.t)
(pn: R.ref SZ.t)
(pl: R.ref SZ.t)
(b: bool)
: Tot vprop
= exists_ (fun n -> exists_ (fun l ->
R.pts_to pn full_perm n `star`
R.pts_to pl full_perm l `star`
pure (gcd_inv_prop (SZ.v n0) (SZ.v l0) (SZ.v n) (SZ.v l) b)
))
let gcd_inv
(n0: SZ.t)
(l0: SZ.t)
(pn: R.ref SZ.t)
(pl: R.ref SZ.t)
(b: bool)
: Tot vprop
= gcd_inv0 n0 l0 pn pl b
let gcd_post
(n0: SZ.t)
(l0: SZ.t)
(res: SZ.t)
: Tot prop
= SZ.v l0 < SZ.v n0 /\
SZ.v res == (Prf.mk_bezout (SZ.v n0) (SZ.v l0)).d
#push-options "--z3rlimit 16"
#restart-solver
let gcd
(n0: SZ.t)
(l0: SZ.t)
: ST SZ.t
emp
(fun _ -> emp)
(SZ.v l0 < SZ.v n0)
(fun res -> gcd_post n0 l0 res)
= let res =
R.with_local n0 (fun pn ->
R.with_local l0 (fun pl ->
noop ();
rewrite (gcd_inv0 n0 l0 pn pl (l0 `SZ.gt` 0sz)) (gcd_inv n0 l0 pn pl (l0 `SZ.gt` 0sz));
Steel.ST.Loops.while_loop
(gcd_inv n0 l0 pn pl)
(fun _ ->
let gb = elim_exists () in
rewrite (gcd_inv n0 l0 pn pl gb) (gcd_inv0 n0 l0 pn pl gb);
let _ = gen_elim () in
let l = R.read pl in
[@@inline_let]
let b = l `SZ.gt` 0sz in
noop ();
rewrite (gcd_inv0 n0 l0 pn pl b) (gcd_inv n0 l0 pn pl b);
return b
)
(fun _ ->
rewrite (gcd_inv n0 l0 pn pl true) (gcd_inv0 n0 l0 pn pl true);
let _ = gen_elim () in
let n = R.read pn in
let l = R.read pl in
[@@inline_let]
let l' = SZ.rem n l in
R.write pn l;
R.write pl l';
rewrite (gcd_inv0 n0 l0 pn pl (l' `SZ.gt` 0sz)) (gcd_inv n0 l0 pn pl (l' `SZ.gt` 0sz));
noop ()
);
rewrite (gcd_inv n0 l0 pn pl false) (gcd_inv0 n0 l0 pn pl false);
let _ = gen_elim () in
let res = R.read pn in
return res
)
)
in
elim_pure (gcd_post n0 l0 res);
return res
#pop-options
let array_swap_partial_invariant
(#t: Type)
(n: nat)
(l: nat)
(bz: Prf.bezout n l)
(s0: Ghost.erased (Seq.seq t))
(s: Ghost.erased (Seq.seq t))
(i: nat)
: GTot prop
= n == Seq.length s0 /\
n == Seq.length s /\
0 < l /\
l < n /\
i <= bz.d /\
(forall (i': Prf.nat_up_to bz.d) .
(forall (j: Prf.nat_up_to bz.q_n) .
(i' < i) ==> (
let idx = Prf.iter_fun #(Prf.nat_up_to n) (Prf.jump n l) j i' in
Seq.index s idx == Seq.index s0 (Prf.jump n l idx)
))) /\
(forall (i': Prf.nat_up_to bz.d) .
(forall (j: Prf.nat_up_to bz.q_n) .
(i' > i) ==> (
let idx = Prf.iter_fun #(Prf.nat_up_to n) (Prf.jump n l) j i' in
Seq.index s idx == Seq.index s0 idx
)))
let array_swap_inner_invariant_prop
(#t: Type)
(n: nat)
(l: nat)
(bz: Prf.bezout n l)
(s0: Ghost.erased (Seq.seq t))
(s: Ghost.erased (Seq.seq t))
(i: nat)
(j: nat)
(idx: nat)
(b: bool)
: GTot prop
= Prf.array_swap_inner_invariant s0 n l bz s i j idx /\
(b == (j < bz.q_n - 1))
let array_swap_outer_invariant_prop
(#t: Type)
(n: nat)
(l: nat)
(bz: Prf.bezout n l)
(s0: Ghost.erased (Seq.seq t))
(s: Ghost.erased (Seq.seq t))
(i: nat)
(b: bool)
: GTot prop
= Prf.array_swap_outer_invariant s0 n l bz s i /\
(b == (i < bz.d))
[@@__reduce__]
let array_swap_outer_invariant_body0
(#t: Type)
(pts_to: array_pts_to_t t)
(pi: R.ref SZ.t)
(i: SZ.t)
(s: Ghost.erased (Seq.seq t))
: Tot vprop
=
R.pts_to pi full_perm i `star`
pts_to s
[@@erasable]
noeq
type array_swap_outer_invariant_t (t: Type)
= {
i: SZ.t;
s: Ghost.erased (Seq.seq t);
}
[@@__reduce__]
let array_swap_outer_invariant0
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(b: bool)
: Tot vprop
= exists_ (fun w ->
array_swap_outer_invariant_body0 pts_to pi w.i w.s `star`
pure (array_swap_outer_invariant_prop (SZ.v n) (SZ.v l) bz s0 w.s (SZ.v w.i) b)
)
let array_swap_outer_invariant
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(b: bool)
: Tot vprop
= array_swap_outer_invariant0 pts_to n l bz s0 pi b
let intro_array_swap_outer_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(b: bool)
(i: SZ.t)
(s: Ghost.erased (Seq.seq t))
: STGhost unit opened
(array_swap_outer_invariant_body0 pts_to pi i s)
(fun _ -> array_swap_outer_invariant pts_to n l bz s0 pi b)
(array_swap_outer_invariant_prop (SZ.v n) (SZ.v l) bz s0 s (SZ.v i) b)
(fun _ -> True)
= let w = {
i = i;
s = s;
}
in
rewrite (array_swap_outer_invariant_body0 pts_to pi i s) (array_swap_outer_invariant_body0 pts_to pi w.i w.s);
rewrite (array_swap_outer_invariant0 pts_to n l bz s0 pi b) (array_swap_outer_invariant pts_to n l bz s0 pi b)
let elim_array_swap_outer_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(b: bool)
: STGhost (array_swap_outer_invariant_t t) opened
(array_swap_outer_invariant pts_to n l bz s0 pi b)
(fun w -> array_swap_outer_invariant_body0 pts_to pi w.i w.s)
True
(fun w ->
array_swap_outer_invariant_prop (SZ.v n) (SZ.v l) bz s0 w.s (SZ.v w.i) b /\
True // (b == false ==> Ghost.reveal w.s `Seq.equal` (Seq.slice s0 (SZ.v l) (SZ.v n) `Seq.append` Seq.slice s0 0 (SZ.v l)))
)
= let w = elim_exists () in
let _ = gen_elim () in
// Classical.move_requires (array_swap_outer_invariant_prop_end (SZ.v n) (SZ.v l) bz s0 w.s (SZ.v w.i)) b;
noop ();
w
[@@erasable]
noeq
type array_swap_inner_invariant_t (t: Type)
= {
j: SZ.t;
idx: SZ.t;
s: Ghost.erased (Seq.seq t)
}
[@@__reduce__]
let array_swap_inner_invariant_body0
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(i: SZ.t)
(pj: R.ref SZ.t)
(pidx: R.ref SZ.t)
(b: bool)
(j: SZ.t)
(idx: SZ.t)
(s: Ghost.erased (Seq.seq t))
: Tot vprop
= R.pts_to pi full_perm i `star`
R.pts_to pj full_perm j `star`
R.pts_to pidx full_perm idx `star`
pts_to s
[@@__reduce__]
let array_swap_inner_invariant0
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(i: SZ.t)
(pj: R.ref SZ.t)
(pidx: R.ref SZ.t)
(b: bool)
: Tot vprop
= exists_ (fun w ->
array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b w.j w.idx w.s `star`
pure (array_swap_inner_invariant_prop (SZ.v n) (SZ.v l) bz s0 w.s (SZ.v i) (SZ.v w.j) (SZ.v w.idx) b)
)
let array_swap_inner_invariant
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(i: SZ.t)
(pj: R.ref SZ.t)
(pidx: R.ref SZ.t)
(b: bool)
: Tot vprop
= array_swap_inner_invariant0 pts_to n l bz s0 pi i pj pidx b
let intro_array_swap_inner_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n: SZ.t)
(l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(i: SZ.t)
(pj: R.ref SZ.t)
(pidx: R.ref SZ.t)
(b: bool)
(j: SZ.t)
(idx: SZ.t)
(s: Ghost.erased (Seq.seq t))
: STGhost unit opened
(array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b j idx s)
(fun _ -> array_swap_inner_invariant pts_to n l bz s0 pi i pj pidx b)
(array_swap_inner_invariant_prop (SZ.v n) (SZ.v l) bz s0 s (SZ.v i) (SZ.v j) (SZ.v idx) b)
(fun _ -> True)
= let w = {
j = j;
idx = idx;
s = s;
}
in
rewrite
(array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b j idx s)
(array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b w.j w.idx w.s);
rewrite
(array_swap_inner_invariant0 pts_to n l bz s0 pi i pj pidx b)
(array_swap_inner_invariant pts_to n l bz s0 pi i pj pidx b) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Reference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.ST.GenElim.fsti.checked",
"Steel.ST.GenArraySwap.Proof.fst.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenArraySwap.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.ST.Reference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "Steel.ST.GenArraySwap.Proof",
"short_module": "Prf"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "SZ"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"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 |
pts_to: Steel.ST.GenArraySwap.array_pts_to_t t ->
n: FStar.SizeT.t ->
l: FStar.SizeT.t ->
bz: Steel.ST.GenArraySwap.Proof.bezout (FStar.SizeT.v n) (FStar.SizeT.v l) ->
s0: FStar.Ghost.erased (FStar.Seq.Base.seq t) ->
pi: Steel.ST.Reference.ref FStar.SizeT.t ->
i: FStar.SizeT.t ->
pj: Steel.ST.Reference.ref FStar.SizeT.t ->
pidx: Steel.ST.Reference.ref FStar.SizeT.t ->
b: Prims.bool
-> Steel.ST.Effect.Ghost.STGhost (Steel.ST.GenArraySwap.array_swap_inner_invariant_t t) | Steel.ST.Effect.Ghost.STGhost | [] | [] | [
"Steel.Memory.inames",
"Steel.ST.GenArraySwap.array_pts_to_t",
"FStar.SizeT.t",
"Steel.ST.GenArraySwap.Proof.bezout",
"FStar.SizeT.v",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Steel.ST.Reference.ref",
"Prims.bool",
"FStar.Ghost.reveal",
"Steel.ST.GenArraySwap.array_swap_inner_invariant_t",
"Prims.unit",
"Steel.ST.Util.elim_pure",
"Steel.ST.GenArraySwap.array_swap_inner_invariant_prop",
"Steel.ST.GenArraySwap.__proj__Mkarray_swap_inner_invariant_t__item__s",
"Steel.ST.GenArraySwap.__proj__Mkarray_swap_inner_invariant_t__item__j",
"Steel.ST.GenArraySwap.__proj__Mkarray_swap_inner_invariant_t__item__idx",
"Steel.ST.Util.elim_exists",
"Steel.Effect.Common.star",
"Steel.ST.GenArraySwap.array_swap_inner_invariant_body0",
"Steel.ST.Util.pure",
"Steel.Effect.Common.vprop",
"Steel.ST.GenArraySwap.array_swap_inner_invariant",
"Prims.l_True"
] | [] | false | true | false | false | false | let elim_array_swap_inner_invariant
(#opened: _)
(#t: Type)
(pts_to: array_pts_to_t t)
(n l: SZ.t)
(bz: Prf.bezout (SZ.v n) (SZ.v l))
(s0: Ghost.erased (Seq.seq t))
(pi: R.ref SZ.t)
(i: SZ.t)
(pj pidx: R.ref SZ.t)
(b: bool)
: STGhost (array_swap_inner_invariant_t t)
opened
(array_swap_inner_invariant pts_to n l bz s0 pi i pj pidx b)
(fun w -> array_swap_inner_invariant_body0 pts_to n l bz s0 pi i pj pidx b w.j w.idx w.s)
True
(fun w ->
array_swap_inner_invariant_prop (SZ.v n)
(SZ.v l)
bz
s0
w.s
(SZ.v i)
(SZ.v w.j)
(SZ.v w.idx)
b) =
| let w = elim_exists () in
elim_pure _;
w | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at'_mem | val lemma_unchanged_at'_mem (as0: locations) (a: location) (s1 s2: machine_state)
: Lemma (requires ((unchanged_at' as0 s1 s2) /\ (L.mem a as0)))
(ensures ((eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) | val lemma_unchanged_at'_mem (as0: locations) (a: location) (s1 s2: machine_state)
: Lemma (requires ((unchanged_at' as0 s1 s2) /\ (L.mem a as0)))
(ensures ((eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) | let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 414,
"start_col": 0,
"start_line": 403
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 2,
"max_ifuel": 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 |
as0: Vale.Transformers.Locations.locations ->
a: Vale.Transformers.Locations.location ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
Vale.Transformers.BoundedInstructionEffects.unchanged_at' as0 s1 s2 /\
FStar.List.Tot.Base.mem a as0)
(ensures
Vale.Transformers.Locations.eval_location a s1 ==
Vale.Transformers.Locations.eval_location a s2 \/
Prims.op_Negation (Mkmachine_state?.ms_ok s1)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.Transformers.Locations.location",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.list",
"Prims.op_Equality",
"Prims.bool",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at'_mem",
"Prims.unit",
"Prims.l_and",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at'",
"Prims.b2t",
"FStar.List.Tot.Base.mem",
"Prims.squash",
"Prims.l_or",
"Prims.eq2",
"Vale.Transformers.Locations.location_val_t",
"Vale.Transformers.Locations.eval_location",
"Prims.op_Negation",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_unchanged_at'_mem (as0: locations) (a: location) (s1 s2: machine_state)
: Lemma (requires ((unchanged_at' as0 s1 s2) /\ (L.mem a as0)))
(ensures ((eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
| match as0 with
| [_] -> ()
| x :: xs -> if a = x then () else lemma_unchanged_at'_mem xs a s1 s2 | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_instr_apply_eval_same_read | val lemma_instr_apply_eval_same_read
(outs: list instr_out)
(args: list instr_operand)
(f: instr_eval_t outs args)
(oprs: instr_operands_t outs args)
(s1 s2: machine_state)
: Lemma (requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures ((instr_apply_eval outs args f oprs s1) == (instr_apply_eval outs args f oprs s2))) | val lemma_instr_apply_eval_same_read
(outs: list instr_out)
(args: list instr_operand)
(f: instr_eval_t outs args)
(oprs: instr_operands_t outs args)
(s1 s2: machine_state)
: Lemma (requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures ((instr_apply_eval outs args f oprs s1) == (instr_apply_eval outs args f oprs s2))) | let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 359,
"start_col": 0,
"start_line": 350
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 ->
f: Vale.X64.Instruction_s.instr_eval_t outs args ->
oprs: Vale.X64.Instruction_s.instr_operands_t outs args ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Vale.Transformers.BoundedInstructionEffects.aux_read_set1
outs
args
oprs)
s1
s2)
(ensures
Vale.X64.Machine_Semantics_s.instr_apply_eval outs args f oprs s1 ==
Vale.X64.Machine_Semantics_s.instr_apply_eval 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_eval_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.BoundedInstructionEffects.lemma_instr_apply_eval_inouts_same_read",
"Prims.unit",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.Transformers.BoundedInstructionEffects.aux_read_set1",
"Prims.squash",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Machine_Semantics_s.instr_apply_eval",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_instr_apply_eval_same_read
(outs: list instr_out)
(args: list instr_operand)
(f: instr_eval_t outs args)
(oprs: instr_operands_t outs args)
(s1 s2: machine_state)
: Lemma (requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures ((instr_apply_eval outs args f oprs s1) == (instr_apply_eval outs args f oprs s2))) =
| lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2 | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.sym_difference | val sym_difference (#t: eqtype) (l1 l2: list t) : list t | val sym_difference (#t: eqtype) (l1 l2: list t) : list t | let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 855,
"start_col": 0,
"start_line": 854
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | l1: Prims.list t -> l2: Prims.list t -> Prims.list t | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"Prims.list",
"FStar.List.Tot.Base.append",
"Vale.Transformers.BoundedInstructionEffects.difference"
] | [] | false | false | false | false | false | let sym_difference (#t: eqtype) (l1 l2: list t) : list t =
| (difference l1 l2) `L.append` (difference l2 l1) | false |
EverParse3d.Actions.All.fst | EverParse3d.Actions.All.action_field_pos_32 | val action_field_pos_32
(u:squash (EverParse3d.Actions.BackendFlag.backend_flag == BackendFlagBuffer))
: action true_inv disjointness_trivial eloc_none false FStar.UInt32.t | val action_field_pos_32
(u:squash (EverParse3d.Actions.BackendFlag.backend_flag == BackendFlagBuffer))
: action true_inv disjointness_trivial eloc_none false FStar.UInt32.t | let action_field_pos_32 u = false_elim () | {
"file_name": "src/3d/prelude/extern/EverParse3d.Actions.All.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 41,
"end_line": 33,
"start_col": 0,
"start_line": 33
} | module EverParse3d.Actions.All
friend EverParse3d.Actions.Base
friend EverParse3d.InputStream.All
let _ = EverParse3d.Actions.BackendFlagValue.backend_flag_value
let ___PUINT8 = (b:LowStar.Buffer.buffer FStar.UInt8.t { ~ (LowStar.Buffer.g_is_null b) })
let action_field_ptr u = false_elim ()
let action_field_ptr_after _ n write_to =
fun ctxt _err input _len _posBefore currentPosition ->
let buf = EverParse3d.InputStream.Extern.peep input currentPosition n in
let buf_not_null = not (LowStar.Buffer.is_null buf) in
if buf_not_null
then begin
let open LowStar.BufferOps in
ptr_inv_elim write_to;
write_to *= buf
end;
buf_not_null
let action_field_ptr_after_with_setter _ n write_to =
fun ctxt _err input _len _posBefore currentPosition ->
let buf = EverParse3d.InputStream.Extern.peep input currentPosition n in
let buf_not_null = not (LowStar.Buffer.is_null buf) in
if buf_not_null
then
write_to buf ()
;
buf_not_null | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"EverParse3d.InputStream.Extern.fst.checked",
"EverParse3d.InputStream.All.fst.checked",
"EverParse3d.Actions.Base.fst.checked",
"EverParse3d.Actions.BackendFlagValue.fsti.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Actions.All.fst"
} | [
{
"abbrev": true,
"full_module": "EverParse3d.Prelude",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 8,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
u29:
Prims.squash (EverParse3d.Actions.BackendFlag.backend_flag ==
EverParse3d.Actions.Base.BackendFlagBuffer)
-> EverParse3d.Actions.Base.action EverParse3d.Actions.Base.true_inv
EverParse3d.Actions.Base.disjointness_trivial
EverParse3d.Actions.Base.eloc_none
false
FStar.UInt32.t | Prims.Tot | [
"total"
] | [] | [
"Prims.squash",
"Prims.eq2",
"EverParse3d.Actions.Base.backend_flag_t",
"EverParse3d.Actions.BackendFlag.backend_flag",
"EverParse3d.Actions.Base.BackendFlagBuffer",
"FStar.Pervasives.false_elim",
"EverParse3d.Actions.Base.action",
"EverParse3d.Actions.Base.true_inv",
"EverParse3d.Actions.Base.disjointness_trivial",
"EverParse3d.Actions.Base.eloc_none",
"FStar.UInt32.t"
] | [] | false | false | false | false | false | let action_field_pos_32 u =
| false_elim () | false |
EverParse3d.Actions.All.fst | EverParse3d.Actions.All.action_field_ptr | val action_field_ptr
(u:squash (EverParse3d.Actions.BackendFlag.backend_flag == BackendFlagBuffer))
: action true_inv disjointness_trivial eloc_none true ___PUINT8 | val action_field_ptr
(u:squash (EverParse3d.Actions.BackendFlag.backend_flag == BackendFlagBuffer))
: action true_inv disjointness_trivial eloc_none true ___PUINT8 | let action_field_ptr u = false_elim () | {
"file_name": "src/3d/prelude/extern/EverParse3d.Actions.All.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 38,
"end_line": 9,
"start_col": 0,
"start_line": 9
} | module EverParse3d.Actions.All
friend EverParse3d.Actions.Base
friend EverParse3d.InputStream.All
let _ = EverParse3d.Actions.BackendFlagValue.backend_flag_value
let ___PUINT8 = (b:LowStar.Buffer.buffer FStar.UInt8.t { ~ (LowStar.Buffer.g_is_null b) }) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"EverParse3d.InputStream.Extern.fst.checked",
"EverParse3d.InputStream.All.fst.checked",
"EverParse3d.Actions.Base.fst.checked",
"EverParse3d.Actions.BackendFlagValue.fsti.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Actions.All.fst"
} | [
{
"abbrev": true,
"full_module": "EverParse3d.Prelude",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 8,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
u3:
Prims.squash (EverParse3d.Actions.BackendFlag.backend_flag ==
EverParse3d.Actions.Base.BackendFlagBuffer)
-> EverParse3d.Actions.Base.action EverParse3d.Actions.Base.true_inv
EverParse3d.Actions.Base.disjointness_trivial
EverParse3d.Actions.Base.eloc_none
true
EverParse3d.Actions.All.___PUINT8 | Prims.Tot | [
"total"
] | [] | [
"Prims.squash",
"Prims.eq2",
"EverParse3d.Actions.Base.backend_flag_t",
"EverParse3d.Actions.BackendFlag.backend_flag",
"EverParse3d.Actions.Base.BackendFlagBuffer",
"FStar.Pervasives.false_elim",
"EverParse3d.Actions.Base.action",
"EverParse3d.Actions.Base.true_inv",
"EverParse3d.Actions.Base.disjointness_trivial",
"EverParse3d.Actions.Base.eloc_none",
"EverParse3d.Actions.All.___PUINT8"
] | [] | false | false | false | false | false | let action_field_ptr u =
| false_elim () | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_instr_apply_eval_args_same_read | val lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures
((instr_apply_eval_args outs args f oprs s1) == (instr_apply_eval_args outs args f oprs s2))
) | val lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures
((instr_apply_eval_args outs args f oprs s1) == (instr_apply_eval_args outs args f oprs s2))
) | let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 70,
"end_line": 302,
"start_col": 0,
"start_line": 266
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 ->
f: Vale.X64.Instruction_s.instr_args_t outs args ->
oprs: Vale.X64.Instruction_s.instr_operands_t_args args ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Vale.Transformers.BoundedInstructionEffects.aux_read_set0
args
oprs)
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.Machine_Semantics_s.machine_state",
"FStar.Pervasives.Native.option",
"Vale.X64.Instruction_s.instr_val_t",
"Vale.Transformers.BoundedInstructionEffects.lemma_instr_apply_eval_args_same_read",
"Prims.unit",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Machine_Semantics_s.bind_option",
"Vale.X64.Machine_Semantics_s.instr_apply_eval_args",
"Vale.X64.Instruction_s.arrow",
"Vale.X64.Instruction_s.coerce",
"Prims._assert",
"Prims.eq2",
"FStar.Pervasives.Native.tuple3",
"Vale.X64.Instruction_s.instr_operand_explicit",
"FStar.Pervasives.Native.Mktuple3",
"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.Transformers.BoundedInstructionEffects.lemma_instr_eval_operand_explicit_same_read_both",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_append",
"Vale.Transformers.BoundedInstructionEffects.both",
"Vale.Transformers.BoundedInstructionEffects.locations_of_explicit",
"Vale.Transformers.BoundedInstructionEffects.aux_read_set0",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.Instruction_s.instr_operand_implicit",
"Vale.X64.Machine_Semantics_s.instr_eval_operand_implicit",
"Vale.Transformers.BoundedInstructionEffects.lemma_instr_eval_operand_implicit_same_read_both",
"Vale.Transformers.BoundedInstructionEffects.locations_of_implicit",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures
((instr_apply_eval_args outs args f oprs s1) == (instr_apply_eval_args outs args f oprs s2))
) =
| match args with
| [] -> ()
| i :: args ->
let v1, v2, oprs:option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs)))
(aux_read_set0 args (snd oprs))
s1
s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1, instr_eval_operand_implicit i s2, coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v -> lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2 | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_instr_write_outputs_only_affects_write_extend | val lemma_instr_write_outputs_only_affects_write_extend
(outs: list instr_out)
(args: list instr_operand)
(vs: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(s_orig s: machine_state)
(locs_extension: locations)
: Lemma
(ensures
(let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) | val lemma_instr_write_outputs_only_affects_write_extend
(outs: list instr_out)
(args: list instr_operand)
(vs: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(s_orig s: machine_state)
(locs_extension: locations)
: Lemma
(ensures
(let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) | let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s' | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 56,
"end_line": 485,
"start_col": 0,
"start_line": 471
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 ->
vs: Vale.X64.Instruction_s.instr_ret_t outs ->
oprs: Vale.X64.Instruction_s.instr_operands_t outs args ->
s_orig: Vale.X64.Machine_Semantics_s.machine_state ->
s: Vale.X64.Machine_Semantics_s.machine_state ->
locs_extension: Vale.Transformers.Locations.locations
-> FStar.Pervasives.Lemma
(ensures
(let s' = Vale.X64.Machine_Semantics_s.instr_write_outputs outs args vs oprs s_orig s in
let locs = Vale.Transformers.BoundedInstructionEffects.aux_write_set outs args oprs in
Vale.Transformers.BoundedInstructionEffects.unchanged_except (locs_extension @ locs) s s')) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Vale.X64.Instruction_s.instr_out",
"Vale.X64.Instruction_s.instr_operand",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.X64.Instruction_s.instr_operands_t",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.Locations.locations",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_except_extend",
"Prims.unit",
"FStar.Classical.forall_intro",
"Vale.Transformers.Locations.location",
"Prims.l_imp",
"Prims.b2t",
"Vale.Def.PossiblyMonad.op_Bang_Bang",
"Vale.Transformers.Locations.disjoint_location_from_locations",
"Vale.Transformers.BoundedInstructionEffects.aux_write_set",
"Prims.eq2",
"Vale.Transformers.Locations.location_val_t",
"Vale.Transformers.Locations.eval_location",
"Vale.X64.Machine_Semantics_s.instr_write_outputs",
"FStar.Classical.move_requires",
"Vale.Transformers.BoundedInstructionEffects.lemma_instr_write_outputs_only_affects_write",
"Prims.l_True",
"Prims.squash",
"Vale.Transformers.BoundedInstructionEffects.unchanged_except",
"FStar.List.Tot.Base.append",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_instr_write_outputs_only_affects_write_extend
(outs: list instr_out)
(args: list instr_operand)
(vs: instr_ret_t outs)
(oprs: instr_operands_t outs args)
(s_orig s: machine_state)
(locs_extension: locations)
: Lemma
(ensures
(let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
| let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro (FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write
outs
args
vs
oprs
s_orig
s));
lemma_unchanged_except_extend locs_extension locs s s' | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_except_not_mem | val lemma_unchanged_except_not_mem (as0: locations) (a: location)
: Lemma (requires ((not (L.mem a as0)))) (ensures (!!(disjoint_location_from_locations a as0))) | val lemma_unchanged_except_not_mem (as0: locations) (a: location)
: Lemma (requires ((not (L.mem a as0)))) (ensures (!!(disjoint_location_from_locations a as0))) | let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 425,
"start_col": 0,
"start_line": 417
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | as0: Vale.Transformers.Locations.locations -> a: Vale.Transformers.Locations.location
-> FStar.Pervasives.Lemma (requires Prims.op_Negation (FStar.List.Tot.Base.mem a as0))
(ensures !!(Vale.Transformers.Locations.disjoint_location_from_locations a as0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.Transformers.Locations.location",
"Prims.list",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_except_not_mem",
"Prims.unit",
"Prims.b2t",
"Prims.op_Negation",
"FStar.List.Tot.Base.mem",
"Prims.squash",
"Vale.Def.PossiblyMonad.op_Bang_Bang",
"Vale.Transformers.Locations.disjoint_location_from_locations",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_unchanged_except_not_mem (as0: locations) (a: location)
: Lemma (requires ((not (L.mem a as0)))) (ensures (!!(disjoint_location_from_locations a as0))) =
| match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_except_extend | val lemma_unchanged_except_extend (ls_extend ls: locations) (s1 s2: machine_state)
: Lemma (requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) | val lemma_unchanged_except_extend (ls_extend ls: locations) (s1 s2: machine_state)
: Lemma (requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) | let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 66,
"end_line": 469,
"start_col": 0,
"start_line": 459
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
ls_extend: Vale.Transformers.Locations.locations ->
ls: Vale.Transformers.Locations.locations ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires Vale.Transformers.BoundedInstructionEffects.unchanged_except ls s1 s2)
(ensures Vale.Transformers.BoundedInstructionEffects.unchanged_except (ls_extend @ ls) s1 s2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.X64.Machine_Semantics_s.machine_state",
"FStar.Classical.forall_intro",
"Vale.Transformers.Locations.location",
"Prims.l_imp",
"Prims.b2t",
"Vale.Def.PossiblyMonad.op_Bang_Bang",
"Vale.Transformers.Locations.disjoint_location_from_locations",
"FStar.List.Tot.Base.append",
"Prims.eq2",
"Vale.Transformers.Locations.location_val_t",
"Vale.Transformers.Locations.eval_location",
"FStar.Classical.move_requires",
"Prims.unit",
"Vale.Def.PossiblyMonad.uu___is_Ok",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Vale.Transformers.BoundedInstructionEffects.lemma_disjoint_location_from_locations_append",
"Vale.Transformers.BoundedInstructionEffects.unchanged_except"
] | [] | false | false | true | false | false | let lemma_unchanged_except_extend (ls_extend ls: locations) (s1 s2: machine_state)
: Lemma (requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
| let aux a
: Lemma (requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_disjoint_location_from_locations_append | val lemma_disjoint_location_from_locations_append (a: location) (as1 as2: list location)
: Lemma
((!!(disjoint_location_from_locations a as1) /\ !!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) | val lemma_disjoint_location_from_locations_append (a: location) (as1 as2: list location)
: Lemma
((!!(disjoint_location_from_locations a as1) /\ !!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) | let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 457,
"start_col": 0,
"start_line": 448
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Vale.Transformers.Locations.location ->
as1: Prims.list Vale.Transformers.Locations.location ->
as2: Prims.list Vale.Transformers.Locations.location
-> FStar.Pervasives.Lemma
(ensures
!!(Vale.Transformers.Locations.disjoint_location_from_locations a as1) /\
!!(Vale.Transformers.Locations.disjoint_location_from_locations a as2) <==>
!!(Vale.Transformers.Locations.disjoint_location_from_locations a (as1 @ as2))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.location",
"Prims.list",
"Vale.Transformers.BoundedInstructionEffects.lemma_disjoint_location_from_locations_append",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_iff",
"Prims.l_and",
"Prims.b2t",
"Vale.Def.PossiblyMonad.op_Bang_Bang",
"Vale.Transformers.Locations.disjoint_location_from_locations",
"FStar.List.Tot.Base.append",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_disjoint_location_from_locations_append (a: location) (as1 as2: list location)
: Lemma
((!!(disjoint_location_from_locations a as1) /\ !!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
| match as1 with
| [] -> ()
| x :: xs -> lemma_disjoint_location_from_locations_append a xs as2 | false |
EverParse3d.Actions.All.fst | EverParse3d.Actions.All.action_field_ptr_after_with_setter | val action_field_ptr_after_with_setter
(u:squash (EverParse3d.Actions.BackendFlag.backend_flag == BackendFlagExtern))
(sz: FStar.UInt64.t)
(#output_loc: eloc)
(write_to: (___PUINT8 -> Tot (external_action output_loc)))
: action true_inv disjointness_trivial output_loc false bool | val action_field_ptr_after_with_setter
(u:squash (EverParse3d.Actions.BackendFlag.backend_flag == BackendFlagExtern))
(sz: FStar.UInt64.t)
(#output_loc: eloc)
(write_to: (___PUINT8 -> Tot (external_action output_loc)))
: action true_inv disjointness_trivial output_loc false bool | let action_field_ptr_after_with_setter _ n write_to =
fun ctxt _err input _len _posBefore currentPosition ->
let buf = EverParse3d.InputStream.Extern.peep input currentPosition n in
let buf_not_null = not (LowStar.Buffer.is_null buf) in
if buf_not_null
then
write_to buf ()
;
buf_not_null | {
"file_name": "src/3d/prelude/extern/EverParse3d.Actions.All.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 14,
"end_line": 31,
"start_col": 0,
"start_line": 23
} | module EverParse3d.Actions.All
friend EverParse3d.Actions.Base
friend EverParse3d.InputStream.All
let _ = EverParse3d.Actions.BackendFlagValue.backend_flag_value
let ___PUINT8 = (b:LowStar.Buffer.buffer FStar.UInt8.t { ~ (LowStar.Buffer.g_is_null b) })
let action_field_ptr u = false_elim ()
let action_field_ptr_after _ n write_to =
fun ctxt _err input _len _posBefore currentPosition ->
let buf = EverParse3d.InputStream.Extern.peep input currentPosition n in
let buf_not_null = not (LowStar.Buffer.is_null buf) in
if buf_not_null
then begin
let open LowStar.BufferOps in
ptr_inv_elim write_to;
write_to *= buf
end;
buf_not_null | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"EverParse3d.InputStream.Extern.fst.checked",
"EverParse3d.InputStream.All.fst.checked",
"EverParse3d.Actions.Base.fst.checked",
"EverParse3d.Actions.BackendFlagValue.fsti.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Actions.All.fst"
} | [
{
"abbrev": true,
"full_module": "EverParse3d.Prelude",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 8,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
u26:
Prims.squash (EverParse3d.Actions.BackendFlag.backend_flag ==
EverParse3d.Actions.Base.BackendFlagExtern) ->
sz: FStar.UInt64.t ->
write_to:
(_: EverParse3d.Actions.All.___PUINT8 -> EverParse3d.Actions.Base.external_action output_loc)
-> EverParse3d.Actions.Base.action EverParse3d.Actions.Base.true_inv
EverParse3d.Actions.Base.disjointness_trivial
output_loc
false
Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.squash",
"Prims.eq2",
"EverParse3d.Actions.Base.backend_flag_t",
"EverParse3d.Actions.BackendFlag.backend_flag",
"EverParse3d.Actions.Base.BackendFlagExtern",
"FStar.UInt64.t",
"EverParse3d.Actions.Base.eloc",
"EverParse3d.Actions.All.___PUINT8",
"EverParse3d.Actions.Base.external_action",
"EverParse3d.InputStream.Base.extra_t",
"EverParse3d.Actions.Base.input_buffer_t",
"EverParse3d.InputStream.All.inst",
"EverParse3d.Actions.Base.app_ctxt",
"EverParse3d.Actions.Base.error_handler",
"EverParse3d.InputStream.Base.tlen",
"EverParse3d.ErrorCode.pos_t",
"Prims.bool",
"Prims.unit",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.is_null",
"FStar.UInt8.t",
"LowStar.Buffer.trivial_preorder",
"LowStar.Buffer.buffer",
"EverParse3d.InputStream.Extern.peep"
] | [] | false | false | false | false | false | let action_field_ptr_after_with_setter _ n write_to =
| fun ctxt _err input _len _posBefore currentPosition ->
let buf = EverParse3d.InputStream.Extern.peep input currentPosition n in
let buf_not_null = not (LowStar.Buffer.is_null buf) in
if buf_not_null then write_to buf ();
buf_not_null | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at'_maintained | val lemma_unchanged_at'_maintained (locs locs_change: locations) (s1 s1' s2 s2': machine_state)
: Lemma
(requires
((not s1.ms_ok ==> not s1'.ms_ok) /\ (not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\ (unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\ (unchanged_at' locs_change s1' s2')))
(ensures ((unchanged_at' locs s1' s2'))) | val lemma_unchanged_at'_maintained (locs locs_change: locations) (s1 s1' s2 s2': machine_state)
: Lemma
(requires
((not s1.ms_ok ==> not s1'.ms_ok) /\ (not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\ (unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\ (unchanged_at' locs_change s1' s2')))
(ensures ((unchanged_at' locs s1' s2'))) | let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 446,
"start_col": 0,
"start_line": 427
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
locs: Vale.Transformers.Locations.locations ->
locs_change: Vale.Transformers.Locations.locations ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s1': Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state ->
s2': Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
(Prims.op_Negation (Mkmachine_state?.ms_ok s1) ==>
Prims.op_Negation (Mkmachine_state?.ms_ok s1')) /\
(Prims.op_Negation (Mkmachine_state?.ms_ok s2) ==>
Prims.op_Negation (Mkmachine_state?.ms_ok s2')) /\
Vale.Transformers.BoundedInstructionEffects.unchanged_at' locs s1 s2 /\
Vale.Transformers.BoundedInstructionEffects.unchanged_except locs_change s1 s1' /\
Vale.Transformers.BoundedInstructionEffects.unchanged_except locs_change s2 s2' /\
Vale.Transformers.BoundedInstructionEffects.unchanged_at' locs_change s1' s2')
(ensures Vale.Transformers.BoundedInstructionEffects.unchanged_at' locs s1' s2') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.Locations.location",
"Prims.list",
"FStar.List.Tot.Base.mem",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at'_mem",
"Prims.bool",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_except_not_mem",
"Prims.unit",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at'_maintained",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Negation",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at'",
"Vale.Transformers.BoundedInstructionEffects.unchanged_except",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_unchanged_at'_maintained (locs locs_change: locations) (s1 s1' s2 s2': machine_state)
: Lemma
(requires
((not s1.ms_ok ==> not s1'.ms_ok) /\ (not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\ (unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\ (unchanged_at' locs_change s1' s2')))
(ensures ((unchanged_at' locs s1' s2'))) =
| match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change
then (lemma_unchanged_at'_mem locs_change x s1' s2')
else (lemma_unchanged_except_not_mem locs_change x) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_ok | val lemma_machine_eval_ins_st_ok (i: ins{Instr? i}) (s1 s2: machine_state)
: Lemma
(requires
(let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\ (unchanged_at r s1 s2)))
(ensures
(let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) | val lemma_machine_eval_ins_st_ok (i: ins{Instr? i}) (s1 s2: machine_state)
: Lemma
(requires
(let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\ (unchanged_at r s1 s2)))
(ensures
(let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) | let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 644,
"start_col": 0,
"start_line": 634
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
i: Vale.X64.Machine_Semantics_s.ins{Instr? i} ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
(let r =
Mkrw_set?.loc_reads (Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins i)
in
Mkmachine_state?.ms_ok s1 = Mkmachine_state?.ms_ok s2 /\
Vale.Transformers.BoundedInstructionEffects.unchanged_at r s1 s2))
(ensures
(let f = Vale.X64.Machine_Semantics_s.machine_eval_ins_st i in
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run f s1) =
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run f s2))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Machine_Semantics_s.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.Transformers.BoundedInstructionEffects.lemma_eval_instr_unchanged_at'",
"Prims.unit",
"Prims.l_and",
"Prims.op_Equality",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Prims.list",
"Vale.Transformers.Locations.location",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_reads",
"Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins",
"Prims.squash",
"Vale.X64.Machine_Semantics_s.run",
"Vale.X64.Machine_Semantics_s.st",
"Vale.X64.Machine_Semantics_s.machine_eval_ins_st",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_machine_eval_ins_st_ok (i: ins{Instr? i}) (s1 s2: machine_state)
: Lemma
(requires
(let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\ (unchanged_at r s1 s2)))
(ensures
(let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
| let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2 | false |
EverParse3d.Actions.All.fst | EverParse3d.Actions.All.action_field_ptr_after | val action_field_ptr_after
(u:squash (EverParse3d.Actions.BackendFlag.backend_flag == BackendFlagExtern))
(sz: FStar.UInt64.t)
(write_to: bpointer ___PUINT8)
: action (ptr_inv write_to) disjointness_trivial (ptr_loc write_to) false bool | val action_field_ptr_after
(u:squash (EverParse3d.Actions.BackendFlag.backend_flag == BackendFlagExtern))
(sz: FStar.UInt64.t)
(write_to: bpointer ___PUINT8)
: action (ptr_inv write_to) disjointness_trivial (ptr_loc write_to) false bool | let action_field_ptr_after _ n write_to =
fun ctxt _err input _len _posBefore currentPosition ->
let buf = EverParse3d.InputStream.Extern.peep input currentPosition n in
let buf_not_null = not (LowStar.Buffer.is_null buf) in
if buf_not_null
then begin
let open LowStar.BufferOps in
ptr_inv_elim write_to;
write_to *= buf
end;
buf_not_null | {
"file_name": "src/3d/prelude/extern/EverParse3d.Actions.All.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 14,
"end_line": 21,
"start_col": 0,
"start_line": 11
} | module EverParse3d.Actions.All
friend EverParse3d.Actions.Base
friend EverParse3d.InputStream.All
let _ = EverParse3d.Actions.BackendFlagValue.backend_flag_value
let ___PUINT8 = (b:LowStar.Buffer.buffer FStar.UInt8.t { ~ (LowStar.Buffer.g_is_null b) })
let action_field_ptr u = false_elim () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.Pervasives.fsti.checked",
"EverParse3d.InputStream.Extern.fst.checked",
"EverParse3d.InputStream.All.fst.checked",
"EverParse3d.Actions.Base.fst.checked",
"EverParse3d.Actions.BackendFlagValue.fsti.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Actions.All.fst"
} | [
{
"abbrev": true,
"full_module": "EverParse3d.Prelude",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=100"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 8,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
u12:
Prims.squash (EverParse3d.Actions.BackendFlag.backend_flag ==
EverParse3d.Actions.Base.BackendFlagExtern) ->
sz: FStar.UInt64.t ->
write_to: EverParse3d.Actions.Base.bpointer EverParse3d.Actions.All.___PUINT8
-> EverParse3d.Actions.Base.action (EverParse3d.Actions.Base.ptr_inv write_to)
EverParse3d.Actions.Base.disjointness_trivial
(EverParse3d.Actions.Base.ptr_loc write_to)
false
Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.squash",
"Prims.eq2",
"EverParse3d.Actions.Base.backend_flag_t",
"EverParse3d.Actions.BackendFlag.backend_flag",
"EverParse3d.Actions.Base.BackendFlagExtern",
"FStar.UInt64.t",
"EverParse3d.Actions.Base.bpointer",
"EverParse3d.Actions.All.___PUINT8",
"EverParse3d.InputStream.Base.extra_t",
"EverParse3d.Actions.Base.input_buffer_t",
"EverParse3d.InputStream.All.inst",
"EverParse3d.Actions.Base.app_ctxt",
"EverParse3d.Actions.Base.error_handler",
"EverParse3d.InputStream.Base.tlen",
"EverParse3d.ErrorCode.pos_t",
"Prims.bool",
"Prims.unit",
"LowStar.BufferOps.op_Star_Equals",
"LowStar.Buffer.trivial_preorder",
"EverParse3d.Actions.Base.ptr_inv_elim",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.is_null",
"FStar.UInt8.t",
"LowStar.Buffer.buffer",
"EverParse3d.InputStream.Extern.peep"
] | [] | false | false | false | false | false | let action_field_ptr_after _ n write_to =
| fun ctxt _err input _len _posBefore currentPosition ->
let buf = EverParse3d.InputStream.Extern.peep input currentPosition n in
let buf_not_null = not (LowStar.Buffer.is_null buf) in
if buf_not_null
then
(let open LowStar.BufferOps in
ptr_inv_elim write_to;
write_to *= buf);
buf_not_null | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_unchanged_behavior | val lemma_machine_eval_ins_st_unchanged_behavior (i: ins{Instr? i}) (s1 s2: machine_state)
: Lemma
(requires
(let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\ (unchanged_at r s1 s2) /\ (run f s1).ms_ok /\ (run f s2).ms_ok))
(ensures
(let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) | val lemma_machine_eval_ins_st_unchanged_behavior (i: ins{Instr? i}) (s1 s2: machine_state)
: Lemma
(requires
(let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\ (unchanged_at r s1 s2) /\ (run f s1).ms_ok /\ (run f s2).ms_ok))
(ensures
(let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) | let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 660,
"start_col": 0,
"start_line": 646
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
i: Vale.X64.Machine_Semantics_s.ins{Instr? i} ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
(let r =
Mkrw_set?.loc_reads (Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins i)
in
let f = Vale.X64.Machine_Semantics_s.machine_eval_ins_st i in
Mkmachine_state?.ms_ok s1 = Mkmachine_state?.ms_ok s2 /\
Vale.Transformers.BoundedInstructionEffects.unchanged_at r s1 s2 /\
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run f s1) /\
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run f s2)))
(ensures
(let w =
Mkrw_set?.loc_writes (Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins i)
in
let f = Vale.X64.Machine_Semantics_s.machine_eval_ins_st i in
Vale.Transformers.BoundedInstructionEffects.unchanged_at w
(Vale.X64.Machine_Semantics_s.run f s1)
(Vale.X64.Machine_Semantics_s.run f s2))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Machine_Semantics_s.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.Transformers.BoundedInstructionEffects.lemma_eval_instr_unchanged_at'",
"Prims.unit",
"Prims.l_and",
"Prims.op_Equality",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.X64.Machine_Semantics_s.run",
"Vale.X64.Machine_Semantics_s.st",
"Vale.X64.Machine_Semantics_s.machine_eval_ins_st",
"Prims.list",
"Vale.Transformers.Locations.location",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_reads",
"Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins",
"Prims.squash",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_machine_eval_ins_st_unchanged_behavior (i: ins{Instr? i}) (s1 s2: machine_state)
: Lemma
(requires
(let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\ (unchanged_at r s1 s2) /\ (run f s1).ms_ok /\ (run f s2).ms_ok))
(ensures
(let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
| let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2 | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_bounded_effects_Instr | val lemma_machine_eval_ins_st_bounded_effects_Instr (i: ins{Instr? i})
: Lemma (ensures ((bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) | val lemma_machine_eval_ins_st_bounded_effects_Instr (i: ins{Instr? i})
: Lemma (ensures ((bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) | let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1)) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 88,
"end_line": 716,
"start_col": 0,
"start_line": 707
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 3,
"initial_ifuel": 1,
"max_fuel": 3,
"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 | i: Vale.X64.Machine_Semantics_s.ins{Instr? i}
-> FStar.Pervasives.Lemma
(ensures
Vale.Transformers.BoundedInstructionEffects.bounded_effects (Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins
i)
(Vale.X64.Machine_Semantics_s.machine_eval_ins_st i)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"FStar.Classical.forall_intro_2",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.l_imp",
"Prims.l_and",
"Prims.op_Equality",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_reads",
"Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins",
"Vale.X64.Machine_Semantics_s.run",
"Vale.X64.Machine_Semantics_s.machine_eval_ins_st",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"FStar.Classical.move_requires",
"Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_unchanged_behavior",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_ok",
"FStar.Classical.forall_intro",
"Vale.Transformers.BoundedInstructionEffects.constant_on_execution",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_constant_writes",
"Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_constant_on_execution",
"Vale.Transformers.BoundedInstructionEffects.unchanged_except",
"Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_only_affects_write",
"Vale.Transformers.BoundedInstructionEffects.bounded_effects"
] | [] | false | false | true | false | false | let lemma_machine_eval_ins_st_bounded_effects_Instr (i: ins{Instr? i})
: Lemma (ensures ((bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
| FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1)) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at'_maintained_upon_flag_update | val lemma_unchanged_at'_maintained_upon_flag_update
(locs: locations)
(s1 s2: machine_state)
(flags: flags_t)
: Lemma (requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs ({ s1 with ms_flags = flags }) ({ s2 with ms_flags = flags }))) | val lemma_unchanged_at'_maintained_upon_flag_update
(locs: locations)
(s1 s2: machine_state)
(flags: flags_t)
: Lemma (requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs ({ s1 with ms_flags = flags }) ({ s2 with ms_flags = flags }))) | let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 77,
"end_line": 583,
"start_col": 0,
"start_line": 575
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
locs: Vale.Transformers.Locations.locations ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state ->
flags: Vale.X64.Machine_Semantics_s.flags_t
-> FStar.Pervasives.Lemma
(requires Vale.Transformers.BoundedInstructionEffects.unchanged_at' locs s1 s2)
(ensures
Vale.Transformers.BoundedInstructionEffects.unchanged_at' locs
(Vale.X64.Machine_Semantics_s.Mkmachine_state (Mkmachine_state?.ms_ok s1)
(Mkmachine_state?.ms_regs s1)
flags
(Mkmachine_state?.ms_heap s1)
(Mkmachine_state?.ms_stack s1)
(Mkmachine_state?.ms_stackTaint s1)
(Mkmachine_state?.ms_trace s1))
(Vale.X64.Machine_Semantics_s.Mkmachine_state (Mkmachine_state?.ms_ok s2)
(Mkmachine_state?.ms_regs s2)
flags
(Mkmachine_state?.ms_heap s2)
(Mkmachine_state?.ms_stack s2)
(Mkmachine_state?.ms_stackTaint s2)
(Mkmachine_state?.ms_trace s2))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.flags_t",
"Vale.Transformers.Locations.location",
"Prims.list",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at'_maintained_upon_flag_update",
"Prims.unit",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at'",
"Prims.squash",
"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_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",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_unchanged_at'_maintained_upon_flag_update
(locs: locations)
(s1 s2: machine_state)
(flags: flags_t)
: Lemma (requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs ({ s1 with ms_flags = flags }) ({ s2 with ms_flags = flags }))) =
| match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_code_Ins_bounded_effects_aux1 | val lemma_machine_eval_code_Ins_bounded_effects_aux1 (i: ins) (fuel: nat) (s: _)
: Lemma (requires (safely_bounded i))
(ensures
(let filt s = { s with ms_trace = [] } in
let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) | val lemma_machine_eval_code_Ins_bounded_effects_aux1 (i: ins) (fuel: nat) (s: _)
: Lemma (requires (safely_bounded i))
(ensures
(let filt s = { s with ms_trace = [] } in
let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) | let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 751,
"start_col": 0,
"start_line": 737
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
i: Vale.X64.Machine_Semantics_s.ins ->
fuel: Prims.nat ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma (requires Vale.Transformers.BoundedInstructionEffects.safely_bounded i)
(ensures
(let filt s =
Vale.X64.Machine_Semantics_s.Mkmachine_state (Mkmachine_state?.ms_ok s)
(Mkmachine_state?.ms_regs s)
(Mkmachine_state?.ms_flags s)
(Mkmachine_state?.ms_heap s)
(Mkmachine_state?.ms_stack s)
(Mkmachine_state?.ms_stackTaint s)
[]
in
let f = Vale.Transformers.BoundedInstructionEffects.machine_eval_code_Ins i fuel in
let rw = Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins i in
Vale.Transformers.BoundedInstructionEffects.unchanged_except (Mkrw_set?.loc_writes rw)
s
(Vale.X64.Machine_Semantics_s.run f s))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Prims.nat",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims._assert",
"Vale.Transformers.BoundedInstructionEffects.unchanged_except",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"Vale.X64.Machine_Semantics_s.run",
"Vale.X64.Machine_Semantics_s.machine_eval_ins_st",
"Prims.unit",
"Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_only_affects_write",
"Vale.Transformers.BoundedInstructionEffects.rw_set",
"Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins",
"Vale.X64.Machine_Semantics_s.st",
"Vale.Transformers.BoundedInstructionEffects.machine_eval_code_Ins",
"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.b2t",
"Vale.Transformers.BoundedInstructionEffects.safely_bounded",
"Prims.squash",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i: ins) (fuel: nat) s
: Lemma (requires (safely_bounded i))
(ensures
(let filt s = { s with ms_trace = [] } in
let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
| let filt s = { s with ms_trace = [] } in
let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes (run (machine_eval_ins_st i) (filt s)) (run f s)) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_bounded_effects | val lemma_machine_eval_ins_st_bounded_effects :
(i:ins) ->
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) | val lemma_machine_eval_ins_st_bounded_effects :
(i:ins) ->
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) | let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i)) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 723,
"start_col": 0,
"start_line": 720
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | i: Vale.X64.Machine_Semantics_s.ins
-> FStar.Pervasives.Lemma (requires Vale.Transformers.BoundedInstructionEffects.safely_bounded i)
(ensures
Vale.Transformers.BoundedInstructionEffects.bounded_effects (Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins
i)
(Vale.X64.Machine_Semantics_s.machine_eval_ins_st i)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"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.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_bounded_effects_Instr",
"Vale.X64.Bytes_Code_s.instruction_t",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Negation",
"Vale.Transformers.BoundedInstructionEffects.safely_bounded",
"Prims.unit"
] | [] | false | false | true | false | false | let lemma_machine_eval_ins_st_bounded_effects i =
| match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i)) | false |
Vale.AES.GHash_BE_s.fst | Vale.AES.GHash_BE_s.gf128_mul_BE | val gf128_mul_BE (a b: quad32) : quad32 | val gf128_mul_BE (a b: quad32) : quad32 | let gf128_mul_BE (a b:quad32) : quad32 =
gf128_to_quad32 (gf128_mul (gf128_of_quad32 a) (gf128_of_quad32 b)) | {
"file_name": "vale/specs/crypto/Vale.AES.GHash_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 14,
"start_col": 0,
"start_line": 13
} | module Vale.AES.GHash_BE_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.AES.GF128_s
open Vale.Lib.Seqs_s
open FStar.Mul
open FStar.Seq
type ghash_plain_BE:eqtype = s:seq quad32 { length s > 0 } | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.GHash_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_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": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Vale.Def.Types_s.quad32 -> b: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.AES.GF128_s.gf128_to_quad32",
"Vale.AES.GF128_s.gf128_mul",
"Vale.AES.GF128_s.gf128_of_quad32"
] | [] | false | false | false | true | false | let gf128_mul_BE (a b: quad32) : quad32 =
| gf128_to_quad32 (gf128_mul (gf128_of_quad32 a) (gf128_of_quad32 b)) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_trace | val lemma_unchanged_at_trace (locs: locations) (s1 s2: machine_state) (trace1 trace2: _)
: Lemma (requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({ s1 with ms_trace = trace1 }) ({ s2 with ms_trace = trace2 }))) | val lemma_unchanged_at_trace (locs: locations) (s1 s2: machine_state) (trace1 trace2: _)
: Lemma (requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({ s1 with ms_trace = trace1 }) ({ s2 with ms_trace = trace2 }))) | let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 732,
"start_col": 0,
"start_line": 725
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i)) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
locs: Vale.Transformers.Locations.locations ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state ->
trace1: Prims.list Vale.X64.Machine_s.observation ->
trace2: Prims.list Vale.X64.Machine_s.observation
-> FStar.Pervasives.Lemma
(requires Vale.Transformers.BoundedInstructionEffects.unchanged_at locs s1 s2)
(ensures
Vale.Transformers.BoundedInstructionEffects.unchanged_at locs
(Vale.X64.Machine_Semantics_s.Mkmachine_state (Mkmachine_state?.ms_ok s1)
(Mkmachine_state?.ms_regs s1)
(Mkmachine_state?.ms_flags s1)
(Mkmachine_state?.ms_heap s1)
(Mkmachine_state?.ms_stack s1)
(Mkmachine_state?.ms_stackTaint s1)
trace1)
(Vale.X64.Machine_Semantics_s.Mkmachine_state (Mkmachine_state?.ms_ok s2)
(Mkmachine_state?.ms_regs s2)
(Mkmachine_state?.ms_flags s2)
(Mkmachine_state?.ms_heap s2)
(Mkmachine_state?.ms_stack s2)
(Mkmachine_state?.ms_stackTaint s2)
trace2)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.list",
"Vale.X64.Machine_s.observation",
"Vale.Transformers.Locations.location",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_trace",
"Prims.unit",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Prims.squash",
"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",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_unchanged_at_trace
(locs: locations)
(s1: machine_state)
(s2: machine_state)
trace1
trace2
: Lemma (requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({ s1 with ms_trace = trace1 }) ({ s2 with ms_trace = trace2 }))) =
| match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at_trace xs s1 s2 trace1 trace2 | false |
FStar.Sequence.Util.fst | FStar.Sequence.Util.cons | val cons : x: a -> s: FStar.Sequence.Base.seq a -> FStar.Sequence.Base.seq a | let cons #a (x:a) (s:seq a) = singleton x `append` s | {
"file_name": "ulib/experimental/FStar.Sequence.Util.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 52,
"end_line": 30,
"start_col": 0,
"start_line": 30
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
(** This module provides some utilities on top of FStar.Sequence *)
module FStar.Sequence.Util
open FStar.Sequence.Base
/// For convenience, we define `slice` to represent Dafny sequence slices.
let slice (#ty: Type) (s: seq ty) (i: nat) (j: nat{j >= i && j <= length s})
: seq ty
= all_seq_facts_lemma();
drop (take s j) i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Sequence.Util.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Sequence.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: a -> s: FStar.Sequence.Base.seq a -> FStar.Sequence.Base.seq a | Prims.Tot | [
"total"
] | [] | [
"FStar.Sequence.Base.seq",
"FStar.Sequence.Base.append",
"FStar.Sequence.Base.singleton"
] | [] | false | false | false | true | false | let cons #a (x: a) (s: seq a) =
| (singleton x) `append` s | false |
|
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_code_Ins_bounded_effects | val lemma_machine_eval_code_Ins_bounded_effects :
(i:ins) ->
(fuel:nat) ->
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))))) | val lemma_machine_eval_code_Ins_bounded_effects :
(i:ins) ->
(fuel:nat) ->
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))))) | let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 56,
"end_line": 837,
"start_col": 0,
"start_line": 836
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | i: Vale.X64.Machine_Semantics_s.ins -> fuel: Prims.nat
-> FStar.Pervasives.Lemma (requires Vale.Transformers.BoundedInstructionEffects.safely_bounded i)
(ensures
Vale.Transformers.BoundedInstructionEffects.bounded_effects (Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins
i)
(fun s -> (), Some?.v (Vale.X64.Machine_Semantics_s.machine_eval_code_ins_def i s))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Prims.nat",
"Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_code_Ins_bounded_effects_aux",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_machine_eval_code_Ins_bounded_effects i fuel =
| lemma_machine_eval_code_Ins_bounded_effects_aux i fuel | false |
Vale.AES.GHash_BE_s.fst | Vale.AES.GHash_BE_s.ghash_BE | val ghash_BE : _: Vale.Def.Types_s.quad32 -> _: Vale.AES.GHash_BE_s.ghash_plain_BE
-> Prims.Tot Vale.Def.Types_s.quad32 | let ghash_BE = opaque_make ghash_BE_def | {
"file_name": "vale/specs/crypto/Vale.AES.GHash_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 25,
"start_col": 19,
"start_line": 25
} | module Vale.AES.GHash_BE_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.AES.GF128_s
open Vale.Lib.Seqs_s
open FStar.Mul
open FStar.Seq
type ghash_plain_BE:eqtype = s:seq quad32 { length s > 0 }
let gf128_mul_BE (a b:quad32) : quad32 =
gf128_to_quad32 (gf128_mul (gf128_of_quad32 a) (gf128_of_quad32 b))
let rec ghash_BE_def (h_BE:quad32) (x:ghash_plain_BE) : Tot quad32 (decreases %[length x]) =
let y_i_minus_1 =
(if length x = 1 then
Mkfour 0 0 0 0
else
ghash_BE_def h_BE (all_but_last x)) in
let x_i = last x in
let xor_BE = quad32_xor y_i_minus_1 x_i in | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.GHash_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_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": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Vale.Def.Types_s.quad32 -> _: Vale.AES.GHash_BE_s.ghash_plain_BE
-> Prims.Tot Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Opaque_s.opaque_make",
"Vale.Def.Types_s.quad32",
"Vale.AES.GHash_BE_s.ghash_plain_BE",
"Vale.AES.GHash_BE_s.ghash_BE_def"
] | [] | false | false | false | true | false | let ghash_BE =
| opaque_make ghash_BE_def | false |
|
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_code_Ins_bounded_effects_aux3 | val lemma_machine_eval_code_Ins_bounded_effects_aux3 (i: ins) (fuel: nat) (s1 s2: _)
: Lemma
(requires
(let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\ (s1.ms_ok = s2.ms_ok) /\ (unchanged_at rw.loc_reads s1 s2)))
(ensures
(let f:st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) | val lemma_machine_eval_code_Ins_bounded_effects_aux3 (i: ins) (fuel: nat) (s1 s2: _)
: Lemma
(requires
(let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\ (s1.ms_ok = s2.ms_ok) /\ (unchanged_at rw.loc_reads s1 s2)))
(ensures
(let f:st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) | let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 792,
"start_col": 0,
"start_line": 777
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
i: Vale.X64.Machine_Semantics_s.ins ->
fuel: Prims.nat ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
(let f = Vale.Transformers.BoundedInstructionEffects.machine_eval_code_Ins i fuel in
let rw = Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins i in
Vale.Transformers.BoundedInstructionEffects.safely_bounded i /\
Mkmachine_state?.ms_ok s1 = Mkmachine_state?.ms_ok s2 /\
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Mkrw_set?.loc_reads rw) s1 s2))
(ensures
(let f = Vale.Transformers.BoundedInstructionEffects.machine_eval_code_Ins i fuel in
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run f s1) =
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run f s2))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Prims.nat",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_ok",
"Prims.unit",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_trace",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_reads",
"Prims.Nil",
"Vale.X64.Machine_s.observation",
"Vale.Transformers.BoundedInstructionEffects.rw_set",
"Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins",
"Vale.X64.Machine_Semantics_s.st",
"Vale.Transformers.BoundedInstructionEffects.machine_eval_code_Ins",
"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.l_and",
"Prims.b2t",
"Vale.Transformers.BoundedInstructionEffects.safely_bounded",
"Prims.op_Equality",
"Prims.bool",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Prims.squash",
"Vale.X64.Machine_Semantics_s.run",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i: ins) (fuel: nat) s1 s2
: Lemma
(requires
(let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\ (s1.ms_ok = s2.ms_ok) /\ (unchanged_at rw.loc_reads s1 s2)))
(ensures
(let f:st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
| let filt s = { s with ms_trace = [] } in
let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2) | false |
FStar.Sequence.Util.fst | FStar.Sequence.Util.slice | val slice (#ty: Type) (s: seq ty) (i: nat) (j: nat{j >= i && j <= length s}) : seq ty | val slice (#ty: Type) (s: seq ty) (i: nat) (j: nat{j >= i && j <= length s}) : seq ty | let slice (#ty: Type) (s: seq ty) (i: nat) (j: nat{j >= i && j <= length s})
: seq ty
= all_seq_facts_lemma();
drop (take s j) i | {
"file_name": "ulib/experimental/FStar.Sequence.Util.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 28,
"start_col": 0,
"start_line": 25
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
(** This module provides some utilities on top of FStar.Sequence *)
module FStar.Sequence.Util
open FStar.Sequence.Base | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Sequence.Util.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Sequence.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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.Sequence.Base.seq ty ->
i: Prims.nat ->
j: Prims.nat{j >= i && j <= FStar.Sequence.Base.length s}
-> FStar.Sequence.Base.seq ty | Prims.Tot | [
"total"
] | [] | [
"FStar.Sequence.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_AmpAmp",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThanOrEqual",
"FStar.Sequence.Base.length",
"FStar.Sequence.Base.drop",
"FStar.Sequence.Base.take",
"Prims.unit",
"FStar.Sequence.Base.all_seq_facts_lemma"
] | [] | false | false | false | false | false | let slice (#ty: Type) (s: seq ty) (i: nat) (j: nat{j >= i && j <= length s}) : seq ty =
| all_seq_facts_lemma ();
drop (take s j) i | false |
FStar.Sequence.Util.fst | FStar.Sequence.Util.count | val count : x: a -> s: FStar.Sequence.Base.seq a -> Prims.nat | let count (#a:eqtype) (x:a) (s:seq a) = count_matches (fun y -> x = y) s | {
"file_name": "ulib/experimental/FStar.Sequence.Util.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 72,
"end_line": 67,
"start_col": 0,
"start_line": 67
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
(** This module provides some utilities on top of FStar.Sequence *)
module FStar.Sequence.Util
open FStar.Sequence.Base
/// For convenience, we define `slice` to represent Dafny sequence slices.
let slice (#ty: Type) (s: seq ty) (i: nat) (j: nat{j >= i && j <= length s})
: seq ty
= all_seq_facts_lemma();
drop (take s j) i
let cons #a (x:a) (s:seq a) = singleton x `append` s
let head #a (s:seq a{length s > 0}) = s $@ 0
let tail #a (s:seq a{length s > 0}) = drop s 1
/// Split a sequences into a prefix and the last element
/// This is the inverse of the Sequence.build
let un_build (#a:_) (s:seq a{length s > 0})
: seq a & a
= take s (length s - 1),
s $@ (length s - 1)
let split #a (s:seq a) (i:nat{ i <= length s})
: seq a & seq a
= take s i,
drop s i
/// Counts the number of elements of `s` that
/// satisfy the predicate [f]
let rec count_matches (#a:Type) (f:a -> bool) (s:seq a)
: Tot nat (decreases (length s))
= all_seq_facts_lemma();
if length s = 0 then 0
else if f (head s) then 1 + count_matches f (tail s)
else count_matches f (tail s)
/// count_matches on an empty sequence is always zero
let count_matches_empty (a:Type) (f:a -> bool) (s:seq a{length s = 0})
: Lemma (count_matches f s = 0)
= ()
/// count is a specialization of count_matches
/// to count the number of occurrences of a given element `x` in `s`.
///
/// It is opaque to give control over its unrollings in specific proofs | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Sequence.Util.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Sequence.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: a -> s: FStar.Sequence.Base.seq a -> Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.Sequence.Base.seq",
"FStar.Sequence.Util.count_matches",
"Prims.op_Equality",
"Prims.bool",
"Prims.nat"
] | [] | false | false | false | false | false | let count (#a: eqtype) (x: a) (s: seq a) =
| count_matches (fun y -> x = y) s | false |
|
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_constant_on_execution | val lemma_machine_eval_ins_st_constant_on_execution (i: ins{Instr? i}) (s: machine_state)
: Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)
) | val lemma_machine_eval_ins_st_constant_on_execution (i: ins{Instr? i}) (s: machine_state)
: Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)
) | let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else () | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 703,
"start_col": 0,
"start_line": 663
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 3,
"initial_ifuel": 1,
"max_fuel": 3,
"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 | i: Vale.X64.Machine_Semantics_s.ins{Instr? i} -> s: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(ensures
Vale.Transformers.BoundedInstructionEffects.constant_on_execution (Mkrw_set?.loc_constant_writes
(Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins i))
(Vale.X64.Machine_Semantics_s.machine_eval_ins_st i)
s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Prims.b2t",
"Vale.X64.Bytes_Code_s.uu___is_Instr",
"Vale.X64.Machine_Semantics_s.instr_annotation",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"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",
"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",
"FStar.List.Tot.Base.mem",
"Vale.Transformers.Locations.location",
"Vale.Transformers.Locations.ALocOf",
"Prims.bool",
"Vale.X64.Instruction_s.instr_ret_t",
"Vale.Transformers.BoundedInstructionEffects.lemma_instr_write_outputs_only_affects_write",
"Prims.unit",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_except_not_mem",
"Vale.X64.Machine_Semantics_s.instr_write_outputs",
"Vale.X64.Machine_Semantics_s.Mkmachine_state",
"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.Transformers.Locations.ALocCf",
"Vale.Transformers.BoundedInstructionEffects.aux_write_set",
"Prims.l_True",
"Prims.squash",
"Vale.Transformers.BoundedInstructionEffects.constant_on_execution",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_constant_writes",
"Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins",
"Vale.X64.Machine_Semantics_s.machine_eval_ins_st",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_machine_eval_ins_st_constant_on_execution (i: ins{Instr? i}) (s: machine_state)
: Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)
) =
| if s.ms_ok
then
(let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws
then ()
else
(let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> { s0 with ms_flags = havoc_flags }
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf);
if L.mem ALocOf ws
then ()
else
(let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> { s0 with ms_flags = havoc_flags }
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf)) | false |
FStar.Sequence.Util.fst | FStar.Sequence.Util.split | val split (#a: _) (s: seq a) (i: nat{i <= length s}) : seq a & seq a | val split (#a: _) (s: seq a) (i: nat{i <= length s}) : seq a & seq a | let split #a (s:seq a) (i:nat{ i <= length s})
: seq a & seq a
= take s i,
drop s i | {
"file_name": "ulib/experimental/FStar.Sequence.Util.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 12,
"end_line": 46,
"start_col": 0,
"start_line": 43
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
(** This module provides some utilities on top of FStar.Sequence *)
module FStar.Sequence.Util
open FStar.Sequence.Base
/// For convenience, we define `slice` to represent Dafny sequence slices.
let slice (#ty: Type) (s: seq ty) (i: nat) (j: nat{j >= i && j <= length s})
: seq ty
= all_seq_facts_lemma();
drop (take s j) i
let cons #a (x:a) (s:seq a) = singleton x `append` s
let head #a (s:seq a{length s > 0}) = s $@ 0
let tail #a (s:seq a{length s > 0}) = drop s 1
/// Split a sequences into a prefix and the last element
/// This is the inverse of the Sequence.build
let un_build (#a:_) (s:seq a{length s > 0})
: seq a & a
= take s (length s - 1),
s $@ (length s - 1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Sequence.Util.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Sequence.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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.Sequence.Base.seq a -> i: Prims.nat{i <= FStar.Sequence.Base.length s}
-> FStar.Sequence.Base.seq a * FStar.Sequence.Base.seq a | Prims.Tot | [
"total"
] | [] | [
"FStar.Sequence.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Sequence.Base.length",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Sequence.Base.take",
"FStar.Sequence.Base.drop",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | false | false | let split #a (s: seq a) (i: nat{i <= length s}) : seq a & seq a =
| take s i, drop s i | false |
Vale.Stdcalls.X64.Fsqr.fsti | Vale.Stdcalls.X64.Fsqr.fsqr_lemma' | val fsqr_lemma' (code: V.va_code) (_win: bool) (tmp f1 out: b64) (va_s0: V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires fsqr_pre code tmp f1 out va_s0)
(ensures
(fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fsqr_post code tmp f1 out va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\ ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp)) ME.loc_none))
(VS.vs_get_vale_heap va_s0)
(VS.vs_get_vale_heap va_s1))) | val fsqr_lemma' (code: V.va_code) (_win: bool) (tmp f1 out: b64) (va_s0: V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires fsqr_pre code tmp f1 out va_s0)
(ensures
(fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fsqr_post code tmp f1 out va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\ ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp)) ME.loc_none))
(VS.vs_get_vale_heap va_s0)
(VS.vs_get_vale_heap va_s1))) | let fsqr_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fsqr_pre code tmp f1 out va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fsqr_post code tmp f1 out va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fsqr_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f) | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fsqr.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 106,
"start_col": 0,
"start_line": 78
} | module Vale.Stdcalls.X64.Fsqr
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let fsqr_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; t64_mod] in
assert_norm (List.length y = 3);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fsqr_pre : VSig.vale_pre fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state) ->
FW.va_req_Fsqr_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out)
[@__reduce__] noextract
let fsqr_post : VSig.vale_post fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fsqr_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) va_s1 f
#set-options "--z3rlimit 200" | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fsqr.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
code: Vale.X64.Decls.va_code ->
_win: Prims.bool ->
tmp: Vale.Stdcalls.X64.Fsqr.b64 ->
f1: Vale.Stdcalls.X64.Fsqr.b64 ->
out: Vale.Stdcalls.X64.Fsqr.b64 ->
va_s0: Vale.X64.Decls.va_state
-> Prims.Ghost (Vale.X64.Decls.va_state * Vale.X64.Decls.va_fuel) | Prims.Ghost | [] | [] | [
"Vale.X64.Decls.va_code",
"Prims.bool",
"Vale.Stdcalls.X64.Fsqr.b64",
"Vale.X64.Decls.va_state",
"Vale.X64.Decls.va_fuel",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal",
"Vale.Arch.HeapTypes_s.TUInt64",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.State.vale_state",
"Vale.Curve25519.X64.FastWide.va_lemma_Fsqr_stdcall",
"Vale.Interop.Assumptions.win",
"Vale.X64.MemoryAdapters.as_vale_buffer",
"Vale.Stdcalls.X64.Fsqr.fsqr_pre",
"Prims.l_and",
"Vale.X64.Decls.eval_code",
"Vale.AsLowStar.ValeSig.vale_calling_conventions_stdcall",
"Vale.Stdcalls.X64.Fsqr.fsqr_post",
"Vale.X64.Memory.buffer_readable",
"Vale.X64.State.vs_get_vale_heap",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.modifies",
"Vale.X64.Memory.loc_union",
"Vale.X64.Memory.loc_buffer",
"Vale.X64.Memory.loc_none"
] | [] | false | false | false | false | false | let fsqr_lemma' (code: V.va_code) (_win: bool) (tmp f1 out: b64) (va_s0: V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires fsqr_pre code tmp f1 out va_s0)
(ensures
(fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fsqr_post code tmp f1 out va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\ ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp)) ME.loc_none))
(VS.vs_get_vale_heap va_s0)
(VS.vs_get_vale_heap va_s1))) =
| let va_s1, f =
FW.va_lemma_Fsqr_stdcall code
va_s0
IA.win
(as_vale_buffer tmp)
(as_vale_buffer f1)
(as_vale_buffer out)
in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_code_Ins_bounded_effects_aux2 | val lemma_machine_eval_code_Ins_bounded_effects_aux2 (i: ins) (fuel: nat) (s: _)
: Lemma (requires (safely_bounded i))
(ensures
(let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) | val lemma_machine_eval_code_Ins_bounded_effects_aux2 (i: ins) (fuel: nat) (s: _)
: Lemma (requires (safely_bounded i))
(ensures
(let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) | let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 775,
"start_col": 0,
"start_line": 753
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
i: Vale.X64.Machine_Semantics_s.ins ->
fuel: Prims.nat ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma (requires Vale.Transformers.BoundedInstructionEffects.safely_bounded i)
(ensures
(let f = Vale.Transformers.BoundedInstructionEffects.machine_eval_code_Ins i fuel in
let rw = Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins i in
Vale.Transformers.BoundedInstructionEffects.constant_on_execution (Mkrw_set?.loc_constant_writes
rw)
f
s)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Prims.nat",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_constant_writes",
"Vale.Transformers.BoundedInstructionEffects.locations_with_values",
"Prims.unit",
"Vale.Transformers.BoundedInstructionEffects.constant_on_execution",
"Vale.X64.Machine_Semantics_s.machine_eval_ins_st",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.X64.Machine_Semantics_s.run",
"Vale.Transformers.Locations.location_eq",
"Vale.Transformers.Locations.location_val_eqt",
"Prims.list",
"Vale.Transformers.BoundedInstructionEffects.location_with_value",
"Prims.bool",
"Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_constant_on_execution",
"Vale.Transformers.BoundedInstructionEffects.rw_set",
"Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins",
"Vale.X64.Machine_Semantics_s.st",
"Vale.Transformers.BoundedInstructionEffects.machine_eval_code_Ins",
"Vale.X64.Machine_Semantics_s.Mkmachine_state",
"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",
"Vale.X64.Machine_s.observation",
"Prims.b2t",
"Vale.Transformers.BoundedInstructionEffects.safely_bounded"
] | [] | false | false | true | false | false | let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i: ins) (fuel: nat) s
: Lemma (requires (safely_bounded i))
(ensures
(let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
| let filt s = { s with ms_trace = [] } in
let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c
: Lemma (requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok
then
(match c with
| [] -> ()
| (| l , v |) :: xs -> aux xs)
in
aux rw.loc_constant_writes | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_code_Ins_bounded_effects_aux4 | val lemma_machine_eval_code_Ins_bounded_effects_aux4 (i: ins) (fuel: nat) (s1 s2: _)
: Lemma
(requires
(let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\ (s1.ms_ok = s2.ms_ok) /\ (unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\ (run f s2).ms_ok))
(ensures
(let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) | val lemma_machine_eval_code_Ins_bounded_effects_aux4 (i: ins) (fuel: nat) (s1 s2: _)
: Lemma
(requires
(let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\ (s1.ms_ok = s2.ms_ok) /\ (unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\ (run f s2).ms_ok))
(ensures
(let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) | let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 815,
"start_col": 0,
"start_line": 794
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
i: Vale.X64.Machine_Semantics_s.ins ->
fuel: Prims.nat ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
(let f = Vale.Transformers.BoundedInstructionEffects.machine_eval_code_Ins i fuel in
let rw = Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins i in
Vale.Transformers.BoundedInstructionEffects.safely_bounded i /\
Mkmachine_state?.ms_ok s1 = Mkmachine_state?.ms_ok s2 /\
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Mkrw_set?.loc_reads rw) s1 s2 /\
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run f s1) /\
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run f s2)))
(ensures
(let f = Vale.Transformers.BoundedInstructionEffects.machine_eval_code_Ins i fuel in
let rw = Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins i in
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Mkrw_set?.loc_writes rw)
(Vale.X64.Machine_Semantics_s.run f s1)
(Vale.X64.Machine_Semantics_s.run f s2))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.X64.Machine_Semantics_s.ins",
"Prims.nat",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_trace",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"Vale.X64.Machine_Semantics_s.machine_eval_ins",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_trace",
"Prims.unit",
"Vale.Transformers.BoundedInstructionEffects.lemma_machine_eval_ins_st_unchanged_behavior",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_reads",
"Prims.Nil",
"Vale.X64.Machine_s.observation",
"Vale.Transformers.BoundedInstructionEffects.rw_set",
"Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins",
"Vale.X64.Machine_Semantics_s.st",
"Vale.Transformers.BoundedInstructionEffects.machine_eval_code_Ins",
"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",
"FStar.List.Tot.Base.append",
"Vale.X64.Machine_Semantics_s.ins_obs",
"Prims.l_and",
"Prims.b2t",
"Vale.Transformers.BoundedInstructionEffects.safely_bounded",
"Prims.op_Equality",
"Prims.bool",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.X64.Machine_Semantics_s.run",
"Prims.squash",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i: ins) (fuel: nat) s1 s2
: Lemma
(requires
(let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\ (s1.ms_ok = s2.ms_ok) /\ (unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\ (run f s2).ms_ok))
(ensures
(let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
| let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f:st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes
(machine_eval_ins i (filt s1))
(machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace
(intr s2 s2).ms_trace | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.difference | val difference (#t: eqtype) (l1 l2: list t) : list t | val difference (#t: eqtype) (l1 l2: list t) : list t | let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 77,
"end_line": 852,
"start_col": 0,
"start_line": 849
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | l1: Prims.list t -> l2: Prims.list t -> Prims.list t | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.Nil",
"FStar.List.Tot.Base.mem",
"Vale.Transformers.BoundedInstructionEffects.difference",
"Prims.bool",
"Prims.Cons"
] | [
"recursion"
] | false | false | false | false | false | let rec difference (#t: eqtype) (l1 l2: list t) : list t =
| match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2 | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.rw_set_in_parallel | val rw_set_in_parallel : rw_set -> rw_set -> rw_set | val rw_set_in_parallel : rw_set -> rw_set -> rw_set | let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
} | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 863,
"start_col": 0,
"start_line": 858
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
rw1: Vale.Transformers.BoundedInstructionEffects.rw_set ->
rw2: Vale.Transformers.BoundedInstructionEffects.rw_set
-> Vale.Transformers.BoundedInstructionEffects.rw_set | Prims.Tot | [
"total"
] | [] | [
"Vale.Transformers.BoundedInstructionEffects.rw_set",
"Vale.Transformers.BoundedInstructionEffects.Mkrw_set",
"FStar.List.Tot.Base.append",
"Vale.Transformers.Locations.location",
"Vale.Transformers.BoundedInstructionEffects.sym_difference",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_reads",
"Vale.Transformers.BoundedInstructionEffects.intersect",
"Vale.Transformers.BoundedInstructionEffects.location_with_value",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_constant_writes"
] | [] | false | false | false | true | false | let rw_set_in_parallel rw1 rw2 =
| {
loc_reads
=
(sym_difference rw1.loc_writes rw2.loc_writes) `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes
} | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_eval_instr_unchanged_at' | val lemma_eval_instr_unchanged_at'
(it: instr_t_record)
(oprs: instr_operands_t it.outs it.args)
(ann: instr_annotation it)
(s1 s2: machine_state)
: Lemma
(requires
(let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\ (unchanged_at r s1 s2)))
(ensures
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\ (Some? s1' ==> unchanged_at' w (Some?.v s1') (Some?.v s2')))) | val lemma_eval_instr_unchanged_at'
(it: instr_t_record)
(oprs: instr_operands_t it.outs it.args)
(ann: instr_annotation it)
(s1 s2: machine_state)
: Lemma
(requires
(let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\ (unchanged_at r s1 s2)))
(ensures
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\ (Some? s1' ==> unchanged_at' w (Some?.v s1') (Some?.v s2')))) | let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else () | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 631,
"start_col": 0,
"start_line": 586
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 2,
"max_ifuel": 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 |
it: Vale.X64.Instruction_s.instr_t_record ->
oprs:
Vale.X64.Instruction_s.instr_operands_t (InstrTypeRecord?.outs it) (InstrTypeRecord?.args it) ->
ann: Vale.X64.Machine_Semantics_s.instr_annotation it ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
(let r =
Mkrw_set?.loc_reads (Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins (Vale.X64.Bytes_Code_s.Instr
it oprs ann))
in
Mkmachine_state?.ms_ok s1 = Mkmachine_state?.ms_ok s2 /\
Vale.Transformers.BoundedInstructionEffects.unchanged_at r s1 s2))
(ensures
(let w =
Mkrw_set?.loc_writes (Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins (Vale.X64.Bytes_Code_s.Instr
it oprs ann))
in
let s1' = Vale.X64.Machine_Semantics_s.eval_instr it oprs ann s1 in
let s2' = Vale.X64.Machine_Semantics_s.eval_instr it oprs ann s2 in
Some? s1' = Some? s2' /\
(Some? s1' ==>
Vale.Transformers.BoundedInstructionEffects.unchanged_at' w (Some?.v s1') (Some?.v s2'))
)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"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.Machine_Semantics_s.machine_state",
"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",
"Prims.op_Equality",
"Vale.X64.Instruction_s.HavocFlags",
"FStar.List.Tot.Base.mem",
"Vale.Transformers.Locations.location",
"Vale.Transformers.Locations.ALocCf",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at'_mem",
"Prims.bool",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_except_not_mem",
"Prims.unit",
"Vale.Transformers.Locations.ALocOf",
"Vale.Transformers.BoundedInstructionEffects.aux_write_set",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.Mktuple2",
"Vale.Transformers.BoundedInstructionEffects.lemma_instr_write_outputs_only_writes",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at'_maintained_upon_flag_update",
"Vale.Transformers.BoundedInstructionEffects.aux_read_set1",
"Vale.X64.Machine_Semantics_s.havoc_flags",
"FStar.Option.mapTot",
"Vale.X64.Machine_Semantics_s.instr_write_outputs",
"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_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",
"Prims._assert",
"Prims.eq2",
"Vale.Transformers.BoundedInstructionEffects.lemma_instr_apply_eval_same_read",
"Vale.X64.Instruction_s.instr_eval",
"Vale.X64.Machine_Semantics_s.instr_apply_eval",
"Prims.l_and",
"Prims.b2t",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_reads",
"Vale.Transformers.BoundedInstructionEffects.rw_set_of_ins",
"Vale.X64.Bytes_Code_s.Instr",
"Prims.squash",
"FStar.Pervasives.Native.uu___is_Some",
"Prims.l_imp",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at'",
"FStar.Pervasives.Native.__proj__Some__item__v",
"Vale.X64.Machine_Semantics_s.eval_instr",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_eval_instr_unchanged_at'
(it: instr_t_record)
(oprs: instr_operands_t it.outs it.args)
(ann: instr_annotation it)
(s1 s2: machine_state)
: Lemma
(requires
(let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\ (unchanged_at r s1 s2)))
(ensures
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\ (Some? s1' ==> unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
| let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> { s1 with ms_flags = havoc_flags }, { s2 with ms_flags = havoc_flags }
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags
then
(let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs
then (lemma_unchanged_at'_mem locs ALocOf s1' s2')
else (lemma_unchanged_except_not_mem locs ALocOf);
if L.mem ALocCf locs
then (lemma_unchanged_at'_mem locs ALocCf s1' s2')
else (lemma_unchanged_except_not_mem locs ALocCf)) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.intersect | val intersect (#t: eqtype) (l1 l2: list t) : list t | val intersect (#t: eqtype) (l1 l2: list t) : list t | let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 75,
"end_line": 847,
"start_col": 0,
"start_line": 844
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | l1: Prims.list t -> l2: Prims.list t -> Prims.list t | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.Nil",
"FStar.List.Tot.Base.mem",
"Prims.Cons",
"Vale.Transformers.BoundedInstructionEffects.intersect",
"Prims.bool"
] | [
"recursion"
] | false | false | false | false | false | let rec intersect (#t: eqtype) (l1 l2: list t) : list t =
| match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2 | false |
Vale.AES.GHash_BE_s.fst | Vale.AES.GHash_BE_s.ghash_BE_def | val ghash_BE_def (h_BE: quad32) (x: ghash_plain_BE) : Tot quad32 (decreases %[length x]) | val ghash_BE_def (h_BE: quad32) (x: ghash_plain_BE) : Tot quad32 (decreases %[length x]) | let rec ghash_BE_def (h_BE:quad32) (x:ghash_plain_BE) : Tot quad32 (decreases %[length x]) =
let y_i_minus_1 =
(if length x = 1 then
Mkfour 0 0 0 0
else
ghash_BE_def h_BE (all_but_last x)) in
let x_i = last x in
let xor_BE = quad32_xor y_i_minus_1 x_i in
gf128_mul_BE xor_BE h_BE | {
"file_name": "vale/specs/crypto/Vale.AES.GHash_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 24,
"start_col": 0,
"start_line": 16
} | module Vale.AES.GHash_BE_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.AES.GF128_s
open Vale.Lib.Seqs_s
open FStar.Mul
open FStar.Seq
type ghash_plain_BE:eqtype = s:seq quad32 { length s > 0 }
let gf128_mul_BE (a b:quad32) : quad32 =
gf128_to_quad32 (gf128_mul (gf128_of_quad32 a) (gf128_of_quad32 b)) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.GHash_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_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": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | h_BE: Vale.Def.Types_s.quad32 -> x: Vale.AES.GHash_BE_s.ghash_plain_BE
-> Prims.Tot Vale.Def.Types_s.quad32 | Prims.Tot | [
"total",
""
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.AES.GHash_BE_s.ghash_plain_BE",
"Vale.AES.GHash_BE_s.gf128_mul_BE",
"Vale.Def.Types_s.quad32_xor",
"FStar.Seq.Properties.last",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.nat32",
"Prims.bool",
"Vale.AES.GHash_BE_s.ghash_BE_def",
"Vale.Lib.Seqs_s.all_but_last"
] | [
"recursion"
] | false | false | false | true | false | let rec ghash_BE_def (h_BE: quad32) (x: ghash_plain_BE) : Tot quad32 (decreases %[length x]) =
| let y_i_minus_1 = (if length x = 1 then Mkfour 0 0 0 0 else ghash_BE_def h_BE (all_but_last x)) in
let x_i = last x in
let xor_BE = quad32_xor y_i_minus_1 x_i in
gf128_mul_BE xor_BE h_BE | false |
FStar.Sequence.Util.fst | FStar.Sequence.Util.head | val head : s: FStar.Sequence.Base.seq a {FStar.Sequence.Base.length s > 0} -> a | let head #a (s:seq a{length s > 0}) = s $@ 0 | {
"file_name": "ulib/experimental/FStar.Sequence.Util.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 44,
"end_line": 32,
"start_col": 0,
"start_line": 32
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
(** This module provides some utilities on top of FStar.Sequence *)
module FStar.Sequence.Util
open FStar.Sequence.Base
/// For convenience, we define `slice` to represent Dafny sequence slices.
let slice (#ty: Type) (s: seq ty) (i: nat) (j: nat{j >= i && j <= length s})
: seq ty
= all_seq_facts_lemma();
drop (take s j) i
let cons #a (x:a) (s:seq a) = singleton x `append` s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Sequence.Util.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Sequence.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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.Sequence.Base.seq a {FStar.Sequence.Base.length s > 0} -> a | Prims.Tot | [
"total"
] | [] | [
"FStar.Sequence.Base.seq",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Sequence.Base.length",
"FStar.Sequence.Base.op_Dollar_At"
] | [] | false | false | false | false | false | let head #a (s: seq a {length s > 0}) =
| s $@ 0 | false |
|
FStar.Sequence.Util.fst | FStar.Sequence.Util.un_build | val un_build (#a: _) (s: seq a {length s > 0}) : seq a & a | val un_build (#a: _) (s: seq a {length s > 0}) : seq a & a | let un_build (#a:_) (s:seq a{length s > 0})
: seq a & a
= take s (length s - 1),
s $@ (length s - 1) | {
"file_name": "ulib/experimental/FStar.Sequence.Util.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 23,
"end_line": 41,
"start_col": 0,
"start_line": 38
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
(** This module provides some utilities on top of FStar.Sequence *)
module FStar.Sequence.Util
open FStar.Sequence.Base
/// For convenience, we define `slice` to represent Dafny sequence slices.
let slice (#ty: Type) (s: seq ty) (i: nat) (j: nat{j >= i && j <= length s})
: seq ty
= all_seq_facts_lemma();
drop (take s j) i
let cons #a (x:a) (s:seq a) = singleton x `append` s
let head #a (s:seq a{length s > 0}) = s $@ 0
let tail #a (s:seq a{length s > 0}) = drop s 1
/// Split a sequences into a prefix and the last element | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Sequence.Util.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Sequence.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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.Sequence.Base.seq a {FStar.Sequence.Base.length s > 0} -> FStar.Sequence.Base.seq a * a | Prims.Tot | [
"total"
] | [] | [
"FStar.Sequence.Base.seq",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Sequence.Base.length",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Sequence.Base.take",
"Prims.op_Subtraction",
"FStar.Sequence.Base.op_Dollar_At",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | false | false | let un_build (#a: _) (s: seq a {length s > 0}) : seq a & a =
| take s (length s - 1), s $@ (length s - 1) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.rw_set_in_series | val rw_set_in_series : rw_set -> rw_set -> rw_set | val rw_set_in_series : rw_set -> rw_set -> rw_set | let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
} | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 871,
"start_col": 0,
"start_line": 866
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
} | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
rw1: Vale.Transformers.BoundedInstructionEffects.rw_set ->
rw2: Vale.Transformers.BoundedInstructionEffects.rw_set
-> Vale.Transformers.BoundedInstructionEffects.rw_set | Prims.Tot | [
"total"
] | [] | [
"Vale.Transformers.BoundedInstructionEffects.rw_set",
"Vale.Transformers.BoundedInstructionEffects.Mkrw_set",
"FStar.List.Tot.Base.append",
"Vale.Transformers.Locations.location",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_reads",
"Vale.Transformers.BoundedInstructionEffects.difference",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"Vale.Transformers.BoundedInstructionEffects.intersect",
"Vale.Transformers.BoundedInstructionEffects.location_with_value",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_constant_writes"
] | [] | false | false | false | true | false | let rw_set_in_series rw1 rw2 =
| {
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes
} | false |
Vale.AES.GHash_BE_s.fst | Vale.AES.GHash_BE_s.ghash_BE_reveal | val ghash_BE_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.GHash_BE_s.ghash_BE == Vale.AES.GHash_BE_s.ghash_BE_def) | let ghash_BE_reveal = opaque_revealer (`%ghash_BE) ghash_BE ghash_BE_def | {
"file_name": "vale/specs/crypto/Vale.AES.GHash_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 84,
"end_line": 26,
"start_col": 12,
"start_line": 26
} | module Vale.AES.GHash_BE_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Types_s
open Vale.AES.GF128_s
open Vale.Lib.Seqs_s
open FStar.Mul
open FStar.Seq
type ghash_plain_BE:eqtype = s:seq quad32 { length s > 0 }
let gf128_mul_BE (a b:quad32) : quad32 =
gf128_to_quad32 (gf128_mul (gf128_of_quad32 a) (gf128_of_quad32 b))
let rec ghash_BE_def (h_BE:quad32) (x:ghash_plain_BE) : Tot quad32 (decreases %[length x]) =
let y_i_minus_1 =
(if length x = 1 then
Mkfour 0 0 0 0
else
ghash_BE_def h_BE (all_but_last x)) in
let x_i = last x in
let xor_BE = quad32_xor y_i_minus_1 x_i in
gf128_mul_BE xor_BE h_BE | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.AES.GF128_s.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.GHash_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GF128_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": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.GHash_BE_s.ghash_BE == Vale.AES.GHash_BE_s.ghash_BE_def) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Opaque_s.opaque_revealer",
"Vale.Def.Types_s.quad32",
"Vale.AES.GHash_BE_s.ghash_plain_BE",
"Vale.AES.GHash_BE_s.ghash_BE",
"Vale.AES.GHash_BE_s.ghash_BE_def"
] | [] | true | false | true | false | false | let ghash_BE_reveal =
| opaque_revealer (`%ghash_BE) ghash_BE ghash_BE_def | false |
|
FStar.Sequence.Util.fst | FStar.Sequence.Util.tail | val tail : s: FStar.Sequence.Base.seq a {FStar.Sequence.Base.length s > 0} -> FStar.Sequence.Base.seq a | let tail #a (s:seq a{length s > 0}) = drop s 1 | {
"file_name": "ulib/experimental/FStar.Sequence.Util.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 46,
"end_line": 34,
"start_col": 0,
"start_line": 34
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
(** This module provides some utilities on top of FStar.Sequence *)
module FStar.Sequence.Util
open FStar.Sequence.Base
/// For convenience, we define `slice` to represent Dafny sequence slices.
let slice (#ty: Type) (s: seq ty) (i: nat) (j: nat{j >= i && j <= length s})
: seq ty
= all_seq_facts_lemma();
drop (take s j) i
let cons #a (x:a) (s:seq a) = singleton x `append` s
let head #a (s:seq a{length s > 0}) = s $@ 0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Sequence.Util.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Sequence.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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.Sequence.Base.seq a {FStar.Sequence.Base.length s > 0} -> FStar.Sequence.Base.seq a | Prims.Tot | [
"total"
] | [] | [
"FStar.Sequence.Base.seq",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Sequence.Base.length",
"FStar.Sequence.Base.drop"
] | [] | false | false | false | false | false | let tail #a (s: seq a {length s > 0}) =
| drop s 1 | false |
|
FStar.Sequence.Util.fst | FStar.Sequence.Util.count_empty | val count_empty (#a: eqtype) (s: seq a {length s = 0}) : Lemma (forall x. count x s = 0) | val count_empty (#a: eqtype) (s: seq a {length s = 0}) : Lemma (forall x. count x s = 0) | let count_empty (#a:eqtype) (s:seq a{length s = 0})
: Lemma (forall x. count x s = 0)
= reveal_opaque (`%count) (count #a) | {
"file_name": "ulib/experimental/FStar.Sequence.Util.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 72,
"start_col": 0,
"start_line": 70
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
(** This module provides some utilities on top of FStar.Sequence *)
module FStar.Sequence.Util
open FStar.Sequence.Base
/// For convenience, we define `slice` to represent Dafny sequence slices.
let slice (#ty: Type) (s: seq ty) (i: nat) (j: nat{j >= i && j <= length s})
: seq ty
= all_seq_facts_lemma();
drop (take s j) i
let cons #a (x:a) (s:seq a) = singleton x `append` s
let head #a (s:seq a{length s > 0}) = s $@ 0
let tail #a (s:seq a{length s > 0}) = drop s 1
/// Split a sequences into a prefix and the last element
/// This is the inverse of the Sequence.build
let un_build (#a:_) (s:seq a{length s > 0})
: seq a & a
= take s (length s - 1),
s $@ (length s - 1)
let split #a (s:seq a) (i:nat{ i <= length s})
: seq a & seq a
= take s i,
drop s i
/// Counts the number of elements of `s` that
/// satisfy the predicate [f]
let rec count_matches (#a:Type) (f:a -> bool) (s:seq a)
: Tot nat (decreases (length s))
= all_seq_facts_lemma();
if length s = 0 then 0
else if f (head s) then 1 + count_matches f (tail s)
else count_matches f (tail s)
/// count_matches on an empty sequence is always zero
let count_matches_empty (a:Type) (f:a -> bool) (s:seq a{length s = 0})
: Lemma (count_matches f s = 0)
= ()
/// count is a specialization of count_matches
/// to count the number of occurrences of a given element `x` in `s`.
///
/// It is opaque to give control over its unrollings in specific proofs
[@@"opaque_to_smt"]
let count (#a:eqtype) (x:a) (s:seq a) = count_matches (fun y -> x = y) s | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Sequence.Util.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Sequence.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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.Sequence.Base.seq a {FStar.Sequence.Base.length s = 0}
-> FStar.Pervasives.Lemma (ensures forall (x: a). FStar.Sequence.Util.count x s = 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"FStar.Sequence.Base.seq",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Sequence.Base.length",
"FStar.Pervasives.reveal_opaque",
"Prims.nat",
"FStar.Sequence.Util.count",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_Forall",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let count_empty (#a: eqtype) (s: seq a {length s = 0}) : Lemma (forall x. count x s = 0) =
| reveal_opaque (`%count) (count #a) | false |
FStar.Sequence.Util.fst | FStar.Sequence.Util.count_head | val count_head (#a: eqtype) (s: seq a {length s > 0}) : Lemma (count (head s) s > 0) | val count_head (#a: eqtype) (s: seq a {length s > 0}) : Lemma (count (head s) s > 0) | let count_head (#a:eqtype) (s:seq a{length s > 0})
: Lemma (count (head s) s > 0)
= reveal_opaque (`%count) (count #a) | {
"file_name": "ulib/experimental/FStar.Sequence.Util.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 77,
"start_col": 0,
"start_line": 75
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
(** This module provides some utilities on top of FStar.Sequence *)
module FStar.Sequence.Util
open FStar.Sequence.Base
/// For convenience, we define `slice` to represent Dafny sequence slices.
let slice (#ty: Type) (s: seq ty) (i: nat) (j: nat{j >= i && j <= length s})
: seq ty
= all_seq_facts_lemma();
drop (take s j) i
let cons #a (x:a) (s:seq a) = singleton x `append` s
let head #a (s:seq a{length s > 0}) = s $@ 0
let tail #a (s:seq a{length s > 0}) = drop s 1
/// Split a sequences into a prefix and the last element
/// This is the inverse of the Sequence.build
let un_build (#a:_) (s:seq a{length s > 0})
: seq a & a
= take s (length s - 1),
s $@ (length s - 1)
let split #a (s:seq a) (i:nat{ i <= length s})
: seq a & seq a
= take s i,
drop s i
/// Counts the number of elements of `s` that
/// satisfy the predicate [f]
let rec count_matches (#a:Type) (f:a -> bool) (s:seq a)
: Tot nat (decreases (length s))
= all_seq_facts_lemma();
if length s = 0 then 0
else if f (head s) then 1 + count_matches f (tail s)
else count_matches f (tail s)
/// count_matches on an empty sequence is always zero
let count_matches_empty (a:Type) (f:a -> bool) (s:seq a{length s = 0})
: Lemma (count_matches f s = 0)
= ()
/// count is a specialization of count_matches
/// to count the number of occurrences of a given element `x` in `s`.
///
/// It is opaque to give control over its unrollings in specific proofs
[@@"opaque_to_smt"]
let count (#a:eqtype) (x:a) (s:seq a) = count_matches (fun y -> x = y) s
/// A specializtion of count_matches_empty
let count_empty (#a:eqtype) (s:seq a{length s = 0})
: Lemma (forall x. count x s = 0)
= reveal_opaque (`%count) (count #a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Sequence.Util.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Sequence.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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.Sequence.Base.seq a {FStar.Sequence.Base.length s > 0}
-> FStar.Pervasives.Lemma (ensures FStar.Sequence.Util.count (FStar.Sequence.Util.head s) s > 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"FStar.Sequence.Base.seq",
"Prims.b2t",
"Prims.op_GreaterThan",
"FStar.Sequence.Base.length",
"FStar.Pervasives.reveal_opaque",
"Prims.nat",
"FStar.Sequence.Util.count",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"FStar.Sequence.Util.head",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let count_head (#a: eqtype) (s: seq a {length s > 0}) : Lemma (count (head s) s > 0) =
| reveal_opaque (`%count) (count #a) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_add_r_to_rw_set | val lemma_add_r_to_rw_set :
r:locations ->
rw:rw_set ->
f:st unit ->
Lemma
(requires (
(bounded_effects rw f)))
(ensures (
(bounded_effects (add_r_to_rw_set r rw) f))) | val lemma_add_r_to_rw_set :
r:locations ->
rw:rw_set ->
f:st unit ->
Lemma
(requires (
(bounded_effects rw f)))
(ensures (
(bounded_effects (add_r_to_rw_set r rw) f))) | let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 901,
"start_col": 0,
"start_line": 887
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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.Transformers.Locations.locations ->
rw: Vale.Transformers.BoundedInstructionEffects.rw_set ->
f: Vale.X64.Machine_Semantics_s.st Prims.unit
-> FStar.Pervasives.Lemma
(requires Vale.Transformers.BoundedInstructionEffects.bounded_effects rw f)
(ensures
Vale.Transformers.BoundedInstructionEffects.bounded_effects (Vale.Transformers.BoundedInstructionEffects.add_r_to_rw_set
r
rw)
f) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.Transformers.BoundedInstructionEffects.rw_set",
"Vale.X64.Machine_Semantics_s.st",
"Prims.unit",
"FStar.Classical.forall_intro_2",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.l_imp",
"Prims.l_and",
"Vale.Transformers.BoundedInstructionEffects.bounded_effects",
"Prims.b2t",
"Prims.op_Equality",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_reads",
"FStar.Pervasives.Native.snd",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Classical.move_requires",
"Vale.X64.Machine_Semantics_s.run",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_append",
"Vale.Transformers.BoundedInstructionEffects.add_r_to_rw_set"
] | [] | false | false | true | false | false | let lemma_add_r_to_rw_set r rw_old f =
| let rw = add_r_to_rw_set r rw_old in
let aux s1 s2
: Lemma
(requires
((bounded_effects rw_old f) /\ (s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures
(((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==> unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_constant_on_execution_mem | val lemma_constant_on_execution_mem
(locv: locations_with_values)
(f: st unit)
(s: machine_state)
(l: location_eq)
(v: location_val_eqt l)
: Lemma
(requires ((run f s).ms_ok /\ (constant_on_execution locv f s) /\ (L.mem (| l, v |) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) | val lemma_constant_on_execution_mem
(locv: locations_with_values)
(f: st unit)
(s: machine_state)
(l: location_eq)
(v: location_val_eqt l)
: Lemma
(requires ((run f s).ms_ok /\ (constant_on_execution locv f s) /\ (L.mem (| l, v |) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) | let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 884,
"start_col": 0,
"start_line": 873
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
} | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
locv: Vale.Transformers.BoundedInstructionEffects.locations_with_values ->
f: Vale.X64.Machine_Semantics_s.st Prims.unit ->
s: Vale.X64.Machine_Semantics_s.machine_state ->
l: Vale.Transformers.Locations.location_eq ->
v: Vale.Transformers.Locations.location_val_eqt l
-> FStar.Pervasives.Lemma
(requires
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run f s) /\
Vale.Transformers.BoundedInstructionEffects.constant_on_execution locv f s /\
FStar.List.Tot.Base.mem (| l, v |) locv)
(ensures
Vale.Transformers.Locations.eval_location l (Vale.X64.Machine_Semantics_s.run f s) ==
Vale.Transformers.Locations.raise_location_val_eqt v) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.BoundedInstructionEffects.locations_with_values",
"Vale.X64.Machine_Semantics_s.st",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.Locations.location_eq",
"Vale.Transformers.Locations.location_val_eqt",
"Prims.list",
"Vale.Transformers.BoundedInstructionEffects.location_with_value",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Prims.bool",
"Vale.Transformers.BoundedInstructionEffects.lemma_constant_on_execution_mem",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.X64.Machine_Semantics_s.run",
"Vale.Transformers.BoundedInstructionEffects.constant_on_execution",
"FStar.List.Tot.Base.mem",
"Prims.Mkdtuple2",
"Prims.squash",
"Prims.eq2",
"Vale.Transformers.Locations.location_val_t",
"Vale.Transformers.Locations.eval_location",
"Vale.Transformers.Locations.raise_location_val_eqt",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_constant_on_execution_mem
(locv: locations_with_values)
(f: st unit)
(s: machine_state)
(l: location_eq)
(v: location_val_eqt l)
: Lemma
(requires ((run f s).ms_ok /\ (constant_on_execution locv f s) /\ (L.mem (| l, v |) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
| let (| l1 , v1 |) :: xs = locv in
if l = l1 && v = v1 then () else (lemma_constant_on_execution_mem xs f s l v) | false |
FStar.Sequence.Util.fst | FStar.Sequence.Util.count_matches | val count_matches (#a: Type) (f: (a -> bool)) (s: seq a) : Tot nat (decreases (length s)) | val count_matches (#a: Type) (f: (a -> bool)) (s: seq a) : Tot nat (decreases (length s)) | let rec count_matches (#a:Type) (f:a -> bool) (s:seq a)
: Tot nat (decreases (length s))
= all_seq_facts_lemma();
if length s = 0 then 0
else if f (head s) then 1 + count_matches f (tail s)
else count_matches f (tail s) | {
"file_name": "ulib/experimental/FStar.Sequence.Util.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 55,
"start_col": 0,
"start_line": 50
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
(** This module provides some utilities on top of FStar.Sequence *)
module FStar.Sequence.Util
open FStar.Sequence.Base
/// For convenience, we define `slice` to represent Dafny sequence slices.
let slice (#ty: Type) (s: seq ty) (i: nat) (j: nat{j >= i && j <= length s})
: seq ty
= all_seq_facts_lemma();
drop (take s j) i
let cons #a (x:a) (s:seq a) = singleton x `append` s
let head #a (s:seq a{length s > 0}) = s $@ 0
let tail #a (s:seq a{length s > 0}) = drop s 1
/// Split a sequences into a prefix and the last element
/// This is the inverse of the Sequence.build
let un_build (#a:_) (s:seq a{length s > 0})
: seq a & a
= take s (length s - 1),
s $@ (length s - 1)
let split #a (s:seq a) (i:nat{ i <= length s})
: seq a & seq a
= take s i,
drop s i
/// Counts the number of elements of `s` that | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Sequence.Util.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Sequence.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: a -> Prims.bool) -> s: FStar.Sequence.Base.seq a -> Prims.Tot Prims.nat | Prims.Tot | [
"total",
""
] | [] | [
"Prims.bool",
"FStar.Sequence.Base.seq",
"Prims.op_Equality",
"Prims.int",
"FStar.Sequence.Base.length",
"FStar.Sequence.Util.head",
"Prims.op_Addition",
"FStar.Sequence.Util.count_matches",
"FStar.Sequence.Util.tail",
"Prims.nat",
"Prims.unit",
"FStar.Sequence.Base.all_seq_facts_lemma"
] | [
"recursion"
] | false | false | false | true | false | let rec count_matches (#a: Type) (f: (a -> bool)) (s: seq a) : Tot nat (decreases (length s)) =
| all_seq_facts_lemma ();
if length s = 0
then 0
else if f (head s) then 1 + count_matches f (tail s) else count_matches f (tail s) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_mem | val lemma_unchanged_at_mem (as0: list location) (a: location) (s1 s2: machine_state)
: Lemma (requires ((unchanged_at as0 s1 s2) /\ (L.mem a as0)))
(ensures ((eval_location a s1 == eval_location a s2))) | val lemma_unchanged_at_mem (as0: list location) (a: location) (s1 s2: machine_state)
: Lemma (requires ((unchanged_at as0 s1 s2) /\ (L.mem a as0)))
(ensures ((eval_location a s1 == eval_location a s2))) | let rec lemma_unchanged_at_mem (as0:list location) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at_mem xs a s1 s2 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 938,
"start_col": 0,
"start_line": 927
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux
let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 2,
"max_ifuel": 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 |
as0: Prims.list Vale.Transformers.Locations.location ->
a: Vale.Transformers.Locations.location ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
Vale.Transformers.BoundedInstructionEffects.unchanged_at as0 s1 s2 /\
FStar.List.Tot.Base.mem a as0)
(ensures
Vale.Transformers.Locations.eval_location a s1 ==
Vale.Transformers.Locations.eval_location a s2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Vale.Transformers.Locations.location",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.op_Equality",
"Prims.bool",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_mem",
"Prims.unit",
"Prims.l_and",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Prims.b2t",
"FStar.List.Tot.Base.mem",
"Prims.squash",
"Prims.eq2",
"Vale.Transformers.Locations.location_val_t",
"Vale.Transformers.Locations.eval_location",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_unchanged_at_mem (as0: list location) (a: location) (s1 s2: machine_state)
: Lemma (requires ((unchanged_at as0 s1 s2) /\ (L.mem a as0)))
(ensures ((eval_location a s1 == eval_location a s2))) =
| match as0 with
| [_] -> ()
| x :: xs -> if a = x then () else lemma_unchanged_at_mem xs a s1 s2 | false |
FStar.Sequence.Util.fst | FStar.Sequence.Util.fold_back | val fold_back (#a #b: Type) (f: (b -> a -> Tot a)) (s: seq b) (init: a)
: Tot a (decreases (length s)) | val fold_back (#a #b: Type) (f: (b -> a -> Tot a)) (s: seq b) (init: a)
: Tot a (decreases (length s)) | let rec fold_back (#a #b:Type) (f:b -> a -> Tot a) (s:seq b) (init:a)
: Tot a (decreases (length s))
= all_seq_facts_lemma();
if length s = 0 then init
else let last = s $@ (length s - 1) in
let s = take s (length s - 1) in
f last (fold_back f s init) | {
"file_name": "ulib/experimental/FStar.Sequence.Util.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 102,
"start_col": 0,
"start_line": 96
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
(** This module provides some utilities on top of FStar.Sequence *)
module FStar.Sequence.Util
open FStar.Sequence.Base
/// For convenience, we define `slice` to represent Dafny sequence slices.
let slice (#ty: Type) (s: seq ty) (i: nat) (j: nat{j >= i && j <= length s})
: seq ty
= all_seq_facts_lemma();
drop (take s j) i
let cons #a (x:a) (s:seq a) = singleton x `append` s
let head #a (s:seq a{length s > 0}) = s $@ 0
let tail #a (s:seq a{length s > 0}) = drop s 1
/// Split a sequences into a prefix and the last element
/// This is the inverse of the Sequence.build
let un_build (#a:_) (s:seq a{length s > 0})
: seq a & a
= take s (length s - 1),
s $@ (length s - 1)
let split #a (s:seq a) (i:nat{ i <= length s})
: seq a & seq a
= take s i,
drop s i
/// Counts the number of elements of `s` that
/// satisfy the predicate [f]
let rec count_matches (#a:Type) (f:a -> bool) (s:seq a)
: Tot nat (decreases (length s))
= all_seq_facts_lemma();
if length s = 0 then 0
else if f (head s) then 1 + count_matches f (tail s)
else count_matches f (tail s)
/// count_matches on an empty sequence is always zero
let count_matches_empty (a:Type) (f:a -> bool) (s:seq a{length s = 0})
: Lemma (count_matches f s = 0)
= ()
/// count is a specialization of count_matches
/// to count the number of occurrences of a given element `x` in `s`.
///
/// It is opaque to give control over its unrollings in specific proofs
[@@"opaque_to_smt"]
let count (#a:eqtype) (x:a) (s:seq a) = count_matches (fun y -> x = y) s
/// A specializtion of count_matches_empty
let count_empty (#a:eqtype) (s:seq a{length s = 0})
: Lemma (forall x. count x s = 0)
= reveal_opaque (`%count) (count #a)
/// The head element always occurs in a non-empty list
let count_head (#a:eqtype) (s:seq a{length s > 0})
: Lemma (count (head s) s > 0)
= reveal_opaque (`%count) (count #a)
/// count sums over append
let rec lemma_append_count_aux (#a:eqtype) (x:a) (lo hi:seq a)
: Lemma
(ensures (count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= all_seq_facts_lemma();
reveal_opaque (`%count) (count #a);
if length lo = 0
then assert (append lo hi `equal` hi)
else (
lemma_append_count_aux x (tail lo) hi;
assert (append (tail lo) hi `equal` tail (append lo hi))
)
/// Folding a function over a sequence, starting from its | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Sequence.Util.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Sequence.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: b -> _: a -> a) -> s: FStar.Sequence.Base.seq b -> init: a -> Prims.Tot a | Prims.Tot | [
"total",
""
] | [] | [
"FStar.Sequence.Base.seq",
"Prims.op_Equality",
"Prims.int",
"FStar.Sequence.Base.length",
"Prims.bool",
"FStar.Sequence.Util.fold_back",
"FStar.Sequence.Base.take",
"Prims.op_Subtraction",
"FStar.Sequence.Base.op_Dollar_At",
"Prims.unit",
"FStar.Sequence.Base.all_seq_facts_lemma"
] | [
"recursion"
] | false | false | false | true | false | let rec fold_back (#a #b: Type) (f: (b -> a -> Tot a)) (s: seq b) (init: a)
: Tot a (decreases (length s)) =
| all_seq_facts_lemma ();
if length s = 0
then init
else
let last = s $@ (length s - 1) in
let s = take s (length s - 1) in
f last (fold_back f s init) | false |
Vale.Stdcalls.X64.Fsqr.fsti | Vale.Stdcalls.X64.Fsqr.fsqr2_lemma' | val fsqr2_lemma' (code: V.va_code) (_win: bool) (tmp f1 out: b64) (va_s0: V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires fsqr2_pre code tmp f1 out va_s0)
(ensures
(fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fsqr2_post code tmp f1 out va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\ ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp)) ME.loc_none))
(VS.vs_get_vale_heap va_s0)
(VS.vs_get_vale_heap va_s1))) | val fsqr2_lemma' (code: V.va_code) (_win: bool) (tmp f1 out: b64) (va_s0: V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires fsqr2_pre code tmp f1 out va_s0)
(ensures
(fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fsqr2_post code tmp f1 out va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\ ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp)) ME.loc_none))
(VS.vs_get_vale_heap va_s0)
(VS.vs_get_vale_heap va_s1))) | let fsqr2_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fsqr2_pre code tmp f1 out va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fsqr2_post code tmp f1 out va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fsqr2_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f) | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.Fsqr.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 179,
"start_col": 0,
"start_line": 151
} | module Vale.Stdcalls.X64.Fsqr
open FStar.Mul
val z3rlimit_hack (x:nat) : squash (x < x + x + 1)
#reset-options "--z3rlimit 50"
open FStar.HyperStack.ST
module HS = FStar.HyperStack
module B = LowStar.Buffer
module DV = LowStar.BufferView.Down
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
open Vale.AsLowStar.MemoryHelpers
module FU = Vale.Curve25519.X64.FastUtil
module FH = Vale.Curve25519.X64.FastHybrid
module FW = Vale.Curve25519.X64.FastWide
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b64 = buf_t TUInt64 TUInt64
[@__reduce__] noextract
let t64_mod = TD_Buffer TUInt64 TUInt64 default_bq
[@__reduce__] noextract
let t64_no_mod = TD_Buffer TUInt64 TUInt64 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let fsqr_dom: IX64.arity_ok_stdcall td =
let y = [t64_mod; t64_no_mod; t64_mod] in
assert_norm (List.length y = 3);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fsqr_pre : VSig.vale_pre fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state) ->
FW.va_req_Fsqr_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out)
[@__reduce__] noextract
let fsqr_post : VSig.vale_post fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fsqr_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) va_s1 f
#set-options "--z3rlimit 200"
[@__reduce__] noextract
let fsqr_lemma'
(code:V.va_code)
(_win:bool)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
fsqr_pre code tmp f1 out va_s0)
(ensures (fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\
VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fsqr_post code tmp f1 out va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\
ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp))
ME.loc_none)) (VS.vs_get_vale_heap va_s0) (VS.vs_get_vale_heap va_s1)
)) =
let va_s1, f = FW.va_lemma_Fsqr_stdcall code va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f)
(* Prove that fsqr_lemma' has the required type *)
noextract
let fsqr_lemma = as_t #(VSig.vale_sig_stdcall fsqr_pre fsqr_post) fsqr_lemma'
noextract
let code_Fsqr = FW.va_code_Fsqr_stdcall IA.win
(* Here's the type expected for the fsqr wrapper *)
[@__reduce__] noextract
let lowstar_Fsqr_t =
assert_norm (List.length fsqr_dom + List.length ([]<:list arg) <= 4);
IX64.as_lowstar_sig_t_weak_stdcall
code_Fsqr
fsqr_dom
[]
_
_
(W.mk_prediction code_Fsqr fsqr_dom [] (fsqr_lemma code_Fsqr IA.win))
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let fsqr2_pre : VSig.vale_pre fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state) ->
FW.va_req_Fsqr2_stdcall c va_s0 IA.win
(as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out)
[@__reduce__] noextract
let fsqr2_post : VSig.vale_post fsqr_dom =
fun (c:V.va_code)
(tmp:b64)
(f1:b64)
(out:b64)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
FW.va_ens_Fsqr2_stdcall c va_s0 IA.win (as_vale_buffer tmp) (as_vale_buffer f1) (as_vale_buffer out) va_s1 f
#set-options "--z3rlimit 200" | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Curve25519.X64.FastWide.fsti.checked",
"Vale.Curve25519.X64.FastUtil.fsti.checked",
"Vale.Curve25519.X64.FastHybrid.fsti.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.Fsqr.fsti"
} | [
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastWide",
"short_module": "FW"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastHybrid",
"short_module": "FH"
},
{
"abbrev": true,
"full_module": "Vale.Curve25519.X64.FastUtil",
"short_module": "FU"
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
code: Vale.X64.Decls.va_code ->
_win: Prims.bool ->
tmp: Vale.Stdcalls.X64.Fsqr.b64 ->
f1: Vale.Stdcalls.X64.Fsqr.b64 ->
out: Vale.Stdcalls.X64.Fsqr.b64 ->
va_s0: Vale.X64.Decls.va_state
-> Prims.Ghost (Vale.X64.Decls.va_state * Vale.X64.Decls.va_fuel) | Prims.Ghost | [] | [] | [
"Vale.X64.Decls.va_code",
"Prims.bool",
"Vale.Stdcalls.X64.Fsqr.b64",
"Vale.X64.Decls.va_state",
"Vale.X64.Decls.va_fuel",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal",
"Vale.Arch.HeapTypes_s.TUInt64",
"FStar.Pervasives.Native.tuple2",
"Vale.X64.State.vale_state",
"Vale.Curve25519.X64.FastWide.va_lemma_Fsqr2_stdcall",
"Vale.Interop.Assumptions.win",
"Vale.X64.MemoryAdapters.as_vale_buffer",
"Vale.Stdcalls.X64.Fsqr.fsqr2_pre",
"Prims.l_and",
"Vale.X64.Decls.eval_code",
"Vale.AsLowStar.ValeSig.vale_calling_conventions_stdcall",
"Vale.Stdcalls.X64.Fsqr.fsqr2_post",
"Vale.X64.Memory.buffer_readable",
"Vale.X64.State.vs_get_vale_heap",
"Vale.X64.Memory.buffer_writeable",
"Vale.X64.Memory.modifies",
"Vale.X64.Memory.loc_union",
"Vale.X64.Memory.loc_buffer",
"Vale.X64.Memory.loc_none"
] | [] | false | false | false | false | false | let fsqr2_lemma' (code: V.va_code) (_win: bool) (tmp f1 out: b64) (va_s0: V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires fsqr2_pre code tmp f1 out va_s0)
(ensures
(fun (va_s1, f) ->
V.eval_code code va_s0 f va_s1 /\ VSig.vale_calling_conventions_stdcall va_s0 va_s1 /\
fsqr2_post code tmp f1 out va_s0 va_s1 f /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer out) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer f1) /\
ME.buffer_readable (VS.vs_get_vale_heap va_s1) (as_vale_buffer tmp) /\
ME.buffer_writeable (as_vale_buffer out) /\ ME.buffer_writeable (as_vale_buffer f1) /\
ME.buffer_writeable (as_vale_buffer tmp) /\
ME.modifies (ME.loc_union (ME.loc_buffer (as_vale_buffer out))
(ME.loc_union (ME.loc_buffer (as_vale_buffer tmp)) ME.loc_none))
(VS.vs_get_vale_heap va_s0)
(VS.vs_get_vale_heap va_s1))) =
| let va_s1, f =
FW.va_lemma_Fsqr2_stdcall code
va_s0
IA.win
(as_vale_buffer tmp)
(as_vale_buffer f1)
(as_vale_buffer out)
in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 out;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 f1;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt64 ME.TUInt64 tmp;
(va_s1, f) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_sym_diff_implies_difference | val lemma_unchanged_at_sym_diff_implies_difference (l1 l2: locations) (s1 s2: machine_state)
: Lemma (requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) | val lemma_unchanged_at_sym_diff_implies_difference (l1 l2: locations) (s1 s2: machine_state)
: Lemma (requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) | let lemma_unchanged_at_sym_diff_implies_difference (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) =
lemma_unchanged_at_append (l1 `difference` l2) (l2 `difference` l1) s1 s2 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 75,
"end_line": 959,
"start_col": 0,
"start_line": 955
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux
let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
)
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at_mem (as0:list location) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_at_difference_elim (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1 s2;
lemma_unchanged_at_difference_elim xs l2 s1 s2
) else (
lemma_unchanged_at_difference_elim xs l2 s1 s2
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
l1: Vale.Transformers.Locations.locations ->
l2: Vale.Transformers.Locations.locations ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Vale.Transformers.BoundedInstructionEffects.sym_difference
l1
l2)
s1
s2)
(ensures
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Vale.Transformers.BoundedInstructionEffects.difference
l1
l2)
s1
s2 /\
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Vale.Transformers.BoundedInstructionEffects.difference
l2
l1)
s1
s2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_append",
"Vale.Transformers.BoundedInstructionEffects.difference",
"Vale.Transformers.Locations.location",
"Prims.unit",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.Transformers.BoundedInstructionEffects.sym_difference",
"Prims.squash",
"Prims.l_and",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_unchanged_at_sym_diff_implies_difference (l1 l2: locations) (s1 s2: machine_state)
: Lemma (requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) =
| lemma_unchanged_at_append (l1 `difference` l2) (l2 `difference` l1) s1 s2 | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_difference_elim | val lemma_unchanged_at_difference_elim (l1 l2: locations) (s1 s2: machine_state)
: Lemma (requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) | val lemma_unchanged_at_difference_elim (l1 l2: locations) (s1 s2: machine_state)
: Lemma (requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) | let rec lemma_unchanged_at_difference_elim (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1 s2;
lemma_unchanged_at_difference_elim xs l2 s1 s2
) else (
lemma_unchanged_at_difference_elim xs l2 s1 s2
) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 953,
"start_col": 0,
"start_line": 941
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux
let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
)
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at_mem (as0:list location) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at_mem xs a s1 s2
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
l1: Vale.Transformers.Locations.locations ->
l2: Vale.Transformers.Locations.locations ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Vale.Transformers.BoundedInstructionEffects.difference
l1
l2)
s1
s2 /\ Vale.Transformers.BoundedInstructionEffects.unchanged_at l2 s1 s2)
(ensures Vale.Transformers.BoundedInstructionEffects.unchanged_at l1 s1 s2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.Locations.location",
"Prims.list",
"FStar.List.Tot.Base.mem",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_difference_elim",
"Prims.unit",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_mem",
"Prims.bool",
"Prims.l_and",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.Transformers.BoundedInstructionEffects.difference",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_unchanged_at_difference_elim (l1 l2: locations) (s1 s2: machine_state)
: Lemma (requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) =
| match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2
then
(lemma_unchanged_at_mem l2 x s1 s2;
lemma_unchanged_at_difference_elim xs l2 s1 s2)
else (lemma_unchanged_at_difference_elim xs l2 s1 s2) | false |
Hacl.Impl.Curve25519.Generic.fst | Hacl.Impl.Curve25519.Generic.montgomery_ladder | val montgomery_ladder:
#s:field_spec
-> o:point s
-> k:scalar
-> i:point s
-> Stack unit
(requires fun h0 ->
live h0 o /\ live h0 k /\ live h0 i /\
(disjoint o i \/ o == i) /\ disjoint o k /\ disjoint k i /\
fget_z h0 i == 1 /\ state_inv_t h0 (get_x i) /\ state_inv_t h0 (get_z i))
(ensures fun h0 _ h1 ->
modifies (loc o) h0 h1 /\
state_inv_t h1 (get_x o) /\ state_inv_t h1 (get_z o) /\
fget_xz h1 o == S.montgomery_ladder (fget_x h0 i) (as_seq h0 k)) | val montgomery_ladder:
#s:field_spec
-> o:point s
-> k:scalar
-> i:point s
-> Stack unit
(requires fun h0 ->
live h0 o /\ live h0 k /\ live h0 i /\
(disjoint o i \/ o == i) /\ disjoint o k /\ disjoint k i /\
fget_z h0 i == 1 /\ state_inv_t h0 (get_x i) /\ state_inv_t h0 (get_z i))
(ensures fun h0 _ h1 ->
modifies (loc o) h0 h1 /\
state_inv_t h1 (get_x o) /\ state_inv_t h1 (get_z o) /\
fget_xz h1 o == S.montgomery_ladder (fget_x h0 i) (as_seq h0 k)) | let montgomery_ladder #s out key init =
push_frame();
let h0 = ST.get () in
let tmp2 = create (2ul `FStar.UInt32.mul` ((nwide s) <: FStar.UInt32.t)) (wide_zero s) in
let p01_tmp1_swap = create (8ul *! nlimb s +! 1ul) (limb_zero s) in
let p0 : point s = sub p01_tmp1_swap 0ul (2ul *! nlimb s) in
assert (gsub p01_tmp1_swap 0ul (2ul *! nlimb s) == p0);
ladder4_ #s key init p01_tmp1_swap tmp2;
copy out p0;
pop_frame () | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Generic.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 463,
"start_col": 0,
"start_line": 453
} | module Hacl.Impl.Curve25519.Generic
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Curve25519.Fields
include Hacl.Impl.Curve25519.Finv
include Hacl.Impl.Curve25519.AddAndDouble
module ST = FStar.HyperStack.ST
module BSeq = Lib.ByteSequence
module LSeq = Lib.Sequence
module C = Hacl.Impl.Curve25519.Fields.Core
module S = Spec.Curve25519
module M = Hacl.Spec.Curve25519.AddAndDouble
module Lemmas = Hacl.Spec.Curve25519.Field64.Lemmas
friend Lib.LoopCombinators
#set-options "--z3rlimit 30 --fuel 0 --ifuel 1 --using_facts_from '* -FStar.Seq -Hacl.Spec.*' --record_options"
//#set-options "--debug Hacl.Impl.Curve25519.Generic --debug_level ExtractNorm"
inline_for_extraction noextract
let scalar = lbuffer uint8 32ul
inline_for_extraction noextract
val scalar_bit:
s:scalar
-> n:size_t{v n < 256}
-> Stack uint64
(requires fun h0 -> live h0 s)
(ensures fun h0 r h1 -> h0 == h1 /\
r == S.ith_bit (as_seq h0 s) (v n) /\ v r <= 1)
let scalar_bit s n =
let h0 = ST.get () in
mod_mask_lemma ((LSeq.index (as_seq h0 s) (v n / 8)) >>. (n %. 8ul)) 1ul;
assert_norm (1 = pow2 1 - 1);
assert (v (mod_mask #U8 #SEC 1ul) == v (u8 1));
to_u64 ((s.(n /. 8ul) >>. (n %. 8ul)) &. u8 1)
inline_for_extraction noextract
val decode_point:
#s:field_spec
-> o:point s
-> i:lbuffer uint8 32ul
-> Stack unit
(requires fun h0 -> live h0 o /\ live h0 i /\ disjoint o i)
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
state_inv_t h1 (get_x o) /\ state_inv_t h1 (get_z o) /\
fget_x h1 o == S.decodePoint (as_seq h0 i) /\ fget_z h1 o == 1)
[@ Meta.Attribute.specialize ]
let decode_point #s o i =
push_frame();
let tmp = create 4ul (u64 0) in
let h0 = ST.get () in
uints_from_bytes_le #U64 tmp i;
let h1 = ST.get () in
BSeq.uints_from_bytes_le_nat_lemma #U64 #SEC #4 (as_seq h0 i);
assert (BSeq.nat_from_intseq_le (as_seq h1 tmp) == BSeq.nat_from_bytes_le (as_seq h0 i));
let tmp3 = tmp.(3ul) in
tmp.(3ul) <- tmp3 &. u64 0x7fffffffffffffff;
mod_mask_lemma tmp3 63ul;
assert_norm (0x7fffffffffffffff = pow2 63 - 1);
assert (v (mod_mask #U64 #SEC 63ul) == v (u64 0x7fffffffffffffff));
let h2 = ST.get () in
assert (v (LSeq.index (as_seq h2 tmp) 3) < pow2 63);
Lemmas.lemma_felem64_mod255 (as_seq h1 tmp);
assert (BSeq.nat_from_intseq_le (as_seq h2 tmp) == BSeq.nat_from_bytes_le (as_seq h0 i) % pow2 255);
let x : felem s = sub o 0ul (nlimb s) in
let z : felem s = sub o (nlimb s) (nlimb s) in
set_one z;
load_felem x tmp;
pop_frame()
val encode_point:
#s:field_spec
-> o:lbuffer uint8 32ul
-> i:point s
-> Stack unit
(requires fun h0 ->
live h0 o /\ live h0 i /\ disjoint o i /\
state_inv_t h0 (get_x i) /\ state_inv_t h0 (get_z i))
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == S.encodePoint (fget_x h0 i, fget_z h0 i))
[@ Meta.Attribute.specialize ]
let encode_point #s o i =
push_frame();
let x : felem s = sub i 0ul (nlimb s) in
let z : felem s = sub i (nlimb s) (nlimb s) in
let tmp = create_felem s in
let u64s = create 4ul (u64 0) in
let tmp_w = create (2ul `FStar.UInt32.mul` ((nwide s) <: FStar.UInt32.t)) (wide_zero s) in
let h0 = ST.get () in
finv tmp z tmp_w;
fmul tmp tmp x tmp_w;
let h1 = ST.get () in
assert (feval h1 tmp == S.fmul (S.fpow (feval h0 z) (pow2 255 - 21)) (feval h0 x));
assert (feval h1 tmp == S.fmul (feval h0 x) (S.fpow (feval h0 z) (pow2 255 - 21)));
store_felem u64s tmp;
let h2 = ST.get () in
assert (as_seq h2 u64s == BSeq.nat_to_intseq_le 4 (feval h1 tmp));
uints_to_bytes_le #U64 4ul o u64s;
let h3 = ST.get () in
BSeq.uints_to_bytes_le_nat_lemma #U64 #SEC 4 (feval h1 tmp);
assert (as_seq h3 o == BSeq.nat_to_bytes_le 32 (feval h1 tmp));
pop_frame()
// TODO: why re-define the signature here?
val cswap2:
#s:field_spec
-> bit:uint64{v bit <= 1}
-> p1:felem2 s
-> p2:felem2 s
-> Stack unit
(requires fun h0 ->
live h0 p1 /\ live h0 p2 /\ disjoint p1 p2)
(ensures fun h0 _ h1 ->
modifies (loc p1 |+| loc p2) h0 h1 /\
(v bit == 1 ==> as_seq h1 p1 == as_seq h0 p2 /\ as_seq h1 p2 == as_seq h0 p1) /\
(v bit == 0 ==> as_seq h1 p1 == as_seq h0 p1 /\ as_seq h1 p2 == as_seq h0 p2) /\
(fget_xz h1 p1, fget_xz h1 p2) == S.cswap2 bit (fget_xz h0 p1) (fget_xz h0 p2))
[@ Meta.Attribute.inline_ ]
let cswap2 #s bit p0 p1 =
C.cswap2 #s bit p0 p1
val ladder_step:
#s:field_spec
-> k:scalar
-> q:point s
-> i:size_t{v i < 251}
-> p01_tmp1_swap:lbuffer (limb s) (8ul *! nlimb s +! 1ul)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 q /\ live h0 p01_tmp1_swap /\ live h0 tmp2 /\
LowStar.Monotonic.Buffer.all_disjoint [loc k; loc q; loc p01_tmp1_swap; loc tmp2] /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
v (LSeq.index (as_seq h0 bit) 0) <= 1 /\
state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q) /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
state_inv_t h0 (get_x nq_p1) /\ state_inv_t h0 (get_z nq_p1)))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
let (p0, p1, b) = S.ladder_step (as_seq h0 k) (fget_xz h0 q) (v i)
(fget_xz h0 nq, fget_xz h0 nq_p1, LSeq.index (as_seq h0 bit) 0) in
p0 == fget_xz h1 nq /\ p1 == fget_xz h1 nq_p1 /\
b == LSeq.index (as_seq h1 bit) 0 /\
v (LSeq.index (as_seq h1 bit) 0) <= 1 /\
state_inv_t h1 (get_x q) /\ state_inv_t h1 (get_z q) /\
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
state_inv_t h1 (get_x nq_p1) /\ state_inv_t h1 (get_z nq_p1)))
#push-options "--z3rlimit 200 --fuel 0 --ifuel 1"
[@ Meta.Attribute.inline_ ]
let ladder_step #s k q i p01_tmp1_swap tmp2 =
let p01_tmp1 = sub p01_tmp1_swap 0ul (8ul *! nlimb s) in
let swap : lbuffer uint64 1ul = sub p01_tmp1_swap (8ul *! nlimb s) 1ul in
let nq = sub p01_tmp1 0ul (2ul *! nlimb s) in
let nq_p1 = sub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) in
assert (gsub p01_tmp1_swap 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) == nq_p1);
assert (gsub p01_tmp1 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) == nq_p1);
assert (gsub p01_tmp1_swap 0ul (8ul *! nlimb s) == p01_tmp1);
assert (gsub p01_tmp1_swap (8ul *! nlimb s) 1ul == swap);
let h0 = ST.get () in
let bit = scalar_bit k (253ul -. i) in
assert (v bit == v (S.ith_bit (as_seq h0 k) (253 - v i)));
let sw = swap.(0ul) ^. bit in
logxor_lemma1 (LSeq.index (as_seq h0 swap) 0) bit;
cswap2 #s sw nq nq_p1;
point_add_and_double #s q p01_tmp1 tmp2;
swap.(0ul) <- bit
#pop-options
#push-options "--z3rlimit 300 --fuel 1 --ifuel 1"
val ladder_step_loop:
#s:field_spec
-> k:scalar
-> q:point s
-> p01_tmp1_swap:lbuffer (limb s) (8ul *! nlimb s +! 1ul)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 q /\ live h0 p01_tmp1_swap /\ live h0 tmp2 /\
LowStar.Monotonic.Buffer.all_disjoint [loc k; loc q; loc p01_tmp1_swap; loc tmp2] /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
v (LSeq.index (as_seq h0 bit) 0) <= 1 /\
state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q) /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
state_inv_t h0 (get_x nq_p1) /\ state_inv_t h0 (get_z nq_p1)))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
let (p0, p1, b) =
Lib.LoopCombinators.repeati 251
(S.ladder_step (as_seq h0 k) (fget_xz h0 q))
(fget_xz h0 nq, fget_xz h0 nq_p1, LSeq.index (as_seq h0 bit) 0) in
p0 == fget_xz h1 nq /\ p1 == fget_xz h1 nq_p1 /\ b == LSeq.index (as_seq h1 bit) 0 /\
v (LSeq.index (as_seq h1 bit) 0) <= 1 /\
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
state_inv_t h1 (get_x nq_p1) /\ state_inv_t h1 (get_z nq_p1)))
[@ Meta.Attribute.inline_ ]
let ladder_step_loop #s k q p01_tmp1_swap tmp2 =
let h0 = ST.get () in
[@ inline_let]
let spec_fh h0 =
S.ladder_step (as_seq h0 k) (fget_x h0 q, fget_z h0 q) in
[@ inline_let]
let acc h : GTot (tuple3 S.proj_point S.proj_point uint64) =
let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
(fget_xz h nq, fget_xz h nq_p1, LSeq.index (as_seq h bit) 0) in
[@ inline_let]
let inv h (i:nat{i <= 251}) =
let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let bit : lbuffer uint64 1ul = gsub p01_tmp1_swap (8ul *! nlimb s) 1ul in
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h /\
v (LSeq.index (as_seq h bit) 0) <= 1 /\
state_inv_t h (get_x q) /\ state_inv_t h (get_z q) /\
state_inv_t h (get_x nq) /\ state_inv_t h (get_z nq) /\
state_inv_t h (get_x nq_p1) /\ state_inv_t h (get_z nq_p1) /\
acc h == Lib.LoopCombinators.repeati i (spec_fh h0) (acc h0) in
Lib.Loops.for 0ul 251ul inv
(fun i ->
Lib.LoopCombinators.unfold_repeati 251 (spec_fh h0) (acc h0) (v i);
ladder_step #s k q i p01_tmp1_swap tmp2)
#pop-options
#push-options "--z3refresh --fuel 0 --ifuel 1 --z3rlimit 800"
val ladder0_:
#s:field_spec
-> k:scalar
-> q:point s
-> p01_tmp1_swap:lbuffer (limb s) (8ul *! nlimb s +! 1ul)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 q /\ live h0 p01_tmp1_swap /\ live h0 tmp2 /\
LowStar.Monotonic.Buffer.all_disjoint [loc k; loc q; loc p01_tmp1_swap; loc tmp2] /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q) /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
state_inv_t h0 (get_x nq_p1) /\ state_inv_t h0 (get_z nq_p1)))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
fget_xz h1 nq ==
M.montgomery_ladder1_0 (as_seq h0 k) (fget_xz h0 q) (fget_xz h0 nq) (fget_xz h0 nq_p1)))
[@ Meta.Attribute.inline_ ]
let ladder0_ #s k q p01_tmp1_swap tmp2 =
let p01_tmp1 = sub p01_tmp1_swap 0ul (8ul *! nlimb s) in
let nq : point s = sub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 : point s = sub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
let swap:lbuffer uint64 1ul = sub p01_tmp1_swap (8ul *! nlimb s) 1ul in
assert (gsub p01_tmp1_swap 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) == nq_p1);
assert (gsub p01_tmp1 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) == nq_p1);
assert (gsub p01_tmp1_swap 0ul (8ul *! nlimb s) == p01_tmp1);
assert (gsub p01_tmp1_swap (8ul *! nlimb s) 1ul == swap);
// bit 255 is 0 and bit 254 is 1
cswap2 #s (u64 1) nq nq_p1;
point_add_and_double #s q p01_tmp1 tmp2;
swap.(0ul) <- u64 1;
//Got about 1K speedup by removing 4 iterations here.
//First iteration can be skipped because top bit of scalar is 0
ladder_step_loop #s k q p01_tmp1_swap tmp2;
let sw = swap.(0ul) in
cswap2 #s sw nq nq_p1
val ladder1_:
#s:field_spec
-> p01_tmp1:lbuffer (limb s) (8ul *! nlimb s)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 p01_tmp1 /\ live h0 tmp2 /\ disjoint p01_tmp1 tmp2 /\
(let nq = gsub p01_tmp1 0ul (2ul *! nlimb s) in
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq)))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1 |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1 0ul (2ul *! nlimb s) in
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
fget_xz h1 nq == M.montgomery_ladder1_1 (fget_xz h0 nq)))
[@ Meta.Attribute.inline_ ]
let ladder1_ #s p01_tmp1 tmp2 =
let nq : point s = sub p01_tmp1 0ul (2ul *! nlimb s) in
let tmp1 = sub p01_tmp1 (4ul *! nlimb s) (4ul *! nlimb s) in
assert (gsub p01_tmp1 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1 (4ul *! nlimb s) (4ul *! nlimb s) == tmp1);
point_double nq tmp1 tmp2;
point_double nq tmp1 tmp2;
point_double nq tmp1 tmp2
val ladder2_:
#s:field_spec
-> k:scalar
-> q:point s
-> p01_tmp1_swap:lbuffer (limb s) (8ul *! nlimb s +! 1ul)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 q /\ live h0 p01_tmp1_swap /\ live h0 tmp2 /\
LowStar.Monotonic.Buffer.all_disjoint [loc k; loc q; loc p01_tmp1_swap; loc tmp2] /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q) /\
state_inv_t h0 (get_x nq) /\ state_inv_t h0 (get_z nq) /\
state_inv_t h0 (get_x nq_p1) /\ state_inv_t h0 (get_z nq_p1)))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
(let nq' = M.montgomery_ladder1_0 (as_seq h0 k) (fget_xz h0 q) (fget_xz h0 nq) (fget_xz h0 nq_p1) in
fget_xz h1 nq == M.montgomery_ladder1_1 nq')))
[@ Meta.Attribute.inline_ ]
let ladder2_ #s k q p01_tmp1_swap tmp2 =
let p01_tmp1 = sub p01_tmp1_swap 0ul (8ul *! nlimb s) in
let nq : point s = sub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let nq_p1 : point s = sub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
assert (gsub p01_tmp1_swap 0ul (8ul *! nlimb s) == p01_tmp1);
assert (gsub p01_tmp1_swap 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1 0ul (2ul *! nlimb s) == nq);
assert (gsub p01_tmp1 (2ul *! nlimb s) (2ul *! nlimb s) == nq_p1);
assert (gsub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) == nq_p1);
ladder0_ #s k q p01_tmp1_swap tmp2;
ladder1_ #s p01_tmp1 tmp2
inline_for_extraction noextract
val ladder3_:
#s:field_spec
-> q:point s
-> p01:lbuffer (limb s) (4ul *! nlimb s)
-> Stack unit
(requires fun h0 ->
live h0 q /\ live h0 p01 /\ disjoint q p01 /\
fget_z h0 q == 1 /\ state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q))
(ensures fun h0 _ h1 ->
modifies (loc p01) h0 h1 /\
(let nq = gsub p01 0ul (2ul *! nlimb s) in
let nq_p1 = gsub p01 (2ul *! nlimb s) (2ul *! nlimb s) in
state_inv_t h1 (get_x q) /\ state_inv_t h1 (get_z q) /\
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
state_inv_t h1 (get_x nq_p1) /\ state_inv_t h1 (get_z nq_p1) /\
(fget_xz h1 q, fget_xz h1 nq, fget_xz h1 nq_p1) == M.montgomery_ladder1_2 (fget_x h0 q)))
let ladder3_ #s q p01 =
let p0 : point s = sub p01 0ul (2ul *! nlimb s) in
let p1 : point s = sub p01 (2ul *! nlimb s) (2ul *! nlimb s) in
copy p1 q;
let x0 : felem s = sub p0 0ul (nlimb s) in
let z0 : felem s = sub p0 (nlimb s) (nlimb s) in
set_one x0;
set_zero z0;
let h0 = ST.get () in
assert (gsub p01 0ul (2ul *! nlimb s) == p0);
assert (gsub p01 (2ul *! nlimb s) (2ul *! nlimb s) == p1);
assert (gsub p0 0ul (nlimb s) == x0);
assert (gsub p0 (nlimb s) (nlimb s) == z0);
assert (fget_x h0 p1 == fget_x h0 q);
assert (fget_z h0 p1 == 1);
assert (fget_x h0 p0 == 1);
assert (fget_z h0 p0 == 0);
assert (
state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q) /\
state_inv_t h0 (get_x p0) /\ state_inv_t h0 (get_z p0) /\
state_inv_t h0 (get_x p1) /\ state_inv_t h0 (get_z p1))
val ladder4_:
#s:field_spec
-> k:scalar
-> q:point s
-> p01_tmp1_swap:lbuffer (limb s) (8ul *! nlimb s +! 1ul)
-> tmp2:felem_wide2 s
-> Stack unit
(requires fun h0 ->
live h0 k /\ live h0 q /\ live h0 p01_tmp1_swap /\ live h0 tmp2 /\
LowStar.Monotonic.Buffer.all_disjoint [loc k; loc q; loc p01_tmp1_swap; loc tmp2] /\
fget_z h0 q == 1 /\ state_inv_t h0 (get_x q) /\ state_inv_t h0 (get_z q))
(ensures fun h0 _ h1 ->
modifies (loc p01_tmp1_swap |+| loc tmp2) h0 h1 /\
(let nq = gsub p01_tmp1_swap 0ul (2ul *! nlimb s) in
state_inv_t h1 (get_x nq) /\ state_inv_t h1 (get_z nq) /\
fget_xz h1 nq == S.montgomery_ladder (fget_x h0 q) (as_seq h0 k)))
[@ Meta.Attribute.inline_ ]
let ladder4_ #s k q p01_tmp1_swap tmp2 =
let h0 = ST.get () in
let p01 = sub p01_tmp1_swap 0ul (4ul *! nlimb s) in
let p0 : point s = sub p01_tmp1_swap 0ul (2ul *! nlimb s) in
let p1 : point s = sub p01_tmp1_swap (2ul *! nlimb s) (2ul *! nlimb s) in
assert (gsub p01_tmp1_swap 0ul (4ul *! nlimb s) == p01);
assert (gsub p01 0ul (2ul *! nlimb s) == p0);
assert (gsub p01 (2ul *! nlimb s) (2ul *! nlimb s) == p1);
ladder3_ #s q p01;
ladder2_ #s k q p01_tmp1_swap tmp2;
let h1 = ST.get () in
assert (fget_xz h1 p0 == M.montgomery_ladder1 (fget_x h0 q) (as_seq h0 k));
M.lemma_montgomery_ladder (fget_x h0 q) (as_seq h0 k)
val montgomery_ladder:
#s:field_spec
-> o:point s
-> k:scalar
-> i:point s
-> Stack unit
(requires fun h0 ->
live h0 o /\ live h0 k /\ live h0 i /\
(disjoint o i \/ o == i) /\ disjoint o k /\ disjoint k i /\
fget_z h0 i == 1 /\ state_inv_t h0 (get_x i) /\ state_inv_t h0 (get_z i))
(ensures fun h0 _ h1 ->
modifies (loc o) h0 h1 /\
state_inv_t h1 (get_x o) /\ state_inv_t h1 (get_z o) /\
fget_xz h1 o == S.montgomery_ladder (fget_x h0 i) (as_seq h0 k)) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.AddAndDouble.fst.checked",
"Hacl.Impl.Curve25519.Finv.fst.checked",
"Hacl.Impl.Curve25519.Fields.Core.fsti.checked",
"Hacl.Impl.Curve25519.Fields.fst.checked",
"Hacl.Impl.Curve25519.AddAndDouble.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Curve25519.Generic.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.AddAndDouble",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.AddAndDouble",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Finv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"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.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": true,
"z3rlimit": 800,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
o: Hacl.Impl.Curve25519.AddAndDouble.point s ->
k: Hacl.Impl.Curve25519.Generic.scalar ->
i: Hacl.Impl.Curve25519.AddAndDouble.point s
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Curve25519.Fields.Core.field_spec",
"Hacl.Impl.Curve25519.AddAndDouble.point",
"Hacl.Impl.Curve25519.Generic.scalar",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Lib.Buffer.copy",
"Lib.Buffer.MUT",
"Hacl.Impl.Curve25519.Fields.Core.limb",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Curve25519.Fields.Core.nlimb",
"Hacl.Impl.Curve25519.Generic.ladder4_",
"Prims._assert",
"Prims.eq2",
"Lib.Buffer.buffer_t",
"Prims.l_or",
"Prims.int",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.Buffer.length",
"Lib.IntTypes.v",
"Lib.IntTypes.op_Star_Bang",
"FStar.UInt32.__uint_to_t",
"Lib.Buffer.gsub",
"Lib.Buffer.sub",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Lib.IntTypes.add",
"Lib.IntTypes.mul",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Hacl.Impl.Curve25519.Fields.Core.limb_zero",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.U128",
"FStar.UInt32.mul",
"Hacl.Impl.Curve25519.Fields.Core.wide",
"Hacl.Impl.Curve25519.Fields.Core.nwide",
"Hacl.Impl.Curve25519.Fields.Core.wide_zero",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let montgomery_ladder #s out key init =
| push_frame ();
let h0 = ST.get () in
let tmp2 = create (2ul `FStar.UInt32.mul` ((nwide s) <: FStar.UInt32.t)) (wide_zero s) in
let p01_tmp1_swap = create (8ul *! nlimb s +! 1ul) (limb_zero s) in
let p0:point s = sub p01_tmp1_swap 0ul (2ul *! nlimb s) in
assert (gsub p01_tmp1_swap 0ul (2ul *! nlimb s) == p0);
ladder4_ #s key init p01_tmp1_swap tmp2;
copy out p0;
pop_frame () | false |
FStar.Sequence.Util.fst | FStar.Sequence.Util.lemma_append_count_aux | val lemma_append_count_aux (#a: eqtype) (x: a) (lo hi: seq a)
: Lemma (ensures (count x (append lo hi) = (count x lo + count x hi))) (decreases (length lo)) | val lemma_append_count_aux (#a: eqtype) (x: a) (lo hi: seq a)
: Lemma (ensures (count x (append lo hi) = (count x lo + count x hi))) (decreases (length lo)) | let rec lemma_append_count_aux (#a:eqtype) (x:a) (lo hi:seq a)
: Lemma
(ensures (count x (append lo hi) = (count x lo + count x hi)))
(decreases (length lo))
= all_seq_facts_lemma();
reveal_opaque (`%count) (count #a);
if length lo = 0
then assert (append lo hi `equal` hi)
else (
lemma_append_count_aux x (tail lo) hi;
assert (append (tail lo) hi `equal` tail (append lo hi))
) | {
"file_name": "ulib/experimental/FStar.Sequence.Util.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 5,
"end_line": 91,
"start_col": 0,
"start_line": 80
} | (*
Copyright 2021 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.
Author: N. Swamy
*)
(** This module provides some utilities on top of FStar.Sequence *)
module FStar.Sequence.Util
open FStar.Sequence.Base
/// For convenience, we define `slice` to represent Dafny sequence slices.
let slice (#ty: Type) (s: seq ty) (i: nat) (j: nat{j >= i && j <= length s})
: seq ty
= all_seq_facts_lemma();
drop (take s j) i
let cons #a (x:a) (s:seq a) = singleton x `append` s
let head #a (s:seq a{length s > 0}) = s $@ 0
let tail #a (s:seq a{length s > 0}) = drop s 1
/// Split a sequences into a prefix and the last element
/// This is the inverse of the Sequence.build
let un_build (#a:_) (s:seq a{length s > 0})
: seq a & a
= take s (length s - 1),
s $@ (length s - 1)
let split #a (s:seq a) (i:nat{ i <= length s})
: seq a & seq a
= take s i,
drop s i
/// Counts the number of elements of `s` that
/// satisfy the predicate [f]
let rec count_matches (#a:Type) (f:a -> bool) (s:seq a)
: Tot nat (decreases (length s))
= all_seq_facts_lemma();
if length s = 0 then 0
else if f (head s) then 1 + count_matches f (tail s)
else count_matches f (tail s)
/// count_matches on an empty sequence is always zero
let count_matches_empty (a:Type) (f:a -> bool) (s:seq a{length s = 0})
: Lemma (count_matches f s = 0)
= ()
/// count is a specialization of count_matches
/// to count the number of occurrences of a given element `x` in `s`.
///
/// It is opaque to give control over its unrollings in specific proofs
[@@"opaque_to_smt"]
let count (#a:eqtype) (x:a) (s:seq a) = count_matches (fun y -> x = y) s
/// A specializtion of count_matches_empty
let count_empty (#a:eqtype) (s:seq a{length s = 0})
: Lemma (forall x. count x s = 0)
= reveal_opaque (`%count) (count #a)
/// The head element always occurs in a non-empty list
let count_head (#a:eqtype) (s:seq a{length s > 0})
: Lemma (count (head s) s > 0)
= reveal_opaque (`%count) (count #a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Sequence.Base.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Sequence.Util.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Sequence.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: a -> lo: FStar.Sequence.Base.seq a -> hi: FStar.Sequence.Base.seq a
-> FStar.Pervasives.Lemma
(ensures
FStar.Sequence.Util.count x (FStar.Sequence.Base.append lo hi) =
FStar.Sequence.Util.count x lo + FStar.Sequence.Util.count x hi)
(decreases FStar.Sequence.Base.length lo) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.eqtype",
"FStar.Sequence.Base.seq",
"Prims.op_Equality",
"Prims.int",
"FStar.Sequence.Base.length",
"Prims._assert",
"FStar.Sequence.Base.equal",
"FStar.Sequence.Base.append",
"Prims.bool",
"FStar.Sequence.Util.tail",
"Prims.unit",
"FStar.Sequence.Util.lemma_append_count_aux",
"FStar.Pervasives.reveal_opaque",
"Prims.nat",
"FStar.Sequence.Util.count",
"FStar.Sequence.Base.all_seq_facts_lemma",
"Prims.l_True",
"Prims.squash",
"Prims.b2t",
"Prims.op_Addition",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_append_count_aux (#a: eqtype) (x: a) (lo hi: seq a)
: Lemma (ensures (count x (append lo hi) = (count x lo + count x hi))) (decreases (length lo)) =
| all_seq_facts_lemma ();
reveal_opaque (`%count) (count #a);
if length lo = 0
then assert ((append lo hi) `equal` hi)
else
(lemma_append_count_aux x (tail lo) hi;
assert ((append (tail lo) hi) `equal` (tail (append lo hi)))) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_difference_disjoint | val lemma_difference_disjoint (l1 l2: locations)
: Lemma (ensures (!!(disjoint_locations (l1 `difference` l2) l2))) | val lemma_difference_disjoint (l1 l2: locations)
: Lemma (ensures (!!(disjoint_locations (l1 `difference` l2) l2))) | let rec lemma_difference_disjoint (l1 l2:locations) :
Lemma
(ensures (
!!(disjoint_locations (l1 `difference` l2) l2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem l2 x;
lemma_difference_disjoint xs l2 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 979,
"start_col": 0,
"start_line": 971
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux
let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
)
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at_mem (as0:list location) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_at_difference_elim (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1 s2;
lemma_unchanged_at_difference_elim xs l2 s1 s2
) else (
lemma_unchanged_at_difference_elim xs l2 s1 s2
)
let lemma_unchanged_at_sym_diff_implies_difference (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) =
lemma_unchanged_at_append (l1 `difference` l2) (l2 `difference` l1) s1 s2
let rec lemma_disjoint_location_from_locations_not_mem (locs:locations) (l:location) :
Lemma
(ensures (
!!(disjoint_location_from_locations l locs) <==>
not (L.mem l locs))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem xs l | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | l1: Vale.Transformers.Locations.locations -> l2: Vale.Transformers.Locations.locations
-> FStar.Pervasives.Lemma
(ensures
!!(Vale.Transformers.Locations.disjoint_locations (Vale.Transformers.BoundedInstructionEffects.difference
l1
l2)
l2)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.Transformers.Locations.location",
"Prims.list",
"Vale.Transformers.BoundedInstructionEffects.lemma_difference_disjoint",
"Prims.unit",
"Vale.Transformers.BoundedInstructionEffects.lemma_disjoint_location_from_locations_not_mem",
"Prims.l_True",
"Prims.squash",
"Prims.b2t",
"Vale.Def.PossiblyMonad.op_Bang_Bang",
"Vale.Transformers.Locations.disjoint_locations",
"Vale.Transformers.BoundedInstructionEffects.difference",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_difference_disjoint (l1 l2: locations)
: Lemma (ensures (!!(disjoint_locations (l1 `difference` l2) l2))) =
| match l1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem l2 x;
lemma_difference_disjoint xs l2 | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_bounded_effects_parallel_aux1 | val lemma_bounded_effects_parallel_aux1 (rw1 rw2 f1 f2 s1 s2: _)
: Lemma
(requires
(let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\ (bounded_effects rw2 f2) /\ (s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\ (run f1 s2).ms_ok /\ unchanged_at rw.loc_reads s1 s2))
(ensures
(let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) | val lemma_bounded_effects_parallel_aux1 (rw1 rw2 f1 f2 s1 s2: _)
: Lemma
(requires
(let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\ (bounded_effects rw2 f2) /\ (s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\ (run f1 s2).ms_ok /\ unchanged_at rw.loc_reads s1 s2))
(ensures
(let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) | let lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\
(run f1 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw1.loc_reads s1 s2);
assert (unchanged_at rw1.loc_writes (run f1 s1) (run f1 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw2.loc_writes `difference` rw1.loc_writes) rw1.loc_writes s1 (run f1 s1) s2 (run f1 s2);
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) (run f1 s1) (run f1 s2));
lemma_unchanged_at_difference_elim rw2.loc_writes rw1.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw2.loc_writes (run f1 s1) (run f1 s2)) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 1033,
"start_col": 0,
"start_line": 1010
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux
let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
)
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at_mem (as0:list location) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_at_difference_elim (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1 s2;
lemma_unchanged_at_difference_elim xs l2 s1 s2
) else (
lemma_unchanged_at_difference_elim xs l2 s1 s2
)
let lemma_unchanged_at_sym_diff_implies_difference (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) =
lemma_unchanged_at_append (l1 `difference` l2) (l2 `difference` l1) s1 s2
let rec lemma_disjoint_location_from_locations_not_mem (locs:locations) (l:location) :
Lemma
(ensures (
!!(disjoint_location_from_locations l locs) <==>
not (L.mem l locs))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem xs l
let rec lemma_difference_disjoint (l1 l2:locations) :
Lemma
(ensures (
!!(disjoint_locations (l1 `difference` l2) l2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem l2 x;
lemma_difference_disjoint xs l2
let rec lemma_unchanged_except_to_at_difference (locs locs_change:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except locs_change s1 s2))
(ensures (unchanged_at (locs `difference` locs_change) s1 s2)) =
match locs with
| [] -> ()
| x :: xs ->
lemma_difference_disjoint locs locs_change;
lemma_unchanged_except_to_at_difference xs locs_change s1 s2
let rec lemma_unchanged_at_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(unchanged_at locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at locs_change s1' s2')))
(ensures (
(unchanged_at locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
rw1: Vale.Transformers.BoundedInstructionEffects.rw_set ->
rw2: Vale.Transformers.BoundedInstructionEffects.rw_set ->
f1: Vale.X64.Machine_Semantics_s.st Prims.unit ->
f2: Vale.X64.Machine_Semantics_s.st Prims.unit ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
(let rw = Vale.Transformers.BoundedInstructionEffects.rw_set_in_parallel rw1 rw2 in
Vale.Transformers.BoundedInstructionEffects.bounded_effects rw1 f1 /\
Vale.Transformers.BoundedInstructionEffects.bounded_effects rw2 f2 /\
Mkmachine_state?.ms_ok s1 = Mkmachine_state?.ms_ok s2 /\
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run f1 s1) /\
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run f1 s2) /\
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Mkrw_set?.loc_reads rw) s1 s2))
(ensures
(let rw = Vale.Transformers.BoundedInstructionEffects.rw_set_in_parallel rw1 rw2 in
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Mkrw_set?.loc_writes rw)
(Vale.X64.Machine_Semantics_s.run f1 s1)
(Vale.X64.Machine_Semantics_s.run f1 s2))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.BoundedInstructionEffects.rw_set",
"Vale.X64.Machine_Semantics_s.st",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims._assert",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"Vale.X64.Machine_Semantics_s.run",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_difference_elim",
"Vale.Transformers.BoundedInstructionEffects.difference",
"Vale.Transformers.Locations.location",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_maintained",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_sym_diff_implies_difference",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_reads",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_append",
"Vale.Transformers.BoundedInstructionEffects.sym_difference",
"FStar.List.Tot.Base.append",
"Prims.l_and",
"Vale.Transformers.BoundedInstructionEffects.bounded_effects",
"Prims.b2t",
"Prims.op_Equality",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.Transformers.BoundedInstructionEffects.rw_set_in_parallel",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2
: Lemma
(requires
(let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\ (bounded_effects rw2 f2) /\ (s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\ (run f1 s2).ms_ok /\ unchanged_at rw.loc_reads s1 s2))
(ensures
(let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
| lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes)
(rw1.loc_reads `L.append` rw2.loc_reads)
s1
s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw1.loc_reads s1 s2);
assert (unchanged_at rw1.loc_writes (run f1 s1) (run f1 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw2.loc_writes `difference` rw1.loc_writes)
rw1.loc_writes
s1
(run f1 s1)
s2
(run f1 s2);
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) (run f1 s1) (run f1 s2));
lemma_unchanged_at_difference_elim rw2.loc_writes rw1.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw2.loc_writes (run f1 s1) (run f1 s2)) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_except_to_at_difference | val lemma_unchanged_except_to_at_difference (locs locs_change: locations) (s1 s2: machine_state)
: Lemma (requires (unchanged_except locs_change s1 s2))
(ensures (unchanged_at (locs `difference` locs_change) s1 s2)) | val lemma_unchanged_except_to_at_difference (locs locs_change: locations) (s1 s2: machine_state)
: Lemma (requires (unchanged_except locs_change s1 s2))
(ensures (unchanged_at (locs `difference` locs_change) s1 s2)) | let rec lemma_unchanged_except_to_at_difference (locs locs_change:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except locs_change s1 s2))
(ensures (unchanged_at (locs `difference` locs_change) s1 s2)) =
match locs with
| [] -> ()
| x :: xs ->
lemma_difference_disjoint locs locs_change;
lemma_unchanged_except_to_at_difference xs locs_change s1 s2 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 64,
"end_line": 989,
"start_col": 0,
"start_line": 981
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux
let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
)
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at_mem (as0:list location) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_at_difference_elim (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1 s2;
lemma_unchanged_at_difference_elim xs l2 s1 s2
) else (
lemma_unchanged_at_difference_elim xs l2 s1 s2
)
let lemma_unchanged_at_sym_diff_implies_difference (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) =
lemma_unchanged_at_append (l1 `difference` l2) (l2 `difference` l1) s1 s2
let rec lemma_disjoint_location_from_locations_not_mem (locs:locations) (l:location) :
Lemma
(ensures (
!!(disjoint_location_from_locations l locs) <==>
not (L.mem l locs))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem xs l
let rec lemma_difference_disjoint (l1 l2:locations) :
Lemma
(ensures (
!!(disjoint_locations (l1 `difference` l2) l2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem l2 x;
lemma_difference_disjoint xs l2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
locs: Vale.Transformers.Locations.locations ->
locs_change: Vale.Transformers.Locations.locations ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires Vale.Transformers.BoundedInstructionEffects.unchanged_except locs_change s1 s2)
(ensures
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Vale.Transformers.BoundedInstructionEffects.difference
locs
locs_change)
s1
s2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.Locations.location",
"Prims.list",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_except_to_at_difference",
"Prims.unit",
"Vale.Transformers.BoundedInstructionEffects.lemma_difference_disjoint",
"Vale.Transformers.BoundedInstructionEffects.unchanged_except",
"Prims.squash",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.Transformers.BoundedInstructionEffects.difference",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_unchanged_except_to_at_difference (locs locs_change: locations) (s1 s2: machine_state)
: Lemma (requires (unchanged_except locs_change s1 s2))
(ensures (unchanged_at (locs `difference` locs_change) s1 s2)) =
| match locs with
| [] -> ()
| x :: xs ->
lemma_difference_disjoint locs locs_change;
lemma_unchanged_except_to_at_difference xs locs_change s1 s2 | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_disjoint_location_from_locations_not_mem | val lemma_disjoint_location_from_locations_not_mem (locs: locations) (l: location)
: Lemma (ensures (!!(disjoint_location_from_locations l locs) <==> not (L.mem l locs))) | val lemma_disjoint_location_from_locations_not_mem (locs: locations) (l: location)
: Lemma (ensures (!!(disjoint_location_from_locations l locs) <==> not (L.mem l locs))) | let rec lemma_disjoint_location_from_locations_not_mem (locs:locations) (l:location) :
Lemma
(ensures (
!!(disjoint_location_from_locations l locs) <==>
not (L.mem l locs))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem xs l | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 969,
"start_col": 0,
"start_line": 961
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux
let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
)
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at_mem (as0:list location) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_at_difference_elim (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1 s2;
lemma_unchanged_at_difference_elim xs l2 s1 s2
) else (
lemma_unchanged_at_difference_elim xs l2 s1 s2
)
let lemma_unchanged_at_sym_diff_implies_difference (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) =
lemma_unchanged_at_append (l1 `difference` l2) (l2 `difference` l1) s1 s2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | locs: Vale.Transformers.Locations.locations -> l: Vale.Transformers.Locations.location
-> FStar.Pervasives.Lemma
(ensures
!!(Vale.Transformers.Locations.disjoint_location_from_locations l locs) <==>
Prims.op_Negation (FStar.List.Tot.Base.mem l locs)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.Transformers.Locations.location",
"Prims.list",
"Vale.Transformers.BoundedInstructionEffects.lemma_disjoint_location_from_locations_not_mem",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_iff",
"Prims.b2t",
"Vale.Def.PossiblyMonad.op_Bang_Bang",
"Vale.Transformers.Locations.disjoint_location_from_locations",
"Prims.op_Negation",
"FStar.List.Tot.Base.mem",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_disjoint_location_from_locations_not_mem (locs: locations) (l: location)
: Lemma (ensures (!!(disjoint_location_from_locations l locs) <==> not (L.mem l locs))) =
| match locs with
| [] -> ()
| x :: xs -> lemma_disjoint_location_from_locations_not_mem xs l | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_maintained | val lemma_unchanged_at_maintained (locs locs_change: locations) (s1 s1' s2 s2': machine_state)
: Lemma
(requires
((unchanged_at locs s1 s2) /\ (unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\ (unchanged_at locs_change s1' s2')))
(ensures ((unchanged_at locs s1' s2'))) | val lemma_unchanged_at_maintained (locs locs_change: locations) (s1 s1' s2 s2': machine_state)
: Lemma
(requires
((unchanged_at locs s1 s2) /\ (unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\ (unchanged_at locs_change s1' s2')))
(ensures ((unchanged_at locs s1' s2'))) | let rec lemma_unchanged_at_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(unchanged_at locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at locs_change s1' s2')))
(ensures (
(unchanged_at locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 1008,
"start_col": 0,
"start_line": 991
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux
let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
)
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at_mem (as0:list location) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_at_difference_elim (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1 s2;
lemma_unchanged_at_difference_elim xs l2 s1 s2
) else (
lemma_unchanged_at_difference_elim xs l2 s1 s2
)
let lemma_unchanged_at_sym_diff_implies_difference (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) =
lemma_unchanged_at_append (l1 `difference` l2) (l2 `difference` l1) s1 s2
let rec lemma_disjoint_location_from_locations_not_mem (locs:locations) (l:location) :
Lemma
(ensures (
!!(disjoint_location_from_locations l locs) <==>
not (L.mem l locs))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem xs l
let rec lemma_difference_disjoint (l1 l2:locations) :
Lemma
(ensures (
!!(disjoint_locations (l1 `difference` l2) l2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem l2 x;
lemma_difference_disjoint xs l2
let rec lemma_unchanged_except_to_at_difference (locs locs_change:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except locs_change s1 s2))
(ensures (unchanged_at (locs `difference` locs_change) s1 s2)) =
match locs with
| [] -> ()
| x :: xs ->
lemma_difference_disjoint locs locs_change;
lemma_unchanged_except_to_at_difference xs locs_change s1 s2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
locs: Vale.Transformers.Locations.locations ->
locs_change: Vale.Transformers.Locations.locations ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s1': Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state ->
s2': Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
Vale.Transformers.BoundedInstructionEffects.unchanged_at locs s1 s2 /\
Vale.Transformers.BoundedInstructionEffects.unchanged_except locs_change s1 s1' /\
Vale.Transformers.BoundedInstructionEffects.unchanged_except locs_change s2 s2' /\
Vale.Transformers.BoundedInstructionEffects.unchanged_at locs_change s1' s2')
(ensures Vale.Transformers.BoundedInstructionEffects.unchanged_at locs s1' s2') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.Locations.location",
"Prims.list",
"FStar.List.Tot.Base.mem",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_mem",
"Prims.bool",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_except_not_mem",
"Prims.unit",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_maintained",
"Prims.l_and",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.Transformers.BoundedInstructionEffects.unchanged_except",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_unchanged_at_maintained (locs locs_change: locations) (s1 s1' s2 s2': machine_state)
: Lemma
(requires
((unchanged_at locs s1 s2) /\ (unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\ (unchanged_at locs_change s1' s2')))
(ensures ((unchanged_at locs s1' s2'))) =
| match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change
then (lemma_unchanged_at_mem locs_change x s1' s2')
else (lemma_unchanged_except_not_mem locs_change x) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_bounded_effects_series_aux1 | val lemma_bounded_effects_series_aux1 (rw1 rw2 f1 f2 s a: _)
: Lemma
(requires
(let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\ (bounded_effects rw2 f2) /\
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run (let* _ = f1 in
f2)
s)
.ms_ok))
(ensures
(let open Vale.X64.Machine_Semantics_s in
eval_location a s ==
eval_location a
(run (let* _ = f1 in
f2)
s))) | val lemma_bounded_effects_series_aux1 (rw1 rw2 f1 f2 s a: _)
: Lemma
(requires
(let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\ (bounded_effects rw2 f2) /\
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run (let* _ = f1 in
f2)
s)
.ms_ok))
(ensures
(let open Vale.X64.Machine_Semantics_s in
eval_location a s ==
eval_location a
(run (let* _ = f1 in
f2)
s))) | let lemma_bounded_effects_series_aux1 rw1 rw2 f1 f2 s a :
Lemma
(requires (
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run (f1 ;* f2) s).ms_ok))
(ensures (
let open Vale.X64.Machine_Semantics_s in
eval_location a s == eval_location a (run (f1;*f2) s))) =
let open Vale.X64.Machine_Semantics_s in
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw1.loc_writes s (run f1 s));
assert (eval_location a s == eval_location a (run f1 s));
assert (unchanged_except rw2.loc_writes (run f1 s) (run f2 (run f1 s)));
assert (eval_location a s == eval_location a (run (f1;*f2) s)) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 64,
"end_line": 1198,
"start_col": 0,
"start_line": 1181
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux
let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
)
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at_mem (as0:list location) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_at_difference_elim (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1 s2;
lemma_unchanged_at_difference_elim xs l2 s1 s2
) else (
lemma_unchanged_at_difference_elim xs l2 s1 s2
)
let lemma_unchanged_at_sym_diff_implies_difference (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) =
lemma_unchanged_at_append (l1 `difference` l2) (l2 `difference` l1) s1 s2
let rec lemma_disjoint_location_from_locations_not_mem (locs:locations) (l:location) :
Lemma
(ensures (
!!(disjoint_location_from_locations l locs) <==>
not (L.mem l locs))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem xs l
let rec lemma_difference_disjoint (l1 l2:locations) :
Lemma
(ensures (
!!(disjoint_locations (l1 `difference` l2) l2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem l2 x;
lemma_difference_disjoint xs l2
let rec lemma_unchanged_except_to_at_difference (locs locs_change:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except locs_change s1 s2))
(ensures (unchanged_at (locs `difference` locs_change) s1 s2)) =
match locs with
| [] -> ()
| x :: xs ->
lemma_difference_disjoint locs locs_change;
lemma_unchanged_except_to_at_difference xs locs_change s1 s2
let rec lemma_unchanged_at_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(unchanged_at locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at locs_change s1' s2')))
(ensures (
(unchanged_at locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\
(run f1 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw1.loc_reads s1 s2);
assert (unchanged_at rw1.loc_writes (run f1 s1) (run f1 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw2.loc_writes `difference` rw1.loc_writes) rw1.loc_writes s1 (run f1 s1) s2 (run f1 s2);
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) (run f1 s1) (run f1 s2));
lemma_unchanged_at_difference_elim rw2.loc_writes rw1.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw2.loc_writes (run f1 s1) (run f1 s2))
let lemma_bounded_effects_parallel_aux2 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\
(run f2 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw2.loc_reads s1 s2);
assert (unchanged_at rw2.loc_writes (run f2 s1) (run f2 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw1.loc_writes `difference` rw2.loc_writes) rw2.loc_writes s1 (run f2 s1) s2 (run f2 s2);
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) (run f2 s1) (run f2 s2));
lemma_unchanged_at_difference_elim rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw1.loc_writes (run f2 s1) (run f2 s2))
(* See fsti *)
let lemma_bounded_effects_parallel rw1 rw2 f1 f2 =
let rw = rw_set_in_parallel rw1 rw2 in
let aux s a :
Lemma
(requires (
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run f1 s).ms_ok))
(ensures (eval_location a s == eval_location a (run f1 s))) =
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw1.loc_writes s (run f1 s)) (* OBSERVE *)
in
let aux s = FStar.Classical.move_requires (aux s) in
FStar.Classical.forall_intro_2 aux;
let aux s a :
Lemma
(requires (
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run f2 s).ms_ok))
(ensures (eval_location a s == eval_location a (run f2 s))) =
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw2.loc_writes s (run f2 s)) (* OBSERVE *)
in
let aux s = FStar.Classical.move_requires (aux s) in
FStar.Classical.forall_intro_2 aux;
assert (only_affects rw.loc_writes f1);
assert (only_affects rw.loc_writes f2);
let rec aux c1 c2 s :
Lemma
(requires (constant_on_execution c1 f1 s /\ constant_on_execution c2 f2 s))
(ensures (constant_on_execution (c1 `intersect` c2) f1 s)) =
match c1 with
| [] -> ()
| x :: xs ->
aux xs c2 s
in
let aux = FStar.Classical.move_requires (aux rw1.loc_constant_writes rw2.loc_constant_writes) in
FStar.Classical.forall_intro aux;
let rec aux c1 c2 s :
Lemma
(requires (constant_on_execution c1 f1 s /\ constant_on_execution c2 f2 s))
(ensures (constant_on_execution (c1 `intersect` c2) f2 s)) =
match c1 with
| [] -> ()
| x :: xs ->
aux xs c2 s;
if (run f2 s).ms_ok && x `L.mem` c2 then (
lemma_constant_on_execution_mem c2 f2 s (dfst x) (dsnd x)
) else ()
in
let aux = FStar.Classical.move_requires (aux rw1.loc_constant_writes rw2.loc_constant_writes) in
FStar.Classical.forall_intro aux;
assert (forall s. constant_on_execution rw.loc_constant_writes f1 s);
assert (forall s. constant_on_execution rw.loc_constant_writes f2 s);
let aux l v :
Lemma
(L.mem (|l,v|) rw.loc_constant_writes ==> L.mem l rw.loc_writes) =
FStar.Classical.arrow_to_impl #(L.mem (|l,v|) rw.loc_constant_writes) #(L.mem l rw.loc_writes)
(fun _ -> lemma_constant_intersect_belongs_to_writes_union
rw1.loc_constant_writes rw2.loc_constant_writes rw1.loc_writes rw2.loc_writes l v)
in
FStar.Classical.forall_intro_2 aux;
assert (forall l v. L.mem (|l,v|) rw.loc_constant_writes ==> L.mem l rw.loc_writes);
let aux s1 s2 :
Lemma
(requires (s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2))
(ensures (
((run f1 s1).ms_ok = (run f1 s2).ms_ok) /\
((run f2 s1).ms_ok = (run f2 s2).ms_ok))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 s2 :
Lemma
(requires ((s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\
(run f1 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 s2 :
Lemma
(requires ((s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\
(run f2 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) =
lemma_bounded_effects_parallel_aux2 rw1 rw2 f1 f2 s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
assert (
forall s1 s2. (
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2) ==> (
((run f1 s1).ms_ok = (run f1 s2).ms_ok) /\
((run f1 s1).ms_ok ==>
unchanged_at rw.loc_writes (run f1 s1) (run f1 s2))
)
)
);
assert (
forall s1 s2. (
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2) ==> (
((run f2 s1).ms_ok = (run f2 s2).ms_ok) /\
((run f2 s1).ms_ok ==>
unchanged_at rw.loc_writes (run f2 s1) (run f2 s2))
)
)
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
rw1: Vale.Transformers.BoundedInstructionEffects.rw_set ->
rw2: Vale.Transformers.BoundedInstructionEffects.rw_set ->
f1: Vale.X64.Machine_Semantics_s.st Prims.unit ->
f2: Vale.X64.Machine_Semantics_s.st Prims.unit ->
s: Vale.X64.Machine_Semantics_s.machine_state ->
a: Vale.Transformers.Locations.location
-> FStar.Pervasives.Lemma
(requires
(let rw = Vale.Transformers.BoundedInstructionEffects.rw_set_in_series rw1 rw2 in
Vale.Transformers.BoundedInstructionEffects.bounded_effects rw1 f1 /\
Vale.Transformers.BoundedInstructionEffects.bounded_effects rw2 f2 /\
!!(Vale.Transformers.Locations.disjoint_location_from_locations a
(Mkrw_set?.loc_writes rw)) /\
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run (( let* ) f1 (fun _ -> f2)) s)))
(ensures
Vale.Transformers.Locations.eval_location a s ==
Vale.Transformers.Locations.eval_location a
(Vale.X64.Machine_Semantics_s.run (( let* ) f1 (fun _ -> f2)) s)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.BoundedInstructionEffects.rw_set",
"Vale.X64.Machine_Semantics_s.st",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.Locations.location",
"Prims._assert",
"Prims.eq2",
"Vale.Transformers.Locations.location_val_t",
"Vale.Transformers.Locations.eval_location",
"Vale.X64.Machine_Semantics_s.run",
"Vale.X64.Machine_Semantics_s.op_let_Star",
"Vale.Transformers.BoundedInstructionEffects.unchanged_except",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"Vale.Transformers.BoundedInstructionEffects.lemma_disjoint_location_from_locations_append",
"Prims.l_and",
"Vale.Transformers.BoundedInstructionEffects.bounded_effects",
"Prims.b2t",
"Vale.Def.PossiblyMonad.op_Bang_Bang",
"Vale.Transformers.Locations.disjoint_location_from_locations",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.Transformers.BoundedInstructionEffects.rw_set_in_series",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_bounded_effects_series_aux1 rw1 rw2 f1 f2 s a
: Lemma
(requires
(let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\ (bounded_effects rw2 f2) /\
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run (let* _ = f1 in
f2)
s)
.ms_ok))
(ensures
(let open Vale.X64.Machine_Semantics_s in
eval_location a s ==
eval_location a
(run (let* _ = f1 in
f2)
s))) =
| let open Vale.X64.Machine_Semantics_s in
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw1.loc_writes s (run f1 s));
assert (eval_location a s == eval_location a (run f1 s));
assert (unchanged_except rw2.loc_writes (run f1 s) (run f2 (run f1 s)));
assert (eval_location a s ==
eval_location a
(run (let* _ = f1 in
f2)
s)) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_except_disjoint | val lemma_unchanged_at_except_disjoint (same change: locations) (s1 s2 s1' s2': machine_state)
: Lemma
(requires
((unchanged_at same s1 s2) /\ (unchanged_except change s1 s1') /\
(unchanged_except change s2 s2') /\ !!(disjoint_locations same change)))
(ensures ((unchanged_at same s1' s2'))) | val lemma_unchanged_at_except_disjoint (same change: locations) (s1 s2 s1' s2': machine_state)
: Lemma
(requires
((unchanged_at same s1 s2) /\ (unchanged_except change s1 s1') /\
(unchanged_except change s2 s2') /\ !!(disjoint_locations same change)))
(ensures ((unchanged_at same s1' s2'))) | let rec lemma_unchanged_at_except_disjoint (same change:locations) (s1 s2 s1' s2':machine_state) :
Lemma
(requires (
(unchanged_at same s1 s2) /\
(unchanged_except change s1 s1') /\
(unchanged_except change s2 s2') /\
!!(disjoint_locations same change)))
(ensures (
(unchanged_at same s1' s2'))) =
match same with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_except_disjoint xs change s1 s2 s1' s2' | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 1235,
"start_col": 0,
"start_line": 1223
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux
let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
)
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at_mem (as0:list location) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_at_difference_elim (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1 s2;
lemma_unchanged_at_difference_elim xs l2 s1 s2
) else (
lemma_unchanged_at_difference_elim xs l2 s1 s2
)
let lemma_unchanged_at_sym_diff_implies_difference (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) =
lemma_unchanged_at_append (l1 `difference` l2) (l2 `difference` l1) s1 s2
let rec lemma_disjoint_location_from_locations_not_mem (locs:locations) (l:location) :
Lemma
(ensures (
!!(disjoint_location_from_locations l locs) <==>
not (L.mem l locs))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem xs l
let rec lemma_difference_disjoint (l1 l2:locations) :
Lemma
(ensures (
!!(disjoint_locations (l1 `difference` l2) l2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem l2 x;
lemma_difference_disjoint xs l2
let rec lemma_unchanged_except_to_at_difference (locs locs_change:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except locs_change s1 s2))
(ensures (unchanged_at (locs `difference` locs_change) s1 s2)) =
match locs with
| [] -> ()
| x :: xs ->
lemma_difference_disjoint locs locs_change;
lemma_unchanged_except_to_at_difference xs locs_change s1 s2
let rec lemma_unchanged_at_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(unchanged_at locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at locs_change s1' s2')))
(ensures (
(unchanged_at locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\
(run f1 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw1.loc_reads s1 s2);
assert (unchanged_at rw1.loc_writes (run f1 s1) (run f1 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw2.loc_writes `difference` rw1.loc_writes) rw1.loc_writes s1 (run f1 s1) s2 (run f1 s2);
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) (run f1 s1) (run f1 s2));
lemma_unchanged_at_difference_elim rw2.loc_writes rw1.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw2.loc_writes (run f1 s1) (run f1 s2))
let lemma_bounded_effects_parallel_aux2 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\
(run f2 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw2.loc_reads s1 s2);
assert (unchanged_at rw2.loc_writes (run f2 s1) (run f2 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw1.loc_writes `difference` rw2.loc_writes) rw2.loc_writes s1 (run f2 s1) s2 (run f2 s2);
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) (run f2 s1) (run f2 s2));
lemma_unchanged_at_difference_elim rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw1.loc_writes (run f2 s1) (run f2 s2))
(* See fsti *)
let lemma_bounded_effects_parallel rw1 rw2 f1 f2 =
let rw = rw_set_in_parallel rw1 rw2 in
let aux s a :
Lemma
(requires (
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run f1 s).ms_ok))
(ensures (eval_location a s == eval_location a (run f1 s))) =
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw1.loc_writes s (run f1 s)) (* OBSERVE *)
in
let aux s = FStar.Classical.move_requires (aux s) in
FStar.Classical.forall_intro_2 aux;
let aux s a :
Lemma
(requires (
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run f2 s).ms_ok))
(ensures (eval_location a s == eval_location a (run f2 s))) =
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw2.loc_writes s (run f2 s)) (* OBSERVE *)
in
let aux s = FStar.Classical.move_requires (aux s) in
FStar.Classical.forall_intro_2 aux;
assert (only_affects rw.loc_writes f1);
assert (only_affects rw.loc_writes f2);
let rec aux c1 c2 s :
Lemma
(requires (constant_on_execution c1 f1 s /\ constant_on_execution c2 f2 s))
(ensures (constant_on_execution (c1 `intersect` c2) f1 s)) =
match c1 with
| [] -> ()
| x :: xs ->
aux xs c2 s
in
let aux = FStar.Classical.move_requires (aux rw1.loc_constant_writes rw2.loc_constant_writes) in
FStar.Classical.forall_intro aux;
let rec aux c1 c2 s :
Lemma
(requires (constant_on_execution c1 f1 s /\ constant_on_execution c2 f2 s))
(ensures (constant_on_execution (c1 `intersect` c2) f2 s)) =
match c1 with
| [] -> ()
| x :: xs ->
aux xs c2 s;
if (run f2 s).ms_ok && x `L.mem` c2 then (
lemma_constant_on_execution_mem c2 f2 s (dfst x) (dsnd x)
) else ()
in
let aux = FStar.Classical.move_requires (aux rw1.loc_constant_writes rw2.loc_constant_writes) in
FStar.Classical.forall_intro aux;
assert (forall s. constant_on_execution rw.loc_constant_writes f1 s);
assert (forall s. constant_on_execution rw.loc_constant_writes f2 s);
let aux l v :
Lemma
(L.mem (|l,v|) rw.loc_constant_writes ==> L.mem l rw.loc_writes) =
FStar.Classical.arrow_to_impl #(L.mem (|l,v|) rw.loc_constant_writes) #(L.mem l rw.loc_writes)
(fun _ -> lemma_constant_intersect_belongs_to_writes_union
rw1.loc_constant_writes rw2.loc_constant_writes rw1.loc_writes rw2.loc_writes l v)
in
FStar.Classical.forall_intro_2 aux;
assert (forall l v. L.mem (|l,v|) rw.loc_constant_writes ==> L.mem l rw.loc_writes);
let aux s1 s2 :
Lemma
(requires (s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2))
(ensures (
((run f1 s1).ms_ok = (run f1 s2).ms_ok) /\
((run f2 s1).ms_ok = (run f2 s2).ms_ok))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 s2 :
Lemma
(requires ((s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\
(run f1 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 s2 :
Lemma
(requires ((s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\
(run f2 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) =
lemma_bounded_effects_parallel_aux2 rw1 rw2 f1 f2 s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
assert (
forall s1 s2. (
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2) ==> (
((run f1 s1).ms_ok = (run f1 s2).ms_ok) /\
((run f1 s1).ms_ok ==>
unchanged_at rw.loc_writes (run f1 s1) (run f1 s2))
)
)
);
assert (
forall s1 s2. (
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2) ==> (
((run f2 s1).ms_ok = (run f2 s2).ms_ok) /\
((run f2 s1).ms_ok ==>
unchanged_at rw.loc_writes (run f2 s1) (run f2 s2))
)
)
)
let lemma_bounded_effects_series_aux1 rw1 rw2 f1 f2 s a :
Lemma
(requires (
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run (f1 ;* f2) s).ms_ok))
(ensures (
let open Vale.X64.Machine_Semantics_s in
eval_location a s == eval_location a (run (f1;*f2) s))) =
let open Vale.X64.Machine_Semantics_s in
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw1.loc_writes s (run f1 s));
assert (eval_location a s == eval_location a (run f1 s));
assert (unchanged_except rw2.loc_writes (run f1 s) (run f2 (run f1 s)));
assert (eval_location a s == eval_location a (run (f1;*f2) s))
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_bounded_effects_series_aux2 c1 c2 f1 f2 s :
Lemma
(requires (
(forall s. {:pattern (constant_on_execution c1 f1 s)} (constant_on_execution c1 f1 s)) /\
(forall s. {:pattern (constant_on_execution c2 f2 s)} (constant_on_execution c2 f2 s))))
(ensures (
let open Vale.X64.Machine_Semantics_s in
(constant_on_execution (c1 `intersect` c2) (f1;*f2) s))) =
let open Vale.X64.Machine_Semantics_s in
let f = f1;*f2 in
if (run f s).ms_ok then (
match c1 with
| [] -> ()
| (|l,v|) :: xs ->
if L.mem (|l,v|) c2 then (
lemma_constant_on_execution_mem c2 f2 (run f1 s) l v
) else ();
assert (forall s. constant_on_execution c1 f1 s ==> constant_on_execution xs f1 s); (* OBSERVE *)
lemma_bounded_effects_series_aux2 xs c2 f1 f2 s
) else ()
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
same: Vale.Transformers.Locations.locations ->
change: Vale.Transformers.Locations.locations ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state ->
s1': Vale.X64.Machine_Semantics_s.machine_state ->
s2': Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
Vale.Transformers.BoundedInstructionEffects.unchanged_at same s1 s2 /\
Vale.Transformers.BoundedInstructionEffects.unchanged_except change s1 s1' /\
Vale.Transformers.BoundedInstructionEffects.unchanged_except change s2 s2' /\
!!(Vale.Transformers.Locations.disjoint_locations same change))
(ensures Vale.Transformers.BoundedInstructionEffects.unchanged_at same s1' s2') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.Locations.location",
"Prims.list",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_except_disjoint",
"Prims.unit",
"Prims.l_and",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.Transformers.BoundedInstructionEffects.unchanged_except",
"Prims.b2t",
"Vale.Def.PossiblyMonad.op_Bang_Bang",
"Vale.Transformers.Locations.disjoint_locations",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_unchanged_at_except_disjoint (same change: locations) (s1 s2 s1' s2': machine_state)
: Lemma
(requires
((unchanged_at same s1 s2) /\ (unchanged_except change s1 s1') /\
(unchanged_except change s2 s2') /\ !!(disjoint_locations same change)))
(ensures ((unchanged_at same s1' s2'))) =
| match same with
| [] -> ()
| x :: xs -> lemma_unchanged_at_except_disjoint xs change s1 s2 s1' s2' | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_bounded_effects_series_aux4 | val lemma_bounded_effects_series_aux4 (rw1 rw2 f1 f2 s1 s2: _)
: Lemma
(requires
(let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\ (bounded_effects rw2 f2) /\ (s1.ms_ok = s2.ms_ok) /\
(run (let* _ = f1 in
f2)
s1)
.ms_ok /\
(run (let* _ = f1 in
f2)
s2)
.ms_ok /\ (unchanged_at rw.loc_reads s1 s2)))
(ensures
(let open Vale.X64.Machine_Semantics_s in
let f =
let* _ = f1 in
f2
in
let rw = rw_set_in_series rw1 rw2 in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) | val lemma_bounded_effects_series_aux4 (rw1 rw2 f1 f2 s1 s2: _)
: Lemma
(requires
(let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\ (bounded_effects rw2 f2) /\ (s1.ms_ok = s2.ms_ok) /\
(run (let* _ = f1 in
f2)
s1)
.ms_ok /\
(run (let* _ = f1 in
f2)
s2)
.ms_ok /\ (unchanged_at rw.loc_reads s1 s2)))
(ensures
(let open Vale.X64.Machine_Semantics_s in
let f =
let* _ = f1 in
f2
in
let rw = rw_set_in_series rw1 rw2 in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) | let lemma_bounded_effects_series_aux4 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run (f1;*f2) s1).ms_ok /\
(run (f1;*f2) s2).ms_ok /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let open Vale.X64.Machine_Semantics_s in
let f = f1;*f2 in
let rw = rw_set_in_series rw1 rw2 in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
let f = (f1;*f2) in
let s1_1, s2_1 = run f1 s1, run f1 s2 in
let s1_1_2, s2_1_2 = run f2 s1_1, run f2 s2_1 in
lemma_unchanged_at_append rw1.loc_reads (rw2.loc_reads `difference` rw1.loc_writes) s1 s2;
assert (s1_1.ms_ok /\ s2_1.ms_ok);
assert (s1_1_2.ms_ok /\ s2_1_2.ms_ok);
assert (unchanged_except rw1.loc_writes s1 s1_1);
assert (unchanged_except rw1.loc_writes s2 s2_1);
assert (unchanged_at (rw2.loc_reads `difference` rw1.loc_writes) s1 s2);
lemma_difference_disjoint rw2.loc_reads rw1.loc_writes;
lemma_unchanged_at_except_disjoint (rw2.loc_reads `difference` rw1.loc_writes) rw1.loc_writes s1 s2 s1_1 s2_1;
lemma_unchanged_at_difference_elim rw2.loc_reads rw1.loc_writes s1_1 s2_1;
assert (unchanged_at rw1.loc_writes s1_1 s2_1);
assert (unchanged_except rw2.loc_writes s1_1 s1_1_2);
assert (unchanged_except rw2.loc_writes s2_1 s2_1_2);
assert (unchanged_at rw2.loc_writes s1_1_2 s2_1_2);
lemma_unchanged_at_extend_append rw1.loc_writes rw2.loc_writes s1_1 s2_1 s1_1_2 s2_1_2 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 88,
"end_line": 1320,
"start_col": 0,
"start_line": 1286
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux
let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
)
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at_mem (as0:list location) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_at_difference_elim (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1 s2;
lemma_unchanged_at_difference_elim xs l2 s1 s2
) else (
lemma_unchanged_at_difference_elim xs l2 s1 s2
)
let lemma_unchanged_at_sym_diff_implies_difference (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) =
lemma_unchanged_at_append (l1 `difference` l2) (l2 `difference` l1) s1 s2
let rec lemma_disjoint_location_from_locations_not_mem (locs:locations) (l:location) :
Lemma
(ensures (
!!(disjoint_location_from_locations l locs) <==>
not (L.mem l locs))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem xs l
let rec lemma_difference_disjoint (l1 l2:locations) :
Lemma
(ensures (
!!(disjoint_locations (l1 `difference` l2) l2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem l2 x;
lemma_difference_disjoint xs l2
let rec lemma_unchanged_except_to_at_difference (locs locs_change:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except locs_change s1 s2))
(ensures (unchanged_at (locs `difference` locs_change) s1 s2)) =
match locs with
| [] -> ()
| x :: xs ->
lemma_difference_disjoint locs locs_change;
lemma_unchanged_except_to_at_difference xs locs_change s1 s2
let rec lemma_unchanged_at_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(unchanged_at locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at locs_change s1' s2')))
(ensures (
(unchanged_at locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\
(run f1 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw1.loc_reads s1 s2);
assert (unchanged_at rw1.loc_writes (run f1 s1) (run f1 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw2.loc_writes `difference` rw1.loc_writes) rw1.loc_writes s1 (run f1 s1) s2 (run f1 s2);
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) (run f1 s1) (run f1 s2));
lemma_unchanged_at_difference_elim rw2.loc_writes rw1.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw2.loc_writes (run f1 s1) (run f1 s2))
let lemma_bounded_effects_parallel_aux2 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\
(run f2 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw2.loc_reads s1 s2);
assert (unchanged_at rw2.loc_writes (run f2 s1) (run f2 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw1.loc_writes `difference` rw2.loc_writes) rw2.loc_writes s1 (run f2 s1) s2 (run f2 s2);
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) (run f2 s1) (run f2 s2));
lemma_unchanged_at_difference_elim rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw1.loc_writes (run f2 s1) (run f2 s2))
(* See fsti *)
let lemma_bounded_effects_parallel rw1 rw2 f1 f2 =
let rw = rw_set_in_parallel rw1 rw2 in
let aux s a :
Lemma
(requires (
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run f1 s).ms_ok))
(ensures (eval_location a s == eval_location a (run f1 s))) =
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw1.loc_writes s (run f1 s)) (* OBSERVE *)
in
let aux s = FStar.Classical.move_requires (aux s) in
FStar.Classical.forall_intro_2 aux;
let aux s a :
Lemma
(requires (
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run f2 s).ms_ok))
(ensures (eval_location a s == eval_location a (run f2 s))) =
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw2.loc_writes s (run f2 s)) (* OBSERVE *)
in
let aux s = FStar.Classical.move_requires (aux s) in
FStar.Classical.forall_intro_2 aux;
assert (only_affects rw.loc_writes f1);
assert (only_affects rw.loc_writes f2);
let rec aux c1 c2 s :
Lemma
(requires (constant_on_execution c1 f1 s /\ constant_on_execution c2 f2 s))
(ensures (constant_on_execution (c1 `intersect` c2) f1 s)) =
match c1 with
| [] -> ()
| x :: xs ->
aux xs c2 s
in
let aux = FStar.Classical.move_requires (aux rw1.loc_constant_writes rw2.loc_constant_writes) in
FStar.Classical.forall_intro aux;
let rec aux c1 c2 s :
Lemma
(requires (constant_on_execution c1 f1 s /\ constant_on_execution c2 f2 s))
(ensures (constant_on_execution (c1 `intersect` c2) f2 s)) =
match c1 with
| [] -> ()
| x :: xs ->
aux xs c2 s;
if (run f2 s).ms_ok && x `L.mem` c2 then (
lemma_constant_on_execution_mem c2 f2 s (dfst x) (dsnd x)
) else ()
in
let aux = FStar.Classical.move_requires (aux rw1.loc_constant_writes rw2.loc_constant_writes) in
FStar.Classical.forall_intro aux;
assert (forall s. constant_on_execution rw.loc_constant_writes f1 s);
assert (forall s. constant_on_execution rw.loc_constant_writes f2 s);
let aux l v :
Lemma
(L.mem (|l,v|) rw.loc_constant_writes ==> L.mem l rw.loc_writes) =
FStar.Classical.arrow_to_impl #(L.mem (|l,v|) rw.loc_constant_writes) #(L.mem l rw.loc_writes)
(fun _ -> lemma_constant_intersect_belongs_to_writes_union
rw1.loc_constant_writes rw2.loc_constant_writes rw1.loc_writes rw2.loc_writes l v)
in
FStar.Classical.forall_intro_2 aux;
assert (forall l v. L.mem (|l,v|) rw.loc_constant_writes ==> L.mem l rw.loc_writes);
let aux s1 s2 :
Lemma
(requires (s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2))
(ensures (
((run f1 s1).ms_ok = (run f1 s2).ms_ok) /\
((run f2 s1).ms_ok = (run f2 s2).ms_ok))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 s2 :
Lemma
(requires ((s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\
(run f1 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 s2 :
Lemma
(requires ((s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\
(run f2 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) =
lemma_bounded_effects_parallel_aux2 rw1 rw2 f1 f2 s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
assert (
forall s1 s2. (
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2) ==> (
((run f1 s1).ms_ok = (run f1 s2).ms_ok) /\
((run f1 s1).ms_ok ==>
unchanged_at rw.loc_writes (run f1 s1) (run f1 s2))
)
)
);
assert (
forall s1 s2. (
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2) ==> (
((run f2 s1).ms_ok = (run f2 s2).ms_ok) /\
((run f2 s1).ms_ok ==>
unchanged_at rw.loc_writes (run f2 s1) (run f2 s2))
)
)
)
let lemma_bounded_effects_series_aux1 rw1 rw2 f1 f2 s a :
Lemma
(requires (
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run (f1 ;* f2) s).ms_ok))
(ensures (
let open Vale.X64.Machine_Semantics_s in
eval_location a s == eval_location a (run (f1;*f2) s))) =
let open Vale.X64.Machine_Semantics_s in
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw1.loc_writes s (run f1 s));
assert (eval_location a s == eval_location a (run f1 s));
assert (unchanged_except rw2.loc_writes (run f1 s) (run f2 (run f1 s)));
assert (eval_location a s == eval_location a (run (f1;*f2) s))
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_bounded_effects_series_aux2 c1 c2 f1 f2 s :
Lemma
(requires (
(forall s. {:pattern (constant_on_execution c1 f1 s)} (constant_on_execution c1 f1 s)) /\
(forall s. {:pattern (constant_on_execution c2 f2 s)} (constant_on_execution c2 f2 s))))
(ensures (
let open Vale.X64.Machine_Semantics_s in
(constant_on_execution (c1 `intersect` c2) (f1;*f2) s))) =
let open Vale.X64.Machine_Semantics_s in
let f = f1;*f2 in
if (run f s).ms_ok then (
match c1 with
| [] -> ()
| (|l,v|) :: xs ->
if L.mem (|l,v|) c2 then (
lemma_constant_on_execution_mem c2 f2 (run f1 s) l v
) else ();
assert (forall s. constant_on_execution c1 f1 s ==> constant_on_execution xs f1 s); (* OBSERVE *)
lemma_bounded_effects_series_aux2 xs c2 f1 f2 s
) else ()
#pop-options
let rec lemma_unchanged_at_except_disjoint (same change:locations) (s1 s2 s1' s2':machine_state) :
Lemma
(requires (
(unchanged_at same s1 s2) /\
(unchanged_except change s1 s1') /\
(unchanged_except change s2 s2') /\
!!(disjoint_locations same change)))
(ensures (
(unchanged_at same s1' s2'))) =
match same with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_except_disjoint xs change s1 s2 s1' s2'
let lemma_bounded_effects_series_aux3 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let open Vale.X64.Machine_Semantics_s in
let f = f1;*f2 in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
let f = (f1;*f2) in
let s1_1, s2_1 = run f1 s1, run f1 s2 in
let s1_1_2, s2_1_2 = run f2 s1_1, run f2 s2_1 in
lemma_unchanged_at_append rw1.loc_reads (rw2.loc_reads `difference` rw1.loc_writes) s1 s2;
assert (s1_1.ms_ok = s2_1.ms_ok);
if s1_1.ms_ok then (
assert (only_affects rw1.loc_writes f1);
assert (unchanged_except rw1.loc_writes s1 s1_1);
assert (unchanged_except rw1.loc_writes s2 s2_1);
assert (unchanged_at (rw2.loc_reads `difference` rw1.loc_writes) s1 s2);
lemma_difference_disjoint rw2.loc_reads rw1.loc_writes;
lemma_unchanged_at_except_disjoint (rw2.loc_reads `difference` rw1.loc_writes) rw1.loc_writes s1 s2 s1_1 s2_1;
lemma_unchanged_at_difference_elim rw2.loc_reads rw1.loc_writes s1_1 s2_1
) else ()
let rec lemma_unchanged_at_extend_append (l1 l2:locations) (s1 s2 s1' s2':machine_state):
Lemma
(requires (
(unchanged_at l1 s1 s2) /\
(unchanged_except l2 s1 s1') /\
(unchanged_except l2 s2 s2') /\
(unchanged_at l2 s1' s2')))
(ensures (
(unchanged_at (l1 `L.append` l2) s1' s2'))) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1' s2'
) else (
lemma_unchanged_except_not_mem l2 x
);
lemma_unchanged_at_extend_append xs l2 s1 s2 s1' s2' | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
rw1: Vale.Transformers.BoundedInstructionEffects.rw_set ->
rw2: Vale.Transformers.BoundedInstructionEffects.rw_set ->
f1: Vale.X64.Machine_Semantics_s.st Prims.unit ->
f2: Vale.X64.Machine_Semantics_s.st Prims.unit ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
(let rw = Vale.Transformers.BoundedInstructionEffects.rw_set_in_series rw1 rw2 in
Vale.Transformers.BoundedInstructionEffects.bounded_effects rw1 f1 /\
Vale.Transformers.BoundedInstructionEffects.bounded_effects rw2 f2 /\
Mkmachine_state?.ms_ok s1 = Mkmachine_state?.ms_ok s2 /\
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run (( let* ) f1 (fun _ -> f2)) s1) /\
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run (( let* ) f1 (fun _ -> f2)) s2) /\
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Mkrw_set?.loc_reads rw) s1 s2))
(ensures
(let f = ( let* ) f1 (fun _ -> f2) in
let rw = Vale.Transformers.BoundedInstructionEffects.rw_set_in_series rw1 rw2 in
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Mkrw_set?.loc_writes rw)
(Vale.X64.Machine_Semantics_s.run f s1)
(Vale.X64.Machine_Semantics_s.run f s2))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.BoundedInstructionEffects.rw_set",
"Vale.X64.Machine_Semantics_s.st",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_extend_append",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"Prims._assert",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.Transformers.BoundedInstructionEffects.unchanged_except",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_difference_elim",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_reads",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_except_disjoint",
"Vale.Transformers.BoundedInstructionEffects.difference",
"Vale.Transformers.Locations.location",
"Vale.Transformers.BoundedInstructionEffects.lemma_difference_disjoint",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_append",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Vale.X64.Machine_Semantics_s.run",
"Vale.X64.Machine_Semantics_s.op_let_Star",
"Vale.Transformers.BoundedInstructionEffects.rw_set_in_series",
"Vale.Transformers.BoundedInstructionEffects.bounded_effects",
"Prims.op_Equality",
"Prims.bool",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_bounded_effects_series_aux4 rw1 rw2 f1 f2 s1 s2
: Lemma
(requires
(let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\ (bounded_effects rw2 f2) /\ (s1.ms_ok = s2.ms_ok) /\
(run (let* _ = f1 in
f2)
s1)
.ms_ok /\
(run (let* _ = f1 in
f2)
s2)
.ms_ok /\ (unchanged_at rw.loc_reads s1 s2)))
(ensures
(let open Vale.X64.Machine_Semantics_s in
let f =
let* _ = f1 in
f2
in
let rw = rw_set_in_series rw1 rw2 in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
| let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
let f =
(let* _ = f1 in
f2)
in
let s1_1, s2_1 = run f1 s1, run f1 s2 in
let s1_1_2, s2_1_2 = run f2 s1_1, run f2 s2_1 in
lemma_unchanged_at_append rw1.loc_reads (rw2.loc_reads `difference` rw1.loc_writes) s1 s2;
assert (s1_1.ms_ok /\ s2_1.ms_ok);
assert (s1_1_2.ms_ok /\ s2_1_2.ms_ok);
assert (unchanged_except rw1.loc_writes s1 s1_1);
assert (unchanged_except rw1.loc_writes s2 s2_1);
assert (unchanged_at (rw2.loc_reads `difference` rw1.loc_writes) s1 s2);
lemma_difference_disjoint rw2.loc_reads rw1.loc_writes;
lemma_unchanged_at_except_disjoint (rw2.loc_reads `difference` rw1.loc_writes)
rw1.loc_writes
s1
s2
s1_1
s2_1;
lemma_unchanged_at_difference_elim rw2.loc_reads rw1.loc_writes s1_1 s2_1;
assert (unchanged_at rw1.loc_writes s1_1 s2_1);
assert (unchanged_except rw2.loc_writes s1_1 s1_1_2);
assert (unchanged_except rw2.loc_writes s2_1 s2_1_2);
assert (unchanged_at rw2.loc_writes s1_1_2 s2_1_2);
lemma_unchanged_at_extend_append rw1.loc_writes rw2.loc_writes s1_1 s2_1 s1_1_2 s2_1_2 | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_bounded_effects_parallel_aux2 | val lemma_bounded_effects_parallel_aux2 (rw1 rw2 f1 f2 s1 s2: _)
: Lemma
(requires
(let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\ (bounded_effects rw2 f2) /\ (s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\ (run f2 s2).ms_ok /\ unchanged_at rw.loc_reads s1 s2))
(ensures
(let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) | val lemma_bounded_effects_parallel_aux2 (rw1 rw2 f1 f2 s1 s2: _)
: Lemma
(requires
(let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\ (bounded_effects rw2 f2) /\ (s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\ (run f2 s2).ms_ok /\ unchanged_at rw.loc_reads s1 s2))
(ensures
(let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) | let lemma_bounded_effects_parallel_aux2 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\
(run f2 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw2.loc_reads s1 s2);
assert (unchanged_at rw2.loc_writes (run f2 s1) (run f2 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw1.loc_writes `difference` rw2.loc_writes) rw2.loc_writes s1 (run f2 s1) s2 (run f2 s2);
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) (run f2 s1) (run f2 s2));
lemma_unchanged_at_difference_elim rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw1.loc_writes (run f2 s1) (run f2 s2)) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 1058,
"start_col": 0,
"start_line": 1035
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux
let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
)
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at_mem (as0:list location) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_at_difference_elim (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1 s2;
lemma_unchanged_at_difference_elim xs l2 s1 s2
) else (
lemma_unchanged_at_difference_elim xs l2 s1 s2
)
let lemma_unchanged_at_sym_diff_implies_difference (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) =
lemma_unchanged_at_append (l1 `difference` l2) (l2 `difference` l1) s1 s2
let rec lemma_disjoint_location_from_locations_not_mem (locs:locations) (l:location) :
Lemma
(ensures (
!!(disjoint_location_from_locations l locs) <==>
not (L.mem l locs))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem xs l
let rec lemma_difference_disjoint (l1 l2:locations) :
Lemma
(ensures (
!!(disjoint_locations (l1 `difference` l2) l2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem l2 x;
lemma_difference_disjoint xs l2
let rec lemma_unchanged_except_to_at_difference (locs locs_change:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except locs_change s1 s2))
(ensures (unchanged_at (locs `difference` locs_change) s1 s2)) =
match locs with
| [] -> ()
| x :: xs ->
lemma_difference_disjoint locs locs_change;
lemma_unchanged_except_to_at_difference xs locs_change s1 s2
let rec lemma_unchanged_at_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(unchanged_at locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at locs_change s1' s2')))
(ensures (
(unchanged_at locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\
(run f1 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw1.loc_reads s1 s2);
assert (unchanged_at rw1.loc_writes (run f1 s1) (run f1 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw2.loc_writes `difference` rw1.loc_writes) rw1.loc_writes s1 (run f1 s1) s2 (run f1 s2);
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) (run f1 s1) (run f1 s2));
lemma_unchanged_at_difference_elim rw2.loc_writes rw1.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw2.loc_writes (run f1 s1) (run f1 s2)) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
rw1: Vale.Transformers.BoundedInstructionEffects.rw_set ->
rw2: Vale.Transformers.BoundedInstructionEffects.rw_set ->
f1: Vale.X64.Machine_Semantics_s.st Prims.unit ->
f2: Vale.X64.Machine_Semantics_s.st Prims.unit ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
(let rw = Vale.Transformers.BoundedInstructionEffects.rw_set_in_parallel rw1 rw2 in
Vale.Transformers.BoundedInstructionEffects.bounded_effects rw1 f1 /\
Vale.Transformers.BoundedInstructionEffects.bounded_effects rw2 f2 /\
Mkmachine_state?.ms_ok s1 = Mkmachine_state?.ms_ok s2 /\
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run f2 s1) /\
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run f2 s2) /\
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Mkrw_set?.loc_reads rw) s1 s2))
(ensures
(let rw = Vale.Transformers.BoundedInstructionEffects.rw_set_in_parallel rw1 rw2 in
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Mkrw_set?.loc_writes rw)
(Vale.X64.Machine_Semantics_s.run f2 s1)
(Vale.X64.Machine_Semantics_s.run f2 s2))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.BoundedInstructionEffects.rw_set",
"Vale.X64.Machine_Semantics_s.st",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims._assert",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"Vale.X64.Machine_Semantics_s.run",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_difference_elim",
"Vale.Transformers.BoundedInstructionEffects.difference",
"Vale.Transformers.Locations.location",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_maintained",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_sym_diff_implies_difference",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_reads",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_append",
"Vale.Transformers.BoundedInstructionEffects.sym_difference",
"FStar.List.Tot.Base.append",
"Prims.l_and",
"Vale.Transformers.BoundedInstructionEffects.bounded_effects",
"Prims.b2t",
"Prims.op_Equality",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.Transformers.BoundedInstructionEffects.rw_set_in_parallel",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_bounded_effects_parallel_aux2 rw1 rw2 f1 f2 s1 s2
: Lemma
(requires
(let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\ (bounded_effects rw2 f2) /\ (s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\ (run f2 s2).ms_ok /\ unchanged_at rw.loc_reads s1 s2))
(ensures
(let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) =
| lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes)
(rw1.loc_reads `L.append` rw2.loc_reads)
s1
s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw2.loc_reads s1 s2);
assert (unchanged_at rw2.loc_writes (run f2 s1) (run f2 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw1.loc_writes `difference` rw2.loc_writes)
rw2.loc_writes
s1
(run f2 s1)
s2
(run f2 s2);
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) (run f2 s1) (run f2 s2));
lemma_unchanged_at_difference_elim rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw1.loc_writes (run f2 s1) (run f2 s2)) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_constant_intersect_belongs_to_writes_union | val lemma_constant_intersect_belongs_to_writes_union
(c1 c2: locations_with_values)
(w1 w2: locations)
(l: location_eq)
(v: location_val_eqt l)
: Lemma
(requires
((let x:location_with_value = (| l, v |) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (| l, v |) c1); (L.mem l w1)}
L.mem (| l, v |) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (| l, v |) c2); (L.mem l w2)}
L.mem (| l, v |) c2 ==> L.mem l w2)))) (ensures (L.mem l (w1 `L.append` w2))) | val lemma_constant_intersect_belongs_to_writes_union
(c1 c2: locations_with_values)
(w1 w2: locations)
(l: location_eq)
(v: location_val_eqt l)
: Lemma
(requires
((let x:location_with_value = (| l, v |) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (| l, v |) c1); (L.mem l w1)}
L.mem (| l, v |) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (| l, v |) c2); (L.mem l w2)}
L.mem (| l, v |) c2 ==> L.mem l w2)))) (ensures (L.mem l (w1 `L.append` w2))) | let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
) | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 924,
"start_col": 0,
"start_line": 903
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
c1: Vale.Transformers.BoundedInstructionEffects.locations_with_values ->
c2: Vale.Transformers.BoundedInstructionEffects.locations_with_values ->
w1: Vale.Transformers.Locations.locations ->
w2: Vale.Transformers.Locations.locations ->
l: Vale.Transformers.Locations.location_eq ->
v: Vale.Transformers.Locations.location_val_eqt l
-> FStar.Pervasives.Lemma
(requires
(let x = (| l, v |) in
FStar.List.Tot.Base.mem x (Vale.Transformers.BoundedInstructionEffects.intersect c1 c2) /\
(forall (l:
Vale.Transformers.Locations.location
{ Vale.Transformers.Locations.location_val_t l ==
FStar.Universe.raise_t (Vale.Transformers.Locations.location_val_eqt l) })
(v: Vale.Transformers.Locations.location_val_eqt l).
{:pattern FStar.List.Tot.Base.mem (| l, v |) c1; FStar.List.Tot.Base.mem l w1}
FStar.List.Tot.Base.mem (| l, v |) c1 ==> FStar.List.Tot.Base.mem l w1) /\
(forall (l:
Vale.Transformers.Locations.location
{ Vale.Transformers.Locations.location_val_t l ==
FStar.Universe.raise_t (Vale.Transformers.Locations.location_val_eqt l) })
(v: Vale.Transformers.Locations.location_val_eqt l).
{:pattern FStar.List.Tot.Base.mem (| l, v |) c2; FStar.List.Tot.Base.mem l w2}
FStar.List.Tot.Base.mem (| l, v |) c2 ==> FStar.List.Tot.Base.mem l w2)))
(ensures FStar.List.Tot.Base.mem l (w1 @ w2)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.BoundedInstructionEffects.locations_with_values",
"Vale.Transformers.Locations.locations",
"Vale.Transformers.Locations.location_eq",
"Vale.Transformers.Locations.location_val_eqt",
"Vale.Transformers.BoundedInstructionEffects.location_with_value",
"Prims.list",
"Prims.op_Equality",
"Prims.dtuple2",
"Prims.Mkdtuple2",
"FStar.List.Tot.Properties.append_mem",
"Vale.Transformers.Locations.location",
"Prims.unit",
"Prims._assert",
"Prims.b2t",
"FStar.List.Tot.Base.mem",
"Prims.bool",
"Vale.Transformers.BoundedInstructionEffects.lemma_constant_intersect_belongs_to_writes_union",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_and",
"Vale.Transformers.BoundedInstructionEffects.intersect",
"Prims.eq2",
"Vale.Transformers.Locations.location_val_t",
"FStar.Universe.raise_t",
"Prims.squash",
"FStar.List.Tot.Base.append",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2: locations_with_values)
(w1 w2: locations)
(l: location_eq)
(v: location_val_eqt l)
: Lemma
(requires
((let x:location_with_value = (| l, v |) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (| l, v |) c1); (L.mem l w1)}
L.mem (| l, v |) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (| l, v |) c2); (L.mem l w2)}
L.mem (| l, v |) c2 ==> L.mem l w2)))) (ensures (L.mem l (w1 `L.append` w2))) =
| match c1 with
| [] -> ()
| x :: xs ->
if x = (| l, v |)
then
(assert (L.mem (| l, v |) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l)
else
(assert (forall l v. L.mem (| l, v |) xs ==> L.mem (| l, v |) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_bounded_effects_series_aux3 | val lemma_bounded_effects_series_aux3 (rw1 rw2 f1 f2 s1 s2: _)
: Lemma
(requires
(let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\ (bounded_effects rw2 f2) /\ (s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures
(let open Vale.X64.Machine_Semantics_s in
let f =
let* _ = f1 in
f2
in
(run f s1).ms_ok = (run f s2).ms_ok)) | val lemma_bounded_effects_series_aux3 (rw1 rw2 f1 f2 s1 s2: _)
: Lemma
(requires
(let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\ (bounded_effects rw2 f2) /\ (s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures
(let open Vale.X64.Machine_Semantics_s in
let f =
let* _ = f1 in
f2
in
(run f s1).ms_ok = (run f s2).ms_ok)) | let lemma_bounded_effects_series_aux3 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let open Vale.X64.Machine_Semantics_s in
let f = f1;*f2 in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
let f = (f1;*f2) in
let s1_1, s2_1 = run f1 s1, run f1 s2 in
let s1_1_2, s2_1_2 = run f2 s1_1, run f2 s2_1 in
lemma_unchanged_at_append rw1.loc_reads (rw2.loc_reads `difference` rw1.loc_writes) s1 s2;
assert (s1_1.ms_ok = s2_1.ms_ok);
if s1_1.ms_ok then (
assert (only_affects rw1.loc_writes f1);
assert (unchanged_except rw1.loc_writes s1 s1_1);
assert (unchanged_except rw1.loc_writes s2 s2_1);
assert (unchanged_at (rw2.loc_reads `difference` rw1.loc_writes) s1 s2);
lemma_difference_disjoint rw2.loc_reads rw1.loc_writes;
lemma_unchanged_at_except_disjoint (rw2.loc_reads `difference` rw1.loc_writes) rw1.loc_writes s1 s2 s1_1 s2_1;
lemma_unchanged_at_difference_elim rw2.loc_reads rw1.loc_writes s1_1 s2_1
) else () | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 1265,
"start_col": 0,
"start_line": 1237
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux
let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
)
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at_mem (as0:list location) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_at_difference_elim (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1 s2;
lemma_unchanged_at_difference_elim xs l2 s1 s2
) else (
lemma_unchanged_at_difference_elim xs l2 s1 s2
)
let lemma_unchanged_at_sym_diff_implies_difference (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) =
lemma_unchanged_at_append (l1 `difference` l2) (l2 `difference` l1) s1 s2
let rec lemma_disjoint_location_from_locations_not_mem (locs:locations) (l:location) :
Lemma
(ensures (
!!(disjoint_location_from_locations l locs) <==>
not (L.mem l locs))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem xs l
let rec lemma_difference_disjoint (l1 l2:locations) :
Lemma
(ensures (
!!(disjoint_locations (l1 `difference` l2) l2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem l2 x;
lemma_difference_disjoint xs l2
let rec lemma_unchanged_except_to_at_difference (locs locs_change:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except locs_change s1 s2))
(ensures (unchanged_at (locs `difference` locs_change) s1 s2)) =
match locs with
| [] -> ()
| x :: xs ->
lemma_difference_disjoint locs locs_change;
lemma_unchanged_except_to_at_difference xs locs_change s1 s2
let rec lemma_unchanged_at_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(unchanged_at locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at locs_change s1' s2')))
(ensures (
(unchanged_at locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\
(run f1 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw1.loc_reads s1 s2);
assert (unchanged_at rw1.loc_writes (run f1 s1) (run f1 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw2.loc_writes `difference` rw1.loc_writes) rw1.loc_writes s1 (run f1 s1) s2 (run f1 s2);
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) (run f1 s1) (run f1 s2));
lemma_unchanged_at_difference_elim rw2.loc_writes rw1.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw2.loc_writes (run f1 s1) (run f1 s2))
let lemma_bounded_effects_parallel_aux2 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\
(run f2 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw2.loc_reads s1 s2);
assert (unchanged_at rw2.loc_writes (run f2 s1) (run f2 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw1.loc_writes `difference` rw2.loc_writes) rw2.loc_writes s1 (run f2 s1) s2 (run f2 s2);
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) (run f2 s1) (run f2 s2));
lemma_unchanged_at_difference_elim rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw1.loc_writes (run f2 s1) (run f2 s2))
(* See fsti *)
let lemma_bounded_effects_parallel rw1 rw2 f1 f2 =
let rw = rw_set_in_parallel rw1 rw2 in
let aux s a :
Lemma
(requires (
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run f1 s).ms_ok))
(ensures (eval_location a s == eval_location a (run f1 s))) =
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw1.loc_writes s (run f1 s)) (* OBSERVE *)
in
let aux s = FStar.Classical.move_requires (aux s) in
FStar.Classical.forall_intro_2 aux;
let aux s a :
Lemma
(requires (
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run f2 s).ms_ok))
(ensures (eval_location a s == eval_location a (run f2 s))) =
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw2.loc_writes s (run f2 s)) (* OBSERVE *)
in
let aux s = FStar.Classical.move_requires (aux s) in
FStar.Classical.forall_intro_2 aux;
assert (only_affects rw.loc_writes f1);
assert (only_affects rw.loc_writes f2);
let rec aux c1 c2 s :
Lemma
(requires (constant_on_execution c1 f1 s /\ constant_on_execution c2 f2 s))
(ensures (constant_on_execution (c1 `intersect` c2) f1 s)) =
match c1 with
| [] -> ()
| x :: xs ->
aux xs c2 s
in
let aux = FStar.Classical.move_requires (aux rw1.loc_constant_writes rw2.loc_constant_writes) in
FStar.Classical.forall_intro aux;
let rec aux c1 c2 s :
Lemma
(requires (constant_on_execution c1 f1 s /\ constant_on_execution c2 f2 s))
(ensures (constant_on_execution (c1 `intersect` c2) f2 s)) =
match c1 with
| [] -> ()
| x :: xs ->
aux xs c2 s;
if (run f2 s).ms_ok && x `L.mem` c2 then (
lemma_constant_on_execution_mem c2 f2 s (dfst x) (dsnd x)
) else ()
in
let aux = FStar.Classical.move_requires (aux rw1.loc_constant_writes rw2.loc_constant_writes) in
FStar.Classical.forall_intro aux;
assert (forall s. constant_on_execution rw.loc_constant_writes f1 s);
assert (forall s. constant_on_execution rw.loc_constant_writes f2 s);
let aux l v :
Lemma
(L.mem (|l,v|) rw.loc_constant_writes ==> L.mem l rw.loc_writes) =
FStar.Classical.arrow_to_impl #(L.mem (|l,v|) rw.loc_constant_writes) #(L.mem l rw.loc_writes)
(fun _ -> lemma_constant_intersect_belongs_to_writes_union
rw1.loc_constant_writes rw2.loc_constant_writes rw1.loc_writes rw2.loc_writes l v)
in
FStar.Classical.forall_intro_2 aux;
assert (forall l v. L.mem (|l,v|) rw.loc_constant_writes ==> L.mem l rw.loc_writes);
let aux s1 s2 :
Lemma
(requires (s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2))
(ensures (
((run f1 s1).ms_ok = (run f1 s2).ms_ok) /\
((run f2 s1).ms_ok = (run f2 s2).ms_ok))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 s2 :
Lemma
(requires ((s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\
(run f1 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 s2 :
Lemma
(requires ((s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\
(run f2 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) =
lemma_bounded_effects_parallel_aux2 rw1 rw2 f1 f2 s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
assert (
forall s1 s2. (
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2) ==> (
((run f1 s1).ms_ok = (run f1 s2).ms_ok) /\
((run f1 s1).ms_ok ==>
unchanged_at rw.loc_writes (run f1 s1) (run f1 s2))
)
)
);
assert (
forall s1 s2. (
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2) ==> (
((run f2 s1).ms_ok = (run f2 s2).ms_ok) /\
((run f2 s1).ms_ok ==>
unchanged_at rw.loc_writes (run f2 s1) (run f2 s2))
)
)
)
let lemma_bounded_effects_series_aux1 rw1 rw2 f1 f2 s a :
Lemma
(requires (
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run (f1 ;* f2) s).ms_ok))
(ensures (
let open Vale.X64.Machine_Semantics_s in
eval_location a s == eval_location a (run (f1;*f2) s))) =
let open Vale.X64.Machine_Semantics_s in
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw1.loc_writes s (run f1 s));
assert (eval_location a s == eval_location a (run f1 s));
assert (unchanged_except rw2.loc_writes (run f1 s) (run f2 (run f1 s)));
assert (eval_location a s == eval_location a (run (f1;*f2) s))
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_bounded_effects_series_aux2 c1 c2 f1 f2 s :
Lemma
(requires (
(forall s. {:pattern (constant_on_execution c1 f1 s)} (constant_on_execution c1 f1 s)) /\
(forall s. {:pattern (constant_on_execution c2 f2 s)} (constant_on_execution c2 f2 s))))
(ensures (
let open Vale.X64.Machine_Semantics_s in
(constant_on_execution (c1 `intersect` c2) (f1;*f2) s))) =
let open Vale.X64.Machine_Semantics_s in
let f = f1;*f2 in
if (run f s).ms_ok then (
match c1 with
| [] -> ()
| (|l,v|) :: xs ->
if L.mem (|l,v|) c2 then (
lemma_constant_on_execution_mem c2 f2 (run f1 s) l v
) else ();
assert (forall s. constant_on_execution c1 f1 s ==> constant_on_execution xs f1 s); (* OBSERVE *)
lemma_bounded_effects_series_aux2 xs c2 f1 f2 s
) else ()
#pop-options
let rec lemma_unchanged_at_except_disjoint (same change:locations) (s1 s2 s1' s2':machine_state) :
Lemma
(requires (
(unchanged_at same s1 s2) /\
(unchanged_except change s1 s1') /\
(unchanged_except change s2 s2') /\
!!(disjoint_locations same change)))
(ensures (
(unchanged_at same s1' s2'))) =
match same with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_except_disjoint xs change s1 s2 s1' s2' | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
rw1: Vale.Transformers.BoundedInstructionEffects.rw_set ->
rw2: Vale.Transformers.BoundedInstructionEffects.rw_set ->
f1: Vale.X64.Machine_Semantics_s.st Prims.unit ->
f2: Vale.X64.Machine_Semantics_s.st Prims.unit ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
(let rw = Vale.Transformers.BoundedInstructionEffects.rw_set_in_series rw1 rw2 in
Vale.Transformers.BoundedInstructionEffects.bounded_effects rw1 f1 /\
Vale.Transformers.BoundedInstructionEffects.bounded_effects rw2 f2 /\
Mkmachine_state?.ms_ok s1 = Mkmachine_state?.ms_ok s2 /\
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Mkrw_set?.loc_reads rw) s1 s2))
(ensures
(let f = ( let* ) f1 (fun _ -> f2) in
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run f s1) =
Mkmachine_state?.ms_ok (Vale.X64.Machine_Semantics_s.run f s2))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.BoundedInstructionEffects.rw_set",
"Vale.X64.Machine_Semantics_s.st",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_difference_elim",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_reads",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_except_disjoint",
"Vale.Transformers.BoundedInstructionEffects.difference",
"Vale.Transformers.Locations.location",
"Vale.Transformers.BoundedInstructionEffects.lemma_difference_disjoint",
"Prims._assert",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.Transformers.BoundedInstructionEffects.unchanged_except",
"Vale.Transformers.BoundedInstructionEffects.only_affects",
"Prims.bool",
"Prims.b2t",
"Prims.op_Equality",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_append",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Vale.X64.Machine_Semantics_s.run",
"Vale.X64.Machine_Semantics_s.op_let_Star",
"Vale.Transformers.BoundedInstructionEffects.rw_set_in_series",
"Prims.l_and",
"Vale.Transformers.BoundedInstructionEffects.bounded_effects",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_bounded_effects_series_aux3 rw1 rw2 f1 f2 s1 s2
: Lemma
(requires
(let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\ (bounded_effects rw2 f2) /\ (s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures
(let open Vale.X64.Machine_Semantics_s in
let f =
let* _ = f1 in
f2
in
(run f s1).ms_ok = (run f s2).ms_ok)) =
| let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
let f =
(let* _ = f1 in
f2)
in
let s1_1, s2_1 = run f1 s1, run f1 s2 in
let s1_1_2, s2_1_2 = run f2 s1_1, run f2 s2_1 in
lemma_unchanged_at_append rw1.loc_reads (rw2.loc_reads `difference` rw1.loc_writes) s1 s2;
assert (s1_1.ms_ok = s2_1.ms_ok);
if s1_1.ms_ok
then
(assert (only_affects rw1.loc_writes f1);
assert (unchanged_except rw1.loc_writes s1 s1_1);
assert (unchanged_except rw1.loc_writes s2 s2_1);
assert (unchanged_at (rw2.loc_reads `difference` rw1.loc_writes) s1 s2);
lemma_difference_disjoint rw2.loc_reads rw1.loc_writes;
lemma_unchanged_at_except_disjoint (rw2.loc_reads `difference` rw1.loc_writes)
rw1.loc_writes
s1
s2
s1_1
s2_1;
lemma_unchanged_at_difference_elim rw2.loc_reads rw1.loc_writes s1_1 s2_1) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_bounded_effects_series_aux2 | val lemma_bounded_effects_series_aux2 (c1 c2 f1 f2 s: _)
: Lemma
(requires
((forall s. {:pattern (constant_on_execution c1 f1 s)} (constant_on_execution c1 f1 s)) /\
(forall s. {:pattern (constant_on_execution c2 f2 s)} (constant_on_execution c2 f2 s))))
(ensures
(let open Vale.X64.Machine_Semantics_s in
(constant_on_execution (c1 `intersect` c2)
(let* _ = f1 in
f2)
s))) | val lemma_bounded_effects_series_aux2 (c1 c2 f1 f2 s: _)
: Lemma
(requires
((forall s. {:pattern (constant_on_execution c1 f1 s)} (constant_on_execution c1 f1 s)) /\
(forall s. {:pattern (constant_on_execution c2 f2 s)} (constant_on_execution c2 f2 s))))
(ensures
(let open Vale.X64.Machine_Semantics_s in
(constant_on_execution (c1 `intersect` c2)
(let* _ = f1 in
f2)
s))) | let rec lemma_bounded_effects_series_aux2 c1 c2 f1 f2 s :
Lemma
(requires (
(forall s. {:pattern (constant_on_execution c1 f1 s)} (constant_on_execution c1 f1 s)) /\
(forall s. {:pattern (constant_on_execution c2 f2 s)} (constant_on_execution c2 f2 s))))
(ensures (
let open Vale.X64.Machine_Semantics_s in
(constant_on_execution (c1 `intersect` c2) (f1;*f2) s))) =
let open Vale.X64.Machine_Semantics_s in
let f = f1;*f2 in
if (run f s).ms_ok then (
match c1 with
| [] -> ()
| (|l,v|) :: xs ->
if L.mem (|l,v|) c2 then (
lemma_constant_on_execution_mem c2 f2 (run f1 s) l v
) else ();
assert (forall s. constant_on_execution c1 f1 s ==> constant_on_execution xs f1 s); (* OBSERVE *)
lemma_bounded_effects_series_aux2 xs c2 f1 f2 s
) else () | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 1220,
"start_col": 0,
"start_line": 1201
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux
let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
)
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at_mem (as0:list location) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_at_difference_elim (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1 s2;
lemma_unchanged_at_difference_elim xs l2 s1 s2
) else (
lemma_unchanged_at_difference_elim xs l2 s1 s2
)
let lemma_unchanged_at_sym_diff_implies_difference (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) =
lemma_unchanged_at_append (l1 `difference` l2) (l2 `difference` l1) s1 s2
let rec lemma_disjoint_location_from_locations_not_mem (locs:locations) (l:location) :
Lemma
(ensures (
!!(disjoint_location_from_locations l locs) <==>
not (L.mem l locs))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem xs l
let rec lemma_difference_disjoint (l1 l2:locations) :
Lemma
(ensures (
!!(disjoint_locations (l1 `difference` l2) l2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem l2 x;
lemma_difference_disjoint xs l2
let rec lemma_unchanged_except_to_at_difference (locs locs_change:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except locs_change s1 s2))
(ensures (unchanged_at (locs `difference` locs_change) s1 s2)) =
match locs with
| [] -> ()
| x :: xs ->
lemma_difference_disjoint locs locs_change;
lemma_unchanged_except_to_at_difference xs locs_change s1 s2
let rec lemma_unchanged_at_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(unchanged_at locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at locs_change s1' s2')))
(ensures (
(unchanged_at locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\
(run f1 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw1.loc_reads s1 s2);
assert (unchanged_at rw1.loc_writes (run f1 s1) (run f1 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw2.loc_writes `difference` rw1.loc_writes) rw1.loc_writes s1 (run f1 s1) s2 (run f1 s2);
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) (run f1 s1) (run f1 s2));
lemma_unchanged_at_difference_elim rw2.loc_writes rw1.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw2.loc_writes (run f1 s1) (run f1 s2))
let lemma_bounded_effects_parallel_aux2 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\
(run f2 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw2.loc_reads s1 s2);
assert (unchanged_at rw2.loc_writes (run f2 s1) (run f2 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw1.loc_writes `difference` rw2.loc_writes) rw2.loc_writes s1 (run f2 s1) s2 (run f2 s2);
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) (run f2 s1) (run f2 s2));
lemma_unchanged_at_difference_elim rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw1.loc_writes (run f2 s1) (run f2 s2))
(* See fsti *)
let lemma_bounded_effects_parallel rw1 rw2 f1 f2 =
let rw = rw_set_in_parallel rw1 rw2 in
let aux s a :
Lemma
(requires (
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run f1 s).ms_ok))
(ensures (eval_location a s == eval_location a (run f1 s))) =
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw1.loc_writes s (run f1 s)) (* OBSERVE *)
in
let aux s = FStar.Classical.move_requires (aux s) in
FStar.Classical.forall_intro_2 aux;
let aux s a :
Lemma
(requires (
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run f2 s).ms_ok))
(ensures (eval_location a s == eval_location a (run f2 s))) =
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw2.loc_writes s (run f2 s)) (* OBSERVE *)
in
let aux s = FStar.Classical.move_requires (aux s) in
FStar.Classical.forall_intro_2 aux;
assert (only_affects rw.loc_writes f1);
assert (only_affects rw.loc_writes f2);
let rec aux c1 c2 s :
Lemma
(requires (constant_on_execution c1 f1 s /\ constant_on_execution c2 f2 s))
(ensures (constant_on_execution (c1 `intersect` c2) f1 s)) =
match c1 with
| [] -> ()
| x :: xs ->
aux xs c2 s
in
let aux = FStar.Classical.move_requires (aux rw1.loc_constant_writes rw2.loc_constant_writes) in
FStar.Classical.forall_intro aux;
let rec aux c1 c2 s :
Lemma
(requires (constant_on_execution c1 f1 s /\ constant_on_execution c2 f2 s))
(ensures (constant_on_execution (c1 `intersect` c2) f2 s)) =
match c1 with
| [] -> ()
| x :: xs ->
aux xs c2 s;
if (run f2 s).ms_ok && x `L.mem` c2 then (
lemma_constant_on_execution_mem c2 f2 s (dfst x) (dsnd x)
) else ()
in
let aux = FStar.Classical.move_requires (aux rw1.loc_constant_writes rw2.loc_constant_writes) in
FStar.Classical.forall_intro aux;
assert (forall s. constant_on_execution rw.loc_constant_writes f1 s);
assert (forall s. constant_on_execution rw.loc_constant_writes f2 s);
let aux l v :
Lemma
(L.mem (|l,v|) rw.loc_constant_writes ==> L.mem l rw.loc_writes) =
FStar.Classical.arrow_to_impl #(L.mem (|l,v|) rw.loc_constant_writes) #(L.mem l rw.loc_writes)
(fun _ -> lemma_constant_intersect_belongs_to_writes_union
rw1.loc_constant_writes rw2.loc_constant_writes rw1.loc_writes rw2.loc_writes l v)
in
FStar.Classical.forall_intro_2 aux;
assert (forall l v. L.mem (|l,v|) rw.loc_constant_writes ==> L.mem l rw.loc_writes);
let aux s1 s2 :
Lemma
(requires (s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2))
(ensures (
((run f1 s1).ms_ok = (run f1 s2).ms_ok) /\
((run f2 s1).ms_ok = (run f2 s2).ms_ok))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 s2 :
Lemma
(requires ((s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\
(run f1 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 s2 :
Lemma
(requires ((s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\
(run f2 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) =
lemma_bounded_effects_parallel_aux2 rw1 rw2 f1 f2 s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
assert (
forall s1 s2. (
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2) ==> (
((run f1 s1).ms_ok = (run f1 s2).ms_ok) /\
((run f1 s1).ms_ok ==>
unchanged_at rw.loc_writes (run f1 s1) (run f1 s2))
)
)
);
assert (
forall s1 s2. (
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2) ==> (
((run f2 s1).ms_ok = (run f2 s2).ms_ok) /\
((run f2 s1).ms_ok ==>
unchanged_at rw.loc_writes (run f2 s1) (run f2 s2))
)
)
)
let lemma_bounded_effects_series_aux1 rw1 rw2 f1 f2 s a :
Lemma
(requires (
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run (f1 ;* f2) s).ms_ok))
(ensures (
let open Vale.X64.Machine_Semantics_s in
eval_location a s == eval_location a (run (f1;*f2) s))) =
let open Vale.X64.Machine_Semantics_s in
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw1.loc_writes s (run f1 s));
assert (eval_location a s == eval_location a (run f1 s));
assert (unchanged_except rw2.loc_writes (run f1 s) (run f2 (run f1 s)));
assert (eval_location a s == eval_location a (run (f1;*f2) s)) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": 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 |
c1: Vale.Transformers.BoundedInstructionEffects.locations_with_values ->
c2: Vale.Transformers.BoundedInstructionEffects.locations_with_values ->
f1: Vale.X64.Machine_Semantics_s.st Prims.unit ->
f2: Vale.X64.Machine_Semantics_s.st Prims.unit ->
s: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
(forall (s: Vale.X64.Machine_Semantics_s.machine_state).
{:pattern Vale.Transformers.BoundedInstructionEffects.constant_on_execution c1 f1 s}
Vale.Transformers.BoundedInstructionEffects.constant_on_execution c1 f1 s) /\
(forall (s: Vale.X64.Machine_Semantics_s.machine_state).
{:pattern Vale.Transformers.BoundedInstructionEffects.constant_on_execution c2 f2 s}
Vale.Transformers.BoundedInstructionEffects.constant_on_execution c2 f2 s))
(ensures
Vale.Transformers.BoundedInstructionEffects.constant_on_execution (Vale.Transformers.BoundedInstructionEffects.intersect
c1
c2)
(( let* ) f1 (fun _ -> f2))
s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.BoundedInstructionEffects.locations_with_values",
"Vale.X64.Machine_Semantics_s.st",
"Prims.unit",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"Vale.X64.Machine_Semantics_s.run",
"Vale.Transformers.Locations.location_eq",
"Vale.Transformers.Locations.location_val_eqt",
"Prims.list",
"Vale.Transformers.BoundedInstructionEffects.location_with_value",
"Vale.Transformers.BoundedInstructionEffects.lemma_bounded_effects_series_aux2",
"Prims._assert",
"Prims.l_Forall",
"Prims.l_imp",
"Vale.Transformers.BoundedInstructionEffects.constant_on_execution",
"FStar.List.Tot.Base.mem",
"Prims.Mkdtuple2",
"Vale.Transformers.BoundedInstructionEffects.lemma_constant_on_execution_mem",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.op_let_Star",
"Prims.l_and",
"Prims.squash",
"Vale.Transformers.BoundedInstructionEffects.intersect",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_bounded_effects_series_aux2 c1 c2 f1 f2 s
: Lemma
(requires
((forall s. {:pattern (constant_on_execution c1 f1 s)} (constant_on_execution c1 f1 s)) /\
(forall s. {:pattern (constant_on_execution c2 f2 s)} (constant_on_execution c2 f2 s))))
(ensures
(let open Vale.X64.Machine_Semantics_s in
(constant_on_execution (c1 `intersect` c2)
(let* _ = f1 in
f2)
s))) =
| let open Vale.X64.Machine_Semantics_s in
let f =
let* _ = f1 in
f2
in
if (run f s).ms_ok
then
(match c1 with
| [] -> ()
| (| l , v |) :: xs ->
if L.mem (| l, v |) c2 then (lemma_constant_on_execution_mem c2 f2 (run f1 s) l v);
assert (forall s. constant_on_execution c1 f1 s ==> constant_on_execution xs f1 s);
lemma_bounded_effects_series_aux2 xs c2 f1 f2 s) | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_bounded_effects_series | val lemma_bounded_effects_series :
rw1:rw_set -> rw2:rw_set ->
f1:st unit -> f2:st unit ->
Lemma
(requires (
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2)))
(ensures (
let open Vale.X64.Machine_Semantics_s in
(bounded_effects (rw_set_in_series rw1 rw2) (f1;*f2)))) | val lemma_bounded_effects_series :
rw1:rw_set -> rw2:rw_set ->
f1:st unit -> f2:st unit ->
Lemma
(requires (
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2)))
(ensures (
let open Vale.X64.Machine_Semantics_s in
(bounded_effects (rw_set_in_series rw1 rw2) (f1;*f2)))) | let lemma_bounded_effects_series rw1 rw2 f1 f2 =
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
let aux s = FStar.Classical.move_requires (lemma_bounded_effects_series_aux1 rw1 rw2 f1 f2 s) in
FStar.Classical.forall_intro_2 aux;
let aux = FStar.Classical.move_requires (lemma_bounded_effects_series_aux2
rw1.loc_constant_writes rw2.loc_constant_writes f1 f2) in
FStar.Classical.forall_intro aux;
let aux l v :
Lemma
(L.mem (|l,v|) rw.loc_constant_writes ==> L.mem l rw.loc_writes) =
FStar.Classical.arrow_to_impl #(L.mem (|l,v|) rw.loc_constant_writes) #(L.mem l rw.loc_writes)
(fun _ -> lemma_constant_intersect_belongs_to_writes_union
rw1.loc_constant_writes rw2.loc_constant_writes rw1.loc_writes rw2.loc_writes l v)
in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_bounded_effects_series_aux3 rw1 rw2 f1 f2 s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_bounded_effects_series_aux4 rw1 rw2 f1 f2 s1) in
FStar.Classical.forall_intro_2 aux | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 1342,
"start_col": 0,
"start_line": 1323
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux
let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
)
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at_mem (as0:list location) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_at_difference_elim (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1 s2;
lemma_unchanged_at_difference_elim xs l2 s1 s2
) else (
lemma_unchanged_at_difference_elim xs l2 s1 s2
)
let lemma_unchanged_at_sym_diff_implies_difference (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) =
lemma_unchanged_at_append (l1 `difference` l2) (l2 `difference` l1) s1 s2
let rec lemma_disjoint_location_from_locations_not_mem (locs:locations) (l:location) :
Lemma
(ensures (
!!(disjoint_location_from_locations l locs) <==>
not (L.mem l locs))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem xs l
let rec lemma_difference_disjoint (l1 l2:locations) :
Lemma
(ensures (
!!(disjoint_locations (l1 `difference` l2) l2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem l2 x;
lemma_difference_disjoint xs l2
let rec lemma_unchanged_except_to_at_difference (locs locs_change:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except locs_change s1 s2))
(ensures (unchanged_at (locs `difference` locs_change) s1 s2)) =
match locs with
| [] -> ()
| x :: xs ->
lemma_difference_disjoint locs locs_change;
lemma_unchanged_except_to_at_difference xs locs_change s1 s2
let rec lemma_unchanged_at_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(unchanged_at locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at locs_change s1' s2')))
(ensures (
(unchanged_at locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\
(run f1 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw1.loc_reads s1 s2);
assert (unchanged_at rw1.loc_writes (run f1 s1) (run f1 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw2.loc_writes `difference` rw1.loc_writes) rw1.loc_writes s1 (run f1 s1) s2 (run f1 s2);
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) (run f1 s1) (run f1 s2));
lemma_unchanged_at_difference_elim rw2.loc_writes rw1.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw2.loc_writes (run f1 s1) (run f1 s2))
let lemma_bounded_effects_parallel_aux2 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\
(run f2 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw2.loc_reads s1 s2);
assert (unchanged_at rw2.loc_writes (run f2 s1) (run f2 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw1.loc_writes `difference` rw2.loc_writes) rw2.loc_writes s1 (run f2 s1) s2 (run f2 s2);
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) (run f2 s1) (run f2 s2));
lemma_unchanged_at_difference_elim rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw1.loc_writes (run f2 s1) (run f2 s2))
(* See fsti *)
let lemma_bounded_effects_parallel rw1 rw2 f1 f2 =
let rw = rw_set_in_parallel rw1 rw2 in
let aux s a :
Lemma
(requires (
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run f1 s).ms_ok))
(ensures (eval_location a s == eval_location a (run f1 s))) =
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw1.loc_writes s (run f1 s)) (* OBSERVE *)
in
let aux s = FStar.Classical.move_requires (aux s) in
FStar.Classical.forall_intro_2 aux;
let aux s a :
Lemma
(requires (
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run f2 s).ms_ok))
(ensures (eval_location a s == eval_location a (run f2 s))) =
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw2.loc_writes s (run f2 s)) (* OBSERVE *)
in
let aux s = FStar.Classical.move_requires (aux s) in
FStar.Classical.forall_intro_2 aux;
assert (only_affects rw.loc_writes f1);
assert (only_affects rw.loc_writes f2);
let rec aux c1 c2 s :
Lemma
(requires (constant_on_execution c1 f1 s /\ constant_on_execution c2 f2 s))
(ensures (constant_on_execution (c1 `intersect` c2) f1 s)) =
match c1 with
| [] -> ()
| x :: xs ->
aux xs c2 s
in
let aux = FStar.Classical.move_requires (aux rw1.loc_constant_writes rw2.loc_constant_writes) in
FStar.Classical.forall_intro aux;
let rec aux c1 c2 s :
Lemma
(requires (constant_on_execution c1 f1 s /\ constant_on_execution c2 f2 s))
(ensures (constant_on_execution (c1 `intersect` c2) f2 s)) =
match c1 with
| [] -> ()
| x :: xs ->
aux xs c2 s;
if (run f2 s).ms_ok && x `L.mem` c2 then (
lemma_constant_on_execution_mem c2 f2 s (dfst x) (dsnd x)
) else ()
in
let aux = FStar.Classical.move_requires (aux rw1.loc_constant_writes rw2.loc_constant_writes) in
FStar.Classical.forall_intro aux;
assert (forall s. constant_on_execution rw.loc_constant_writes f1 s);
assert (forall s. constant_on_execution rw.loc_constant_writes f2 s);
let aux l v :
Lemma
(L.mem (|l,v|) rw.loc_constant_writes ==> L.mem l rw.loc_writes) =
FStar.Classical.arrow_to_impl #(L.mem (|l,v|) rw.loc_constant_writes) #(L.mem l rw.loc_writes)
(fun _ -> lemma_constant_intersect_belongs_to_writes_union
rw1.loc_constant_writes rw2.loc_constant_writes rw1.loc_writes rw2.loc_writes l v)
in
FStar.Classical.forall_intro_2 aux;
assert (forall l v. L.mem (|l,v|) rw.loc_constant_writes ==> L.mem l rw.loc_writes);
let aux s1 s2 :
Lemma
(requires (s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2))
(ensures (
((run f1 s1).ms_ok = (run f1 s2).ms_ok) /\
((run f2 s1).ms_ok = (run f2 s2).ms_ok))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 s2 :
Lemma
(requires ((s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\
(run f1 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 s2 :
Lemma
(requires ((s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\
(run f2 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) =
lemma_bounded_effects_parallel_aux2 rw1 rw2 f1 f2 s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
assert (
forall s1 s2. (
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2) ==> (
((run f1 s1).ms_ok = (run f1 s2).ms_ok) /\
((run f1 s1).ms_ok ==>
unchanged_at rw.loc_writes (run f1 s1) (run f1 s2))
)
)
);
assert (
forall s1 s2. (
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2) ==> (
((run f2 s1).ms_ok = (run f2 s2).ms_ok) /\
((run f2 s1).ms_ok ==>
unchanged_at rw.loc_writes (run f2 s1) (run f2 s2))
)
)
)
let lemma_bounded_effects_series_aux1 rw1 rw2 f1 f2 s a :
Lemma
(requires (
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run (f1 ;* f2) s).ms_ok))
(ensures (
let open Vale.X64.Machine_Semantics_s in
eval_location a s == eval_location a (run (f1;*f2) s))) =
let open Vale.X64.Machine_Semantics_s in
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw1.loc_writes s (run f1 s));
assert (eval_location a s == eval_location a (run f1 s));
assert (unchanged_except rw2.loc_writes (run f1 s) (run f2 (run f1 s)));
assert (eval_location a s == eval_location a (run (f1;*f2) s))
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_bounded_effects_series_aux2 c1 c2 f1 f2 s :
Lemma
(requires (
(forall s. {:pattern (constant_on_execution c1 f1 s)} (constant_on_execution c1 f1 s)) /\
(forall s. {:pattern (constant_on_execution c2 f2 s)} (constant_on_execution c2 f2 s))))
(ensures (
let open Vale.X64.Machine_Semantics_s in
(constant_on_execution (c1 `intersect` c2) (f1;*f2) s))) =
let open Vale.X64.Machine_Semantics_s in
let f = f1;*f2 in
if (run f s).ms_ok then (
match c1 with
| [] -> ()
| (|l,v|) :: xs ->
if L.mem (|l,v|) c2 then (
lemma_constant_on_execution_mem c2 f2 (run f1 s) l v
) else ();
assert (forall s. constant_on_execution c1 f1 s ==> constant_on_execution xs f1 s); (* OBSERVE *)
lemma_bounded_effects_series_aux2 xs c2 f1 f2 s
) else ()
#pop-options
let rec lemma_unchanged_at_except_disjoint (same change:locations) (s1 s2 s1' s2':machine_state) :
Lemma
(requires (
(unchanged_at same s1 s2) /\
(unchanged_except change s1 s1') /\
(unchanged_except change s2 s2') /\
!!(disjoint_locations same change)))
(ensures (
(unchanged_at same s1' s2'))) =
match same with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_except_disjoint xs change s1 s2 s1' s2'
let lemma_bounded_effects_series_aux3 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let open Vale.X64.Machine_Semantics_s in
let f = f1;*f2 in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
let f = (f1;*f2) in
let s1_1, s2_1 = run f1 s1, run f1 s2 in
let s1_1_2, s2_1_2 = run f2 s1_1, run f2 s2_1 in
lemma_unchanged_at_append rw1.loc_reads (rw2.loc_reads `difference` rw1.loc_writes) s1 s2;
assert (s1_1.ms_ok = s2_1.ms_ok);
if s1_1.ms_ok then (
assert (only_affects rw1.loc_writes f1);
assert (unchanged_except rw1.loc_writes s1 s1_1);
assert (unchanged_except rw1.loc_writes s2 s2_1);
assert (unchanged_at (rw2.loc_reads `difference` rw1.loc_writes) s1 s2);
lemma_difference_disjoint rw2.loc_reads rw1.loc_writes;
lemma_unchanged_at_except_disjoint (rw2.loc_reads `difference` rw1.loc_writes) rw1.loc_writes s1 s2 s1_1 s2_1;
lemma_unchanged_at_difference_elim rw2.loc_reads rw1.loc_writes s1_1 s2_1
) else ()
let rec lemma_unchanged_at_extend_append (l1 l2:locations) (s1 s2 s1' s2':machine_state):
Lemma
(requires (
(unchanged_at l1 s1 s2) /\
(unchanged_except l2 s1 s1') /\
(unchanged_except l2 s2 s2') /\
(unchanged_at l2 s1' s2')))
(ensures (
(unchanged_at (l1 `L.append` l2) s1' s2'))) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1' s2'
) else (
lemma_unchanged_except_not_mem l2 x
);
lemma_unchanged_at_extend_append xs l2 s1 s2 s1' s2'
let lemma_bounded_effects_series_aux4 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run (f1;*f2) s1).ms_ok /\
(run (f1;*f2) s2).ms_ok /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let open Vale.X64.Machine_Semantics_s in
let f = f1;*f2 in
let rw = rw_set_in_series rw1 rw2 in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
let f = (f1;*f2) in
let s1_1, s2_1 = run f1 s1, run f1 s2 in
let s1_1_2, s2_1_2 = run f2 s1_1, run f2 s2_1 in
lemma_unchanged_at_append rw1.loc_reads (rw2.loc_reads `difference` rw1.loc_writes) s1 s2;
assert (s1_1.ms_ok /\ s2_1.ms_ok);
assert (s1_1_2.ms_ok /\ s2_1_2.ms_ok);
assert (unchanged_except rw1.loc_writes s1 s1_1);
assert (unchanged_except rw1.loc_writes s2 s2_1);
assert (unchanged_at (rw2.loc_reads `difference` rw1.loc_writes) s1 s2);
lemma_difference_disjoint rw2.loc_reads rw1.loc_writes;
lemma_unchanged_at_except_disjoint (rw2.loc_reads `difference` rw1.loc_writes) rw1.loc_writes s1 s2 s1_1 s2_1;
lemma_unchanged_at_difference_elim rw2.loc_reads rw1.loc_writes s1_1 s2_1;
assert (unchanged_at rw1.loc_writes s1_1 s2_1);
assert (unchanged_except rw2.loc_writes s1_1 s1_1_2);
assert (unchanged_except rw2.loc_writes s2_1 s2_1_2);
assert (unchanged_at rw2.loc_writes s1_1_2 s2_1_2);
lemma_unchanged_at_extend_append rw1.loc_writes rw2.loc_writes s1_1 s2_1 s1_1_2 s2_1_2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
rw1: Vale.Transformers.BoundedInstructionEffects.rw_set ->
rw2: Vale.Transformers.BoundedInstructionEffects.rw_set ->
f1: Vale.X64.Machine_Semantics_s.st Prims.unit ->
f2: Vale.X64.Machine_Semantics_s.st Prims.unit
-> FStar.Pervasives.Lemma
(requires
Vale.Transformers.BoundedInstructionEffects.bounded_effects rw1 f1 /\
Vale.Transformers.BoundedInstructionEffects.bounded_effects rw2 f2)
(ensures
Vale.Transformers.BoundedInstructionEffects.bounded_effects (Vale.Transformers.BoundedInstructionEffects.rw_set_in_series
rw1
rw2)
(( let* ) f1 (fun _ -> f2))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.BoundedInstructionEffects.rw_set",
"Vale.X64.Machine_Semantics_s.st",
"Prims.unit",
"FStar.Classical.forall_intro_2",
"Vale.X64.Machine_Semantics_s.machine_state",
"Prims.l_imp",
"Prims.l_and",
"Vale.Transformers.BoundedInstructionEffects.bounded_effects",
"Prims.b2t",
"Prims.op_Equality",
"Prims.bool",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_ok",
"FStar.Pervasives.Native.snd",
"FStar.Pervasives.Native.Mktuple2",
"Vale.X64.Machine_Semantics_s.Mkmachine_state",
"Prims.op_AmpAmp",
"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",
"Vale.X64.Machine_Semantics_s.__proj__Mkmachine_state__item__ms_trace",
"FStar.Pervasives.Native.tuple2",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_reads",
"Vale.Transformers.BoundedInstructionEffects.rw_set_in_series",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_writes",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Classical.move_requires",
"Vale.X64.Machine_Semantics_s.run",
"Vale.X64.Machine_Semantics_s.op_let_Star",
"Vale.Transformers.BoundedInstructionEffects.lemma_bounded_effects_series_aux4",
"Vale.Transformers.BoundedInstructionEffects.lemma_bounded_effects_series_aux3",
"Vale.Transformers.Locations.location",
"Prims.eq2",
"Vale.Transformers.Locations.location_val_t",
"FStar.Universe.raise_t",
"Vale.Transformers.Locations.location_val_eqt",
"FStar.List.Tot.Base.mem",
"Vale.Transformers.BoundedInstructionEffects.location_with_value",
"Prims.Mkdtuple2",
"Vale.Transformers.Locations.location_eq",
"Vale.Transformers.BoundedInstructionEffects.__proj__Mkrw_set__item__loc_constant_writes",
"FStar.Classical.arrow_to_impl",
"Vale.Transformers.BoundedInstructionEffects.lemma_constant_intersect_belongs_to_writes_union",
"FStar.Classical.forall_intro",
"Prims.l_Forall",
"Vale.Transformers.BoundedInstructionEffects.constant_on_execution",
"Vale.Transformers.BoundedInstructionEffects.intersect",
"Vale.Transformers.BoundedInstructionEffects.lemma_bounded_effects_series_aux2",
"Vale.Def.PossiblyMonad.uu___is_Ok",
"Vale.Transformers.Locations.disjoint_location_from_locations",
"Vale.Transformers.Locations.eval_location",
"Vale.Def.PossiblyMonad.op_Bang_Bang",
"Vale.Transformers.BoundedInstructionEffects.lemma_bounded_effects_series_aux1"
] | [] | false | false | true | false | false | let lemma_bounded_effects_series rw1 rw2 f1 f2 =
| let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
let aux s = FStar.Classical.move_requires (lemma_bounded_effects_series_aux1 rw1 rw2 f1 f2 s) in
FStar.Classical.forall_intro_2 aux;
let aux =
FStar.Classical.move_requires (lemma_bounded_effects_series_aux2 rw1.loc_constant_writes
rw2.loc_constant_writes
f1
f2)
in
FStar.Classical.forall_intro aux;
let aux l v : Lemma (L.mem (| l, v |) rw.loc_constant_writes ==> L.mem l rw.loc_writes) =
FStar.Classical.arrow_to_impl #(L.mem (| l, v |) rw.loc_constant_writes)
#(L.mem l rw.loc_writes)
(fun _ ->
lemma_constant_intersect_belongs_to_writes_union rw1.loc_constant_writes
rw2.loc_constant_writes
rw1.loc_writes
rw2.loc_writes
l
v)
in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_bounded_effects_series_aux3 rw1 rw2 f1 f2 s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_bounded_effects_series_aux4 rw1 rw2 f1 f2 s1) in
FStar.Classical.forall_intro_2 aux | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_extend_append | val lemma_unchanged_at_extend_append (l1 l2: locations) (s1 s2 s1' s2': machine_state)
: Lemma
(requires
((unchanged_at l1 s1 s2) /\ (unchanged_except l2 s1 s1') /\ (unchanged_except l2 s2 s2') /\
(unchanged_at l2 s1' s2'))) (ensures ((unchanged_at (l1 `L.append` l2) s1' s2'))) | val lemma_unchanged_at_extend_append (l1 l2: locations) (s1 s2 s1' s2': machine_state)
: Lemma
(requires
((unchanged_at l1 s1 s2) /\ (unchanged_except l2 s1 s1') /\ (unchanged_except l2 s2 s2') /\
(unchanged_at l2 s1' s2'))) (ensures ((unchanged_at (l1 `L.append` l2) s1' s2'))) | let rec lemma_unchanged_at_extend_append (l1 l2:locations) (s1 s2 s1' s2':machine_state):
Lemma
(requires (
(unchanged_at l1 s1 s2) /\
(unchanged_except l2 s1 s1') /\
(unchanged_except l2 s2 s2') /\
(unchanged_at l2 s1' s2')))
(ensures (
(unchanged_at (l1 `L.append` l2) s1' s2'))) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1' s2'
) else (
lemma_unchanged_except_not_mem l2 x
);
lemma_unchanged_at_extend_append xs l2 s1 s2 s1' s2' | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 56,
"end_line": 1284,
"start_col": 0,
"start_line": 1267
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2
#push-options "--z3rlimit 25 --initial_fuel 6 --max_fuel 6 --initial_ifuel 2 --max_ifuel 2"
let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2
#pop-options
let lemma_instr_apply_eval_same_read
(outs:list instr_out) (args:list instr_operand)
(f:instr_eval_t outs args) (oprs:instr_operands_t outs args)
(s1 s2:machine_state) :
Lemma
(requires (unchanged_at (aux_read_set1 outs args oprs) s1 s2))
(ensures (
(instr_apply_eval outs args f oprs s1) ==
(instr_apply_eval outs args f oprs s2))) =
lemma_instr_apply_eval_inouts_same_read outs outs args f oprs s1 s2
let unchanged_at' (l:locations) (s1 s2:machine_state) =
(s1.ms_ok = s2.ms_ok) /\
(s1.ms_ok /\ s2.ms_ok ==>
unchanged_at l s1 s2)
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 3 --max_ifuel 3"
let lemma_instr_write_output_explicit_only_writes
(i:instr_operand_explicit) (v:instr_val_t (IOpEx i)) (o:instr_operand_t i)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_explicit i o)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_explicit i o)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_explicit i v o s_orig1 s1,
instr_write_output_explicit i v o s_orig2 s2 in
let locs = snd (locations_of_explicit i o) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--z3rlimit 20 --initial_fuel 4 --max_fuel 4 --initial_ifuel 4 --max_ifuel 4"
let lemma_instr_write_output_implicit_only_writes
(i:instr_operand_implicit) (v:instr_val_t (IOpIm i))
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (fst (locations_of_implicit i)) s_orig1 s_orig2) /\
(unchanged_at' (fst (locations_of_implicit i)) s1 s2)))
(ensures (
let s1', s2' =
instr_write_output_implicit i v s_orig1 s1,
instr_write_output_implicit i v s_orig2 s2 in
let locs = snd (locations_of_implicit i) in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2'))) = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at'_mem (as0:locations) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at' as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2 \/ not s1.ms_ok))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at'_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_except_not_mem (as0:locations) (a:location) :
Lemma
(requires (
(not (L.mem a as0))))
(ensures (
!!(disjoint_location_from_locations a as0))) =
match as0 with
| [] -> ()
| x :: xs -> lemma_unchanged_except_not_mem xs a
let rec lemma_unchanged_at'_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok) /\
(unchanged_at' locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at' locs_change s1' s2')))
(ensures (
(unchanged_at' locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at'_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at'_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let rec lemma_disjoint_location_from_locations_append
(a:location) (as1 as2:list location) :
Lemma (
(!!(disjoint_location_from_locations a as1) /\
!!(disjoint_location_from_locations a as2)) <==>
(!!(disjoint_location_from_locations a (as1 `L.append` as2)))) =
match as1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_append a xs as2
let lemma_unchanged_except_extend (ls_extend ls:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except ls s1 s2))
(ensures (unchanged_except (ls_extend `L.append` ls) s1 s2)) =
let aux a :
Lemma
(requires (!!(disjoint_location_from_locations a (ls_extend `L.append` ls))))
(ensures (eval_location a s1 == eval_location a s2)) =
lemma_disjoint_location_from_locations_append a ls_extend ls
in
FStar.Classical.forall_intro (FStar.Classical.move_requires aux)
let lemma_instr_write_outputs_only_affects_write_extend
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig s:machine_state)
(locs_extension:locations) :
Lemma
(ensures (
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
unchanged_except (locs_extension `L.append` locs) s s')) =
let s' = instr_write_outputs outs args vs oprs s_orig s in
let locs = aux_write_set outs args oprs in
FStar.Classical.forall_intro
(FStar.Classical.move_requires (lemma_instr_write_outputs_only_affects_write outs args vs oprs s_orig s));
lemma_unchanged_except_extend locs_extension locs s s'
#restart-solver
#push-options "--z3rlimit 400 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_instr_write_outputs_only_writes
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args)
(s_orig1 s1 s_orig2 s2:machine_state) :
Lemma
(requires (
(unchanged_at (aux_read_set1 outs args oprs) s_orig1 s_orig2) /\
(unchanged_at' (aux_read_set1 outs args oprs) s1 s2) /\
(s1.ms_ok = s2.ms_ok)))
(ensures (
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
let locs = aux_write_set outs args oprs in
(unchanged_at' locs s1' s2' /\
unchanged_except locs s1 s1' /\
unchanged_except locs s2 s2' /\
(not s1.ms_ok ==> not s1'.ms_ok) /\
(not s2.ms_ok ==> not s2'.ms_ok)))) =
let s1', s2' =
instr_write_outputs outs args vs oprs s_orig1 s1,
instr_write_outputs outs args vs oprs s_orig2 s2 in
match outs with
| [] -> ()
| (io, 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 o, oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_explicit i o in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_explicit_only_writes i v o s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_explicit i v o s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_explicit i v o s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
| IOpIm i ->
let oprs = coerce oprs in
let loc_op_l, loc_op_r = locations_of_implicit i in
let loc_op_b = loc_op_l `L.append` loc_op_r in
let loc_rest = aux_read_set1 outs args oprs in
lemma_unchanged_at_append loc_op_l loc_op_r s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_b loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_rest s_orig1 s_orig2;
lemma_unchanged_at_append loc_op_l loc_op_r s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_unchanged_at_append loc_op_b loc_rest s1 s2;
lemma_unchanged_at_append loc_op_l loc_rest s1 s2;
lemma_instr_write_output_implicit_only_writes i v s_orig1 s1 s_orig2 s2;
let s1_old, s1 = s1, instr_write_output_implicit i v s_orig1 s1 in
let s2_old, s2 = s2, instr_write_output_implicit i v s_orig2 s2 in
lemma_unchanged_at'_maintained loc_rest loc_op_r s1_old s1 s2_old s2;
lemma_instr_write_outputs_only_writes outs args vs oprs s_orig1 s1 s_orig2 s2;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 loc_op_r;
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig1 s1 [];
lemma_instr_write_outputs_only_affects_write_extend outs args vs oprs s_orig2 s2 [];
let s1_old, s1 = s1, instr_write_outputs outs args vs oprs s_orig1 s1 in
let s2_old, s2 = s2, instr_write_outputs outs args vs oprs s_orig2 s2 in
lemma_unchanged_at_append loc_op_r (aux_write_set outs args oprs) s1 s2;
lemma_unchanged_at'_maintained loc_op_r (aux_write_set outs args oprs) s1_old s1 s2_old s2
)
#pop-options
let rec lemma_unchanged_at'_maintained_upon_flag_update (locs:locations) (s1 s2:machine_state) (flags:flags_t) :
Lemma
(requires (unchanged_at' locs s1 s2))
(ensures (unchanged_at' locs
({s1 with ms_flags = flags})
({s2 with ms_flags = flags}))) =
match locs with
| [] -> ()
| x :: xs -> lemma_unchanged_at'_maintained_upon_flag_update xs s1 s2 flags
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_unchanged_at'
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins (Instr it oprs ann)).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
let s1' = eval_instr it oprs ann s1 in
let s2' = eval_instr it oprs ann s2 in
(Some? s1' = Some? s2') /\
(Some? s1' ==>
unchanged_at' w (Some?.v s1') (Some?.v s2')))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs1 = instr_apply_eval outs args (instr_eval i) oprs s1 in
let vs2 = instr_apply_eval outs args (instr_eval i) oprs s2 in
lemma_instr_apply_eval_same_read outs args (instr_eval i) oprs s1 s2;
assert (vs1 == vs2);
let s11, s22 =
match havoc_flags' with
| HavocFlags -> {s1 with ms_flags = havoc_flags}, {s2 with ms_flags = havoc_flags}
| PreserveFlags -> s1, s2
in
let s111 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s1 s11) vs1 in
let s222 = FStar.Option.mapTot (fun vs -> instr_write_outputs outs args vs oprs s2 s22) vs2 in
match vs1 with
| None -> ()
| Some vs ->
lemma_unchanged_at'_maintained_upon_flag_update (aux_read_set1 outs args oprs) s1 s2 havoc_flags;
lemma_instr_write_outputs_only_writes outs args vs oprs s1 s11 s2 s22;
if havoc_flags' = HavocFlags then (
let Some s1', Some s2' = s111, s222 in
let locs = aux_write_set outs args oprs in
if L.mem ALocOf locs then (
lemma_unchanged_at'_mem locs ALocOf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocOf
);
if L.mem ALocCf locs then (
lemma_unchanged_at'_mem locs ALocCf s1' s2'
) else (
lemma_unchanged_except_not_mem locs ALocCf
)
) else ()
#pop-options
let lemma_machine_eval_ins_st_ok (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2)))
(ensures (
let f = machine_eval_ins_st i in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
let lemma_machine_eval_ins_st_unchanged_behavior (i:ins{Instr? i}) (s1 s2:machine_state) :
Lemma
(requires (
let r = (rw_set_of_ins i).loc_reads in
let f = machine_eval_ins_st i in
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at r s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let w = (rw_set_of_ins i).loc_writes in
let f = machine_eval_ins_st i in
(unchanged_at w (run f s1) (run f s2)))) =
let Instr it oprs ann = i in
lemma_eval_instr_unchanged_at' it oprs ann s1 s2
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_constant_on_execution (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (constant_on_execution (rw_set_of_ins i).loc_constant_writes (machine_eval_ins_st i) s)) =
if s.ms_ok then (
let Instr it oprs ann = i in
let InstrTypeRecord #outs #args #havoc_flags' i = it in
match havoc_flags' with
| PreserveFlags -> ()
| HavocFlags ->
let ws = aux_write_set outs args oprs in
if L.mem ALocCf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocCf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocCf
);
if L.mem ALocOf ws then () else (
let s0 = s in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
match vs with
| None -> ()
| Some vs ->
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_unchanged_except_not_mem ws ALocOf;
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 ALocOf
)
) else ()
#pop-options
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_ins_st_bounded_effects_Instr (i:ins{Instr? i}) :
Lemma
(ensures (
(bounded_effects (rw_set_of_ins i) (machine_eval_ins_st i)))) =
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_only_affects_write i);
FStar.Classical.forall_intro (lemma_machine_eval_ins_st_constant_on_execution i);
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_ok i s1));
FStar.Classical.forall_intro_2 (fun s1 ->
FStar.Classical.move_requires (lemma_machine_eval_ins_st_unchanged_behavior i s1))
#pop-options
(* See fsti *)
let lemma_machine_eval_ins_st_bounded_effects i =
match i with
| Instr _ _ _ -> lemma_machine_eval_ins_st_bounded_effects_Instr i
| _ -> assert_norm (not (safely_bounded i))
let rec lemma_unchanged_at_trace (locs:locations) (s1 s2:machine_state) trace1 trace2 :
Lemma
(requires (unchanged_at locs s1 s2))
(ensures (unchanged_at locs ({s1 with ms_trace = trace1}) ({s2 with ms_trace = trace2}))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_trace xs s1 s2 trace1 trace2
let machine_eval_code_Ins i fuel : st unit =
(fun s -> (), (Some?.v (machine_eval_code_ins_def i s)))
let lemma_machine_eval_code_Ins_bounded_effects_aux1 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
unchanged_except rw.loc_writes s (run f s))) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_only_affects_write i (filt s);
assert (unchanged_except rw.loc_writes
(run (machine_eval_ins_st i) (filt s))
(run f s)) (* OBSERVE *)
let lemma_machine_eval_code_Ins_bounded_effects_aux2 (i:ins) (fuel:nat) s :
Lemma
(requires (safely_bounded i))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
constant_on_execution rw.loc_constant_writes f s)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_machine_eval_ins_st_constant_on_execution i (filt s);
let rec aux c :
Lemma
(requires (constant_on_execution c (machine_eval_ins_st i) (filt s)))
(ensures (constant_on_execution c f s)) =
if (run f s).ms_ok then (
match c with
| [] -> ()
| (|l,v|) :: xs ->
aux xs
) else ()
in
aux rw.loc_constant_writes
let lemma_machine_eval_code_Ins_bounded_effects_aux3 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let filt s = { s with ms_trace = [] } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_ok i (filt s1) (filt s2)
let lemma_machine_eval_code_Ins_bounded_effects_aux4 (i:ins) (fuel:nat) s1 s2 :
Lemma
(requires (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(safely_bounded i) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2) /\
(run f s1).ms_ok /\
(run f s2).ms_ok))
(ensures (
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
(unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
let filt s = { s with ms_trace = [] } in
let intr s_orig s = { s with ms_trace = (ins_obs i s_orig) `L.append` s_orig.ms_trace } in
let f : st unit = machine_eval_code_Ins i fuel in
let rw = rw_set_of_ins i in
lemma_unchanged_at_trace rw.loc_reads s1 s2 [] [];
lemma_machine_eval_ins_st_unchanged_behavior i (filt s1) (filt s2);
lemma_unchanged_at_trace rw.loc_writes (machine_eval_ins i (filt s1)) (machine_eval_ins i (filt s2))
(intr s1 s1).ms_trace (intr s2 s2).ms_trace
#push-options "--initial_fuel 3 --max_fuel 3 --initial_ifuel 1 --max_ifuel 1"
let lemma_machine_eval_code_Ins_bounded_effects_aux i fuel :
Lemma
(requires (safely_bounded i))
(ensures (
(bounded_effects (rw_set_of_ins i)
(machine_eval_code_Ins i fuel)))) =
let f : st unit = machine_eval_code_Ins i fuel in
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux1 i fuel) in
FStar.Classical.forall_intro aux;
let aux = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux2 i fuel) in
FStar.Classical.forall_intro aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux3 i fuel s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 = FStar.Classical.move_requires (lemma_machine_eval_code_Ins_bounded_effects_aux4 i fuel s1) in
FStar.Classical.forall_intro_2 aux
#pop-options
(* See fsti *)
let lemma_machine_eval_code_Ins_bounded_effects i fuel =
lemma_machine_eval_code_Ins_bounded_effects_aux i fuel
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
(* See fsti *)
let lemma_locations_of_ocmp o s1 s2 = ()
#pop-options
let rec intersect (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then x :: intersect xs l2 else intersect xs l2
let rec difference (#t:eqtype) (l1 l2:list t) : list t =
match l1 with
| [] -> []
| x :: xs -> if L.mem x l2 then difference xs l2 else x :: difference xs l2
let sym_difference (#t:eqtype) (l1 l2:list t) : list t =
difference l1 l2 `L.append` difference l2 l1
(* See fsti *)
let rw_set_in_parallel rw1 rw2 =
{
loc_reads = sym_difference rw1.loc_writes rw2.loc_writes `L.append` (rw1.loc_reads `L.append` rw2.loc_reads);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
(* See fsti *)
let rw_set_in_series rw1 rw2 =
{
loc_reads = rw1.loc_reads `L.append` (difference rw2.loc_reads rw1.loc_writes);
loc_writes = rw1.loc_writes `L.append` rw2.loc_writes;
loc_constant_writes = rw1.loc_constant_writes `intersect` rw2.loc_constant_writes;
}
let rec lemma_constant_on_execution_mem (locv:locations_with_values) (f:st unit) (s:machine_state)
(l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(run f s).ms_ok /\
(constant_on_execution locv f s) /\
(L.mem (|l,v|) locv)))
(ensures (eval_location l (run f s) == raise_location_val_eqt v)) =
let (|l1,v1|) :: xs = locv in
if l = l1 && v = v1 then () else (
lemma_constant_on_execution_mem xs f s l v
)
(* See fsti *)
let lemma_add_r_to_rw_set r rw_old f =
let rw = add_r_to_rw_set r rw_old in
let aux s1 s2 :
Lemma
(requires (
(bounded_effects rw_old f) /\
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2)))
(ensures (
((run f s1).ms_ok = (run f s2).ms_ok) /\
((run f s1).ms_ok ==>
unchanged_at rw.loc_writes (run f s1) (run f s2)))) =
lemma_unchanged_at_append r rw_old.loc_reads s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux
let rec lemma_constant_intersect_belongs_to_writes_union
(c1 c2:locations_with_values) (w1 w2:locations) (l:location_eq) (v:location_val_eqt l) :
Lemma
(requires (
(let x : location_with_value = (|l,v|) in
L.mem x (c1 `intersect` c2) /\
(forall l v. {:pattern (L.mem (|l,v|) c1); (L.mem l w1)}
L.mem (|l,v|) c1 ==> L.mem l w1) /\
(forall l v. {:pattern (L.mem (|l,v|) c2); (L.mem l w2)}
L.mem (|l,v|) c2 ==> L.mem l w2))))
(ensures (L.mem l (w1 `L.append` w2))) =
match c1 with
| [] -> ()
| x :: xs ->
if x = (|l,v|) then (
assert (L.mem (|l,v|) c1);
assert (L.mem l w1);
L.append_mem w1 w2 l
) else (
assert (forall l v. L.mem (|l,v|) xs ==> L.mem (|l,v|) c1);
lemma_constant_intersect_belongs_to_writes_union xs c2 w1 w2 l v
)
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_unchanged_at_mem (as0:list location) (a:location) (s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at as0 s1 s2) /\
(L.mem a as0)))
(ensures (
(eval_location a s1 == eval_location a s2))) =
match as0 with
| [_] -> ()
| x :: xs ->
if a = x then () else
lemma_unchanged_at_mem xs a s1 s2
#pop-options
let rec lemma_unchanged_at_difference_elim (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at l2 s1 s2))
(ensures (unchanged_at l1 s1 s2)) =
match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2 then (
lemma_unchanged_at_mem l2 x s1 s2;
lemma_unchanged_at_difference_elim xs l2 s1 s2
) else (
lemma_unchanged_at_difference_elim xs l2 s1 s2
)
let lemma_unchanged_at_sym_diff_implies_difference (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_at (sym_difference l1 l2) s1 s2))
(ensures (unchanged_at (l1 `difference` l2) s1 s2 /\ unchanged_at (l2 `difference` l1) s1 s2)) =
lemma_unchanged_at_append (l1 `difference` l2) (l2 `difference` l1) s1 s2
let rec lemma_disjoint_location_from_locations_not_mem (locs:locations) (l:location) :
Lemma
(ensures (
!!(disjoint_location_from_locations l locs) <==>
not (L.mem l locs))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem xs l
let rec lemma_difference_disjoint (l1 l2:locations) :
Lemma
(ensures (
!!(disjoint_locations (l1 `difference` l2) l2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_disjoint_location_from_locations_not_mem l2 x;
lemma_difference_disjoint xs l2
let rec lemma_unchanged_except_to_at_difference (locs locs_change:locations) (s1 s2:machine_state) :
Lemma
(requires (unchanged_except locs_change s1 s2))
(ensures (unchanged_at (locs `difference` locs_change) s1 s2)) =
match locs with
| [] -> ()
| x :: xs ->
lemma_difference_disjoint locs locs_change;
lemma_unchanged_except_to_at_difference xs locs_change s1 s2
let rec lemma_unchanged_at_maintained (locs locs_change:locations) (s1 s1' s2 s2':machine_state) :
Lemma
(requires (
(unchanged_at locs s1 s2) /\
(unchanged_except locs_change s1 s1') /\
(unchanged_except locs_change s2 s2') /\
(unchanged_at locs_change s1' s2')))
(ensures (
(unchanged_at locs s1' s2'))) =
match locs with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_maintained xs locs_change s1 s1' s2 s2';
if x `L.mem` locs_change then (
lemma_unchanged_at_mem locs_change x s1' s2'
) else (
lemma_unchanged_except_not_mem locs_change x
)
let lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\
(run f1 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw1.loc_reads s1 s2);
assert (unchanged_at rw1.loc_writes (run f1 s1) (run f1 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw2.loc_writes `difference` rw1.loc_writes) rw1.loc_writes s1 (run f1 s1) s2 (run f1 s2);
assert (unchanged_at (rw2.loc_writes `difference` rw1.loc_writes) (run f1 s1) (run f1 s2));
lemma_unchanged_at_difference_elim rw2.loc_writes rw1.loc_writes (run f1 s1) (run f1 s2);
assert (unchanged_at rw2.loc_writes (run f1 s1) (run f1 s2))
let lemma_bounded_effects_parallel_aux2 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let rw = rw_set_in_parallel rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\
(run f2 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
let rw = rw_set_in_parallel rw1 rw2 in
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2;
lemma_unchanged_at_append rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw2.loc_reads s1 s2);
assert (unchanged_at rw2.loc_writes (run f2 s1) (run f2 s2));
lemma_unchanged_at_sym_diff_implies_difference rw1.loc_writes rw2.loc_writes s1 s2;
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) s1 s2);
lemma_unchanged_at_maintained (rw1.loc_writes `difference` rw2.loc_writes) rw2.loc_writes s1 (run f2 s1) s2 (run f2 s2);
assert (unchanged_at (rw1.loc_writes `difference` rw2.loc_writes) (run f2 s1) (run f2 s2));
lemma_unchanged_at_difference_elim rw1.loc_writes rw2.loc_writes (run f2 s1) (run f2 s2);
assert (unchanged_at rw1.loc_writes (run f2 s1) (run f2 s2))
(* See fsti *)
let lemma_bounded_effects_parallel rw1 rw2 f1 f2 =
let rw = rw_set_in_parallel rw1 rw2 in
let aux s a :
Lemma
(requires (
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run f1 s).ms_ok))
(ensures (eval_location a s == eval_location a (run f1 s))) =
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw1.loc_writes s (run f1 s)) (* OBSERVE *)
in
let aux s = FStar.Classical.move_requires (aux s) in
FStar.Classical.forall_intro_2 aux;
let aux s a :
Lemma
(requires (
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run f2 s).ms_ok))
(ensures (eval_location a s == eval_location a (run f2 s))) =
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw2.loc_writes s (run f2 s)) (* OBSERVE *)
in
let aux s = FStar.Classical.move_requires (aux s) in
FStar.Classical.forall_intro_2 aux;
assert (only_affects rw.loc_writes f1);
assert (only_affects rw.loc_writes f2);
let rec aux c1 c2 s :
Lemma
(requires (constant_on_execution c1 f1 s /\ constant_on_execution c2 f2 s))
(ensures (constant_on_execution (c1 `intersect` c2) f1 s)) =
match c1 with
| [] -> ()
| x :: xs ->
aux xs c2 s
in
let aux = FStar.Classical.move_requires (aux rw1.loc_constant_writes rw2.loc_constant_writes) in
FStar.Classical.forall_intro aux;
let rec aux c1 c2 s :
Lemma
(requires (constant_on_execution c1 f1 s /\ constant_on_execution c2 f2 s))
(ensures (constant_on_execution (c1 `intersect` c2) f2 s)) =
match c1 with
| [] -> ()
| x :: xs ->
aux xs c2 s;
if (run f2 s).ms_ok && x `L.mem` c2 then (
lemma_constant_on_execution_mem c2 f2 s (dfst x) (dsnd x)
) else ()
in
let aux = FStar.Classical.move_requires (aux rw1.loc_constant_writes rw2.loc_constant_writes) in
FStar.Classical.forall_intro aux;
assert (forall s. constant_on_execution rw.loc_constant_writes f1 s);
assert (forall s. constant_on_execution rw.loc_constant_writes f2 s);
let aux l v :
Lemma
(L.mem (|l,v|) rw.loc_constant_writes ==> L.mem l rw.loc_writes) =
FStar.Classical.arrow_to_impl #(L.mem (|l,v|) rw.loc_constant_writes) #(L.mem l rw.loc_writes)
(fun _ -> lemma_constant_intersect_belongs_to_writes_union
rw1.loc_constant_writes rw2.loc_constant_writes rw1.loc_writes rw2.loc_writes l v)
in
FStar.Classical.forall_intro_2 aux;
assert (forall l v. L.mem (|l,v|) rw.loc_constant_writes ==> L.mem l rw.loc_writes);
let aux s1 s2 :
Lemma
(requires (s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2))
(ensures (
((run f1 s1).ms_ok = (run f1 s2).ms_ok) /\
((run f2 s1).ms_ok = (run f2 s2).ms_ok))) =
lemma_unchanged_at_append rw1.loc_reads rw2.loc_reads s1 s2;
lemma_unchanged_at_append (sym_difference rw1.loc_writes rw2.loc_writes) (rw1.loc_reads `L.append` rw2.loc_reads) s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 s2 :
Lemma
(requires ((s1.ms_ok = s2.ms_ok) /\
(run f1 s1).ms_ok /\
(run f1 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
(unchanged_at rw.loc_writes (run f1 s1) (run f1 s2)))) =
lemma_bounded_effects_parallel_aux1 rw1 rw2 f1 f2 s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
let aux s1 s2 :
Lemma
(requires ((s1.ms_ok = s2.ms_ok) /\
(run f2 s1).ms_ok /\
(run f2 s2).ms_ok /\
unchanged_at rw.loc_reads s1 s2))
(ensures (
(unchanged_at rw.loc_writes (run f2 s1) (run f2 s2)))) =
lemma_bounded_effects_parallel_aux2 rw1 rw2 f1 f2 s1 s2
in
let aux s1 = FStar.Classical.move_requires (aux s1) in
FStar.Classical.forall_intro_2 aux;
assert (
forall s1 s2. (
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2) ==> (
((run f1 s1).ms_ok = (run f1 s2).ms_ok) /\
((run f1 s1).ms_ok ==>
unchanged_at rw.loc_writes (run f1 s1) (run f1 s2))
)
)
);
assert (
forall s1 s2. (
(s1.ms_ok = s2.ms_ok /\ unchanged_at rw.loc_reads s1 s2) ==> (
((run f2 s1).ms_ok = (run f2 s2).ms_ok) /\
((run f2 s1).ms_ok ==>
unchanged_at rw.loc_writes (run f2 s1) (run f2 s2))
)
)
)
let lemma_bounded_effects_series_aux1 rw1 rw2 f1 f2 s a :
Lemma
(requires (
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
!!(disjoint_location_from_locations a rw.loc_writes) /\
(run (f1 ;* f2) s).ms_ok))
(ensures (
let open Vale.X64.Machine_Semantics_s in
eval_location a s == eval_location a (run (f1;*f2) s))) =
let open Vale.X64.Machine_Semantics_s in
lemma_disjoint_location_from_locations_append a rw1.loc_writes rw2.loc_writes;
assert (unchanged_except rw1.loc_writes s (run f1 s));
assert (eval_location a s == eval_location a (run f1 s));
assert (unchanged_except rw2.loc_writes (run f1 s) (run f2 (run f1 s)));
assert (eval_location a s == eval_location a (run (f1;*f2) s))
#push-options "--initial_fuel 1 --max_fuel 1 --initial_ifuel 1 --max_ifuel 1"
let rec lemma_bounded_effects_series_aux2 c1 c2 f1 f2 s :
Lemma
(requires (
(forall s. {:pattern (constant_on_execution c1 f1 s)} (constant_on_execution c1 f1 s)) /\
(forall s. {:pattern (constant_on_execution c2 f2 s)} (constant_on_execution c2 f2 s))))
(ensures (
let open Vale.X64.Machine_Semantics_s in
(constant_on_execution (c1 `intersect` c2) (f1;*f2) s))) =
let open Vale.X64.Machine_Semantics_s in
let f = f1;*f2 in
if (run f s).ms_ok then (
match c1 with
| [] -> ()
| (|l,v|) :: xs ->
if L.mem (|l,v|) c2 then (
lemma_constant_on_execution_mem c2 f2 (run f1 s) l v
) else ();
assert (forall s. constant_on_execution c1 f1 s ==> constant_on_execution xs f1 s); (* OBSERVE *)
lemma_bounded_effects_series_aux2 xs c2 f1 f2 s
) else ()
#pop-options
let rec lemma_unchanged_at_except_disjoint (same change:locations) (s1 s2 s1' s2':machine_state) :
Lemma
(requires (
(unchanged_at same s1 s2) /\
(unchanged_except change s1 s1') /\
(unchanged_except change s2 s2') /\
!!(disjoint_locations same change)))
(ensures (
(unchanged_at same s1' s2'))) =
match same with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_except_disjoint xs change s1 s2 s1' s2'
let lemma_bounded_effects_series_aux3 rw1 rw2 f1 f2 s1 s2 :
Lemma
(requires (
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
(bounded_effects rw1 f1) /\
(bounded_effects rw2 f2) /\
(s1.ms_ok = s2.ms_ok) /\
(unchanged_at rw.loc_reads s1 s2)))
(ensures (
let open Vale.X64.Machine_Semantics_s in
let f = f1;*f2 in
(run f s1).ms_ok = (run f s2).ms_ok)) =
let open Vale.X64.Machine_Semantics_s in
let rw = rw_set_in_series rw1 rw2 in
let f = (f1;*f2) in
let s1_1, s2_1 = run f1 s1, run f1 s2 in
let s1_1_2, s2_1_2 = run f2 s1_1, run f2 s2_1 in
lemma_unchanged_at_append rw1.loc_reads (rw2.loc_reads `difference` rw1.loc_writes) s1 s2;
assert (s1_1.ms_ok = s2_1.ms_ok);
if s1_1.ms_ok then (
assert (only_affects rw1.loc_writes f1);
assert (unchanged_except rw1.loc_writes s1 s1_1);
assert (unchanged_except rw1.loc_writes s2 s2_1);
assert (unchanged_at (rw2.loc_reads `difference` rw1.loc_writes) s1 s2);
lemma_difference_disjoint rw2.loc_reads rw1.loc_writes;
lemma_unchanged_at_except_disjoint (rw2.loc_reads `difference` rw1.loc_writes) rw1.loc_writes s1 s2 s1_1 s2_1;
lemma_unchanged_at_difference_elim rw2.loc_reads rw1.loc_writes s1_1 s2_1
) else () | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
l1: Vale.Transformers.Locations.locations ->
l2: Vale.Transformers.Locations.locations ->
s1: Vale.X64.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state ->
s1': Vale.X64.Machine_Semantics_s.machine_state ->
s2': Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
Vale.Transformers.BoundedInstructionEffects.unchanged_at l1 s1 s2 /\
Vale.Transformers.BoundedInstructionEffects.unchanged_except l2 s1 s1' /\
Vale.Transformers.BoundedInstructionEffects.unchanged_except l2 s2 s2' /\
Vale.Transformers.BoundedInstructionEffects.unchanged_at l2 s1' s2')
(ensures Vale.Transformers.BoundedInstructionEffects.unchanged_at (l1 @ l2) s1' s2') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Transformers.Locations.locations",
"Vale.X64.Machine_Semantics_s.machine_state",
"Vale.Transformers.Locations.location",
"Prims.list",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_extend_append",
"Prims.unit",
"FStar.List.Tot.Base.mem",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_mem",
"Prims.bool",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_except_not_mem",
"Prims.l_and",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Vale.Transformers.BoundedInstructionEffects.unchanged_except",
"Prims.squash",
"FStar.List.Tot.Base.append",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_unchanged_at_extend_append (l1 l2: locations) (s1 s2 s1' s2': machine_state)
: Lemma
(requires
((unchanged_at l1 s1 s2) /\ (unchanged_except l2 s1 s1') /\ (unchanged_except l2 s2 s2') /\
(unchanged_at l2 s1' s2'))) (ensures ((unchanged_at (l1 `L.append` l2) s1' s2'))) =
| match l1 with
| [] -> ()
| x :: xs ->
if L.mem x l2
then (lemma_unchanged_at_mem l2 x s1' s2')
else (lemma_unchanged_except_not_mem l2 x);
lemma_unchanged_at_extend_append xs l2 s1 s2 s1' s2' | false |
Hacl.P256.PrecompTable.fst | Hacl.P256.PrecompTable.precomp_basepoint_table_w4 | val precomp_basepoint_table_w4:
x:glbuffer uint64 192ul{witnessed x precomp_basepoint_table_lseq_w4 /\ recallable x} | val precomp_basepoint_table_w4:
x:glbuffer uint64 192ul{witnessed x precomp_basepoint_table_lseq_w4 /\ recallable x} | let precomp_basepoint_table_w4:
x:glbuffer uint64 192ul{witnessed x precomp_basepoint_table_lseq_w4 /\ recallable x} =
createL_global precomp_basepoint_table_list_w4 | {
"file_name": "code/ecdsap256/Hacl.P256.PrecompTable.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 48,
"end_line": 213,
"start_col": 0,
"start_line": 211
} | module Hacl.P256.PrecompTable
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module LE = Lib.Exponentiation
module SE = Spec.Exponentiation
module SPT = Hacl.Spec.PrecompBaseTable
module SPT256 = Hacl.Spec.PrecompBaseTable256
module SPTK = Hacl.Spec.P256.PrecompTable
module S = Spec.P256
module SL = Spec.P256.Lemmas
open Hacl.Impl.P256.Point
include Hacl.Impl.P256.Group
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let proj_point_to_list p =
SPTK.proj_point_to_list_lemma p;
SPTK.proj_point_to_list p
let lemma_refl x =
SPTK.proj_point_to_list_lemma x
//-----------------
inline_for_extraction noextract
let proj_g_pow2_64 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
[@inline_let]
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
[@inline_let]
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
(rX, rY, rZ)
val lemma_proj_g_pow2_64_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops S.base_point 64 == proj_g_pow2_64)
let lemma_proj_g_pow2_64_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops S.base_point 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64);
let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in
let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in
let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_128 : S.proj_point =
[@inline_let]
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
[@inline_let]
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
[@inline_let]
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
(rX, rY, rZ)
val lemma_proj_g_pow2_128_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64 == proj_g_pow2_128)
let lemma_proj_g_pow2_128_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_64 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64);
let rX : S.felem = 0x04c3aaf6c6c00704e96eda89461d63fd2c97ee1e6786fc785e6afac7aa92f9b1 in
let rY : S.felem = 0x14f1edaeb8e9c8d4797d164a3946c7ff50a7c8cd59139a4dbce354e6e4df09c3 in
let rZ : S.felem = 0x80119ced9a5ce83c4e31f8de1a38f89d5f9ff9f637dca86d116a4217f83e55d2 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
inline_for_extraction noextract
let proj_g_pow2_192 : S.proj_point =
[@inline_let]
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
[@inline_let]
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
[@inline_let]
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
(rX, rY, rZ)
val lemma_proj_g_pow2_192_eval : unit ->
Lemma (SE.exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64 == proj_g_pow2_192)
let lemma_proj_g_pow2_192_eval () =
SPT256.exp_pow2_rec_is_exp_pow2 S.mk_p256_concrete_ops proj_g_pow2_128 64;
let qX, qY, qZ = normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64) in
normalize_term_spec (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64);
let rX : S.felem = 0xc762a9c8ae1b2f7434ff8da70fe105e0d4f188594989f193de0dbdbf5f60cb9a in
let rY : S.felem = 0x1eddaf51836859e1369f1ae8d9ab02e4123b6f151d9b796e297a38fa5613d9bc in
let rZ : S.felem = 0xcb433ab3f67815707e398dc7910cc4ec6ea115360060fc73c35b53dce02e2c72 in
assert_norm (qX == rX /\ qY == rY /\ qZ == rZ)
// let proj_g_pow2_64 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops S.base_point 64)
// let proj_g_pow2_128 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_64 64)
// let proj_g_pow2_192 : S.proj_point =
// normalize_term (SPT256.exp_pow2_rec S.mk_p256_concrete_ops proj_g_pow2_128 64)
inline_for_extraction noextract
let proj_g_pow2_64_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_64)
inline_for_extraction noextract
let proj_g_pow2_128_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_128)
inline_for_extraction noextract
let proj_g_pow2_192_list : SPTK.point_list =
normalize_term (SPTK.proj_point_to_list proj_g_pow2_192)
let proj_g_pow2_64_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64);
Seq.seq_of_list proj_g_pow2_64_list
let proj_g_pow2_128_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_128);
Seq.seq_of_list proj_g_pow2_128_list
let proj_g_pow2_192_lseq : LSeq.lseq uint64 12 =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192);
Seq.seq_of_list proj_g_pow2_192_list
val proj_g_pow2_64_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_64 == pow_point (pow2 64) g_aff)
let proj_g_pow2_64_lemma () =
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_64_lemma S.mk_p256_concrete_ops S.base_point
val proj_g_pow2_128_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_128 == pow_point (pow2 128) g_aff)
let proj_g_pow2_128_lemma () =
lemma_proj_g_pow2_128_eval ();
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_128_lemma S.mk_p256_concrete_ops S.base_point
val proj_g_pow2_192_lemma: unit ->
Lemma (S.to_aff_point proj_g_pow2_192 == pow_point (pow2 192) g_aff)
let proj_g_pow2_192_lemma () =
lemma_proj_g_pow2_192_eval ();
lemma_proj_g_pow2_128_eval ();
lemma_proj_g_pow2_64_eval ();
SPT256.a_pow2_192_lemma S.mk_p256_concrete_ops S.base_point
let proj_g_pow2_64_lseq_lemma () =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_64);
proj_g_pow2_64_lemma ();
SPTK.proj_point_to_list_lemma proj_g_pow2_64
let proj_g_pow2_128_lseq_lemma () =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_128);
proj_g_pow2_128_lemma ();
SPTK.proj_point_to_list_lemma proj_g_pow2_128
let proj_g_pow2_192_lseq_lemma () =
normalize_term_spec (SPTK.proj_point_to_list proj_g_pow2_192);
proj_g_pow2_192_lemma ();
SPTK.proj_point_to_list_lemma proj_g_pow2_192
let mk_proj_g_pow2_64 () =
createL proj_g_pow2_64_list
let mk_proj_g_pow2_128 () =
createL proj_g_pow2_128_list
let mk_proj_g_pow2_192 () =
createL proj_g_pow2_192_list
//----------------
/// window size = 4; precomputed table = [[0]G, [1]G, ..., [15]G]
inline_for_extraction noextract
let precomp_basepoint_table_list_w4: x:list uint64{FStar.List.Tot.length x = 192} =
normalize_term (SPT.precomp_base_table_list mk_p256_precomp_base_table S.base_point 15)
let precomp_basepoint_table_lseq_w4 : LSeq.lseq uint64 192 =
normalize_term_spec (SPT.precomp_base_table_list mk_p256_precomp_base_table S.base_point 15);
Seq.seq_of_list precomp_basepoint_table_list_w4
let precomp_basepoint_table_lemma_w4 () =
normalize_term_spec (SPT.precomp_base_table_list mk_p256_precomp_base_table S.base_point 15);
SPT.precomp_base_table_lemma mk_p256_precomp_base_table S.base_point 16 precomp_basepoint_table_lseq_w4 | {
"checked_file": "/",
"dependencies": [
"Spec.P256.Lemmas.fsti.checked",
"Spec.P256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.PrecompBaseTable256.fsti.checked",
"Hacl.Spec.PrecompBaseTable.fsti.checked",
"Hacl.Spec.P256.PrecompTable.fsti.checked",
"Hacl.Impl.P256.Point.fsti.checked",
"Hacl.Impl.P256.Group.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.P256.PrecompTable.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.P256.Lemmas",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.PrecompTable",
"short_module": "SPTK"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable256",
"short_module": "SPT256"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "LE"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Group",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.P256.Point",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Spec.P256.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Spec.P256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompBaseTable",
"short_module": "SPT"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.P256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | x:
Lib.Buffer.glbuffer Lib.IntTypes.uint64 192ul
{ Lib.Buffer.witnessed x Hacl.P256.PrecompTable.precomp_basepoint_table_lseq_w4 /\
Lib.Buffer.recallable x } | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.createL_global",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Hacl.P256.PrecompTable.precomp_basepoint_table_list_w4",
"Lib.Buffer.glbuffer",
"Lib.IntTypes.size",
"FStar.Pervasives.normalize_term",
"Lib.IntTypes.size_nat",
"FStar.List.Tot.Base.length",
"Lib.IntTypes.uint64",
"FStar.UInt32.__uint_to_t",
"Prims.l_and",
"Lib.Buffer.witnessed",
"Hacl.P256.PrecompTable.precomp_basepoint_table_lseq_w4",
"Lib.Buffer.recallable",
"Lib.Buffer.CONST"
] | [] | false | false | false | false | false | let precomp_basepoint_table_w4:x:
glbuffer uint64 192ul {witnessed x precomp_basepoint_table_lseq_w4 /\ recallable x} =
| createL_global precomp_basepoint_table_list_w4 | false |
Vale.Transformers.BoundedInstructionEffects.fst | Vale.Transformers.BoundedInstructionEffects.lemma_instr_apply_eval_inouts_same_read | val lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures
((instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) | val lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures
((instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) | let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures (
(instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
match inouts with
| [] ->
lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i)::inouts ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set1 inouts args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2 | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.BoundedInstructionEffects.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 347,
"start_col": 0,
"start_line": 305
} | module Vale.Transformers.BoundedInstructionEffects
open Vale.X64.Bytes_Code_s
open Vale.X64.Instruction_s
open Vale.X64.Instructions_s
open Vale.X64.Machine_Semantics_s
open Vale.X64.Machine_s
open Vale.X64.Print_s
open Vale.Def.PossiblyMonad
open Vale.Transformers.Locations
friend Vale.Transformers.Locations
module L = FStar.List.Tot
let locations_of_maddr (m:maddr) (mem:location) : locations =
mem :: (
match m with
| MConst _ -> []
| MReg r _ -> [ALocReg r]
| MIndex b _ i _ -> [ALocReg b; ALocReg i]
)
let locations_of_operand64 (o:operand64) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 0 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_operand128 (o:operand128) : locations & locations =
match o with
| OConst _ -> [], []
| OReg r -> [], [ALocReg (Reg 1 r)]
| OMem (m, _) -> locations_of_maddr m ALocMem, [ALocMem]
| OStack (m, _) -> (ALocReg (Reg 0 rRsp)) :: locations_of_maddr m ALocStack, [ALocStack]
let locations_of_explicit (t:instr_operand_explicit) (i:instr_operand_t t) : locations & locations =
match t with
| IOp64 -> locations_of_operand64 i
| IOpXmm -> locations_of_operand128 i
let locations_of_implicit (t:instr_operand_implicit) : locations & locations =
match t with
| IOp64One i -> locations_of_operand64 i
| IOpXmmOne i -> locations_of_operand128 i
| IOpFlagsCf -> [], [ALocCf]
| IOpFlagsOf -> [], [ALocOf]
let both (x: locations & locations) =
let a, b = x in
a `L.append` b
let rec aux_read_set0 (args:list instr_operand) (oprs:instr_operands_t_args args) : locations =
match args with
| [] -> []
| (IOpEx i) :: args ->
let l, r = coerce #(instr_operand_t i & instr_operands_t_args args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set0 args r
| (IOpIm i) :: args ->
both (locations_of_implicit i) `L.append` aux_read_set0 args (coerce #(instr_operands_t_args args) oprs)
let rec aux_read_set1
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> aux_read_set0 args oprs
| (Out, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
fst (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (InOut, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
both (locations_of_explicit i l) `L.append` aux_read_set1 outs args r
| (Out, IOpIm i) :: outs ->
fst (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
| (InOut, IOpIm i) :: outs ->
both (locations_of_implicit i) `L.append` aux_read_set1 outs args (coerce #(instr_operands_t outs args) oprs)
let read_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations =
aux_read_set1 i.outs i.args oprs
let rec aux_write_set
(outs:list instr_out) (args:list instr_operand) (oprs:instr_operands_t outs args) : locations =
match outs with
| [] -> []
| (_, IOpEx i) :: outs ->
let l, r = coerce #(instr_operand_t i & instr_operands_t outs args) oprs in
snd (locations_of_explicit i l) `L.append` aux_write_set outs args r
| (_, IOpIm i) :: outs ->
snd (locations_of_implicit i) `L.append` aux_write_set outs args (coerce #(instr_operands_t outs args) oprs)
let write_set (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : list location =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
let ws = aux_write_set outs args oprs in
match havoc_flags with
| HavocFlags -> ALocCf :: ALocOf :: ws
| PreserveFlags -> ws
let constant_writes (i:instr_t_record) (oprs:instr_operands_t i.outs i.args) : locations_with_values =
let InstrTypeRecord #outs #args #havoc_flags _ = i in
match havoc_flags with
| HavocFlags -> (
let ws = aux_write_set outs args oprs in
let cr = [] in
let cr = if L.mem ALocCf ws then cr else (| ALocCf, None |) :: cr in
let cr = if L.mem ALocOf ws then cr else (| ALocOf, None |) :: cr in
cr
)
| PreserveFlags -> []
(* See fsti *)
let rw_set_of_ins i =
match i with
| Instr i oprs _ ->
{
loc_reads = read_set i oprs;
loc_writes = write_set i oprs;
loc_constant_writes = constant_writes i oprs;
}
| Push src t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: both (locations_of_operand64 src);
loc_writes = [ALocReg (Reg 0 rRsp); ALocStack];
loc_constant_writes = [];
}
| Pop dst t ->
{
loc_reads = ALocReg (Reg 0 rRsp) :: ALocStack :: fst (locations_of_operand64 dst);
loc_writes = ALocReg (Reg 0 rRsp) :: snd (locations_of_operand64 dst);
loc_constant_writes = [];
}
| Alloc _ ->
{
loc_reads = [ALocReg (Reg 0 rRsp)];
loc_writes = [ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
| Dealloc _ ->
{
loc_reads = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_writes = [ALocStack; ALocReg (Reg 0 rRsp)];
loc_constant_writes = [];
}
(* See fsti *)
let locations_of_ocmp o =
match o with
| OEq o1 o2
| ONe o1 o2
| OLe o1 o2
| OGe o1 o2
| OLt o1 o2
| OGt o1 o2 ->
both (locations_of_operand64 o1) `L.append` both (locations_of_operand64 o2)
#push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
#restart-solver
let rec lemma_instr_write_outputs_only_affects_write
(outs:list instr_out) (args:list instr_operand)
(vs:instr_ret_t outs) (oprs:instr_operands_t outs args) (s_orig s:machine_state)
(a:location) :
Lemma
(requires (
let w = aux_write_set outs args oprs in
!!(disjoint_location_from_locations a w)))
(ensures (
(eval_location a s == eval_location a (instr_write_outputs outs args vs oprs s_orig s)))) =
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 s = instr_write_output_explicit i v (fst oprs) s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (snd oprs) s_orig s a
| IOpIm i ->
let s = instr_write_output_implicit i v s_orig s in
lemma_instr_write_outputs_only_affects_write outs args vs (coerce oprs) s_orig s a
)
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2 --initial_ifuel 1 --max_ifuel 1"
let lemma_eval_instr_only_affects_write
(it:instr_t_record) (oprs:instr_operands_t it.outs it.args) (ann:instr_annotation it)
(s0:machine_state)
(a:location) :
Lemma
(requires (
(let w = (rw_set_of_ins (Instr it oprs ann)).loc_writes in
!!(disjoint_location_from_locations a w) /\
(Some? (eval_instr it oprs ann s0)))))
(ensures (
(eval_location a s0 == eval_location a (Some?.v (eval_instr it oprs ann s0))))) =
let InstrTypeRecord #outs #args #havoc_flags' i = it in
let vs = instr_apply_eval outs args (instr_eval i) oprs s0 in
let s1 =
match havoc_flags' with
| HavocFlags -> {s0 with ms_flags = havoc_flags}
| PreserveFlags -> s0
in
let Some vs = vs in
let _ = instr_write_outputs outs args vs oprs s0 s1 in
lemma_instr_write_outputs_only_affects_write outs args vs oprs s0 s1 a
#pop-options
let lemma_machine_eval_ins_st_only_affects_write_aux (i:ins{Instr? i}) (s:machine_state) (a:location) :
Lemma
(requires (
let w = (rw_set_of_ins i).loc_writes in
(!!(disjoint_location_from_locations a w))))
(ensures (
(eval_location a s == eval_location a (run (machine_eval_ins_st i) s)))) =
let Instr it oprs ann = i in
match eval_instr it oprs ann s with
| Some _ -> lemma_eval_instr_only_affects_write it oprs ann s a
| None -> ()
let lemma_machine_eval_ins_st_only_affects_write (i:ins{Instr? i}) (s:machine_state) :
Lemma
(ensures (
(let w = (rw_set_of_ins i).loc_writes in
(unchanged_except w s (run (machine_eval_ins_st i) s))))) =
FStar.Classical.forall_intro (
FStar.Classical.move_requires (lemma_machine_eval_ins_st_only_affects_write_aux i s))
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_explicit_same_read_both
(i:instr_operand_explicit) (o:instr_operand_t i)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_explicit i o)) s1 s2)))
(ensures (
(instr_eval_operand_explicit i o s1) ==
(instr_eval_operand_explicit i o s2))) = ()
#pop-options
#push-options "--initial_fuel 4 --max_fuel 4 --initial_ifuel 2 --max_ifuel 2"
let lemma_instr_eval_operand_implicit_same_read_both
(i:instr_operand_implicit)
(s1 s2:machine_state) :
Lemma
(requires (
(unchanged_at (both (locations_of_implicit i)) s1 s2)))
(ensures (
(instr_eval_operand_implicit i s1) ==
(instr_eval_operand_implicit i s2))) = ()
#pop-options
let rec lemma_unchanged_at_append (l1 l2:locations) (s1 s2:machine_state) :
Lemma
(ensures (
(unchanged_at (l1 `L.append` l2) s1 s2) <==>
(unchanged_at l1 s1 s2 /\ unchanged_at l2 s1 s2))) =
match l1 with
| [] -> ()
| x :: xs ->
lemma_unchanged_at_append xs l2 s1 s2
let rec lemma_instr_apply_eval_args_same_read
(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 (unchanged_at (aux_read_set0 args oprs) s1 s2))
(ensures (
(instr_apply_eval_args outs args f oprs s1) ==
(instr_apply_eval_args outs args f oprs s2))) =
match args with
| [] -> ()
| i :: args ->
let (v1, v2, oprs) : option _ & option _ & instr_operands_t_args args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs))) (aux_read_set0 args (snd oprs)) s1 s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_implicit i)) (aux_read_set0 args oprs) s1 s2;
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1,
instr_eval_operand_implicit i s2,
coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_args_t outs args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_args outs args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_args outs args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v ->
lemma_instr_apply_eval_args_same_read outs args (f v) oprs s1 s2 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Print_s.fst.checked",
"Vale.X64.Machine_Semantics_s.fst.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Instructions_s.fsti.checked",
"Vale.X64.Instruction_s.fsti.checked",
"Vale.X64.Bytes_Code_s.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Transformers.Locations.fst.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Option.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Transformers.BoundedInstructionEffects.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Print_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instructions_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Instruction_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Vale.Transformers.Locations",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_Semantics_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Bytes_Code_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 6,
"initial_ifuel": 2,
"max_fuel": 6,
"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": 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": 25,
"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.Machine_Semantics_s.machine_state ->
s2: Vale.X64.Machine_Semantics_s.machine_state
-> FStar.Pervasives.Lemma
(requires
Vale.Transformers.BoundedInstructionEffects.unchanged_at (Vale.Transformers.BoundedInstructionEffects.aux_read_set1
inouts
args
oprs)
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.Machine_Semantics_s.machine_state",
"Vale.Transformers.BoundedInstructionEffects.lemma_instr_apply_eval_args_same_read",
"Vale.Transformers.BoundedInstructionEffects.lemma_instr_apply_eval_inouts_same_read",
"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.instr_ret_t",
"Vale.X64.Machine_Semantics_s.bind_option",
"Vale.X64.Machine_Semantics_s.instr_apply_eval_inouts",
"Vale.X64.Instruction_s.arrow",
"Prims._assert",
"Prims.eq2",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"Vale.X64.Machine_Semantics_s.instr_eval_operand_explicit",
"FStar.Pervasives.Native.fst",
"Vale.Transformers.BoundedInstructionEffects.lemma_instr_eval_operand_explicit_same_read_both",
"Vale.Transformers.BoundedInstructionEffects.lemma_unchanged_at_append",
"Vale.Transformers.BoundedInstructionEffects.both",
"Vale.Transformers.BoundedInstructionEffects.locations_of_explicit",
"Vale.Transformers.BoundedInstructionEffects.aux_read_set1",
"Vale.X64.Machine_Semantics_s.instr_eval_operand_implicit",
"Vale.Transformers.BoundedInstructionEffects.lemma_instr_eval_operand_implicit_same_read_both",
"Vale.Transformers.BoundedInstructionEffects.unchanged_at",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_instr_apply_eval_inouts_same_read
(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 (unchanged_at (aux_read_set1 inouts args oprs) s1 s2))
(ensures
((instr_apply_eval_inouts outs inouts args f oprs s1) ==
(instr_apply_eval_inouts outs inouts args f oprs s2))) =
| match inouts with
| [] -> lemma_instr_apply_eval_args_same_read 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_instr_apply_eval_inouts_same_read outs inouts args (coerce f) oprs s1 s2
| (InOut, i) :: inouts ->
let v1, v2, oprs:option _ & option _ & instr_operands_t inouts args =
match i with
| IOpEx i ->
let oprs = coerce oprs in
lemma_unchanged_at_append (both (locations_of_explicit i (fst oprs)))
(aux_read_set1 inouts args (snd oprs))
s1
s2;
lemma_instr_eval_operand_explicit_same_read_both i (fst oprs) s1 s2;
(instr_eval_operand_explicit i (fst oprs) s1,
instr_eval_operand_explicit i (fst oprs) s2,
snd oprs)
| IOpIm i ->
lemma_instr_eval_operand_implicit_same_read_both i s1 s2;
(instr_eval_operand_implicit i s1, instr_eval_operand_implicit i s2, coerce oprs)
in
assert (v1 == v2);
let f:arrow (instr_val_t i) (instr_inouts_t outs inouts args) = coerce f in
let _ = bind_option v1 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s1) in
let _ = bind_option v2 (fun v -> instr_apply_eval_inouts outs inouts args (f v) oprs s2) in
match v1 with
| None -> ()
| Some v -> lemma_instr_apply_eval_inouts_same_read outs inouts args (f v) oprs s1 s2 | false |
PulseCore.InstantiatedSemantics.fsti | PulseCore.InstantiatedSemantics.slprop_post_equiv | val slprop_post_equiv (#a: _) (p q: (a -> slprop)) : prop | val slprop_post_equiv (#a: _) (p q: (a -> slprop)) : prop | let slprop_post_equiv #a (p q:a -> slprop)
: prop
= forall x. slprop_equiv (p x) (q x) | {
"file_name": "lib/pulse_core/PulseCore.InstantiatedSemantics.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 36,
"end_line": 56,
"start_col": 0,
"start_line": 54
} | module PulseCore.InstantiatedSemantics
[@@erasable]
val slprop : Type u#2
val emp : slprop
val pure (p:prop) : slprop
val ( ** ) (p q : slprop) : slprop
val ( exists* ) (#a:Type u#a) (p: a -> slprop) : slprop
val slprop_equiv (p q:slprop) : prop
val slprop_equiv_refl (p:slprop)
: slprop_equiv p p
val slprop_equiv_elim (p q:slprop)
: Lemma (p `slprop_equiv` q <==> p==q)
val slprop_equiv_unit (x:slprop)
: slprop_equiv (emp ** x) x
val slprop_equiv_comm (p1 p2:slprop)
: slprop_equiv (p1 ** p2) (p2 ** p1)
val slprop_equiv_assoc (p1 p2 p3:slprop)
: slprop_equiv (p1 ** p2 ** p3) (p1 ** (p2 ** p3))
val slprop_equiv_exists
(#a:Type)
(p q: a -> slprop)
(_:squash (forall x. slprop_equiv (p x) (q x)))
: slprop_equiv (op_exists_Star p) (op_exists_Star q)
val stt (a:Type u#a)
(pre:slprop)
(post:a -> slprop)
: Type0
val return (#a:Type u#a) (x:a) (p:a -> slprop)
: stt a (p x) p
val bind
(#a:Type u#a) (#b:Type u#b)
(#pre1:slprop) (#post1:a -> slprop) (#post2:b -> slprop)
(e1:stt a pre1 post1)
(e2:(x:a -> stt b (post1 x) post2))
: stt b pre1 post2
val frame
(#a:Type u#a)
(#pre:slprop) (#post:a -> slprop)
(frame:slprop)
(e:stt a pre post)
: stt a (pre ** frame) (fun x -> post x ** frame) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "PulseCore.InstantiatedSemantics.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "PulseCore.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "PulseCore.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "PulseCore.Semantics",
"short_module": "Sem"
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: (_: a -> PulseCore.InstantiatedSemantics.slprop) ->
q: (_: a -> PulseCore.InstantiatedSemantics.slprop)
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"PulseCore.InstantiatedSemantics.slprop",
"Prims.l_Forall",
"PulseCore.InstantiatedSemantics.slprop_equiv",
"Prims.prop"
] | [] | false | false | false | true | true | let slprop_post_equiv #a (p: (a -> slprop)) (q: (a -> slprop)) : prop =
| forall x. slprop_equiv (p x) (q x) | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.