file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Vale.Stdcalls.X64.GCMencryptOpt.fst | Vale.Stdcalls.X64.GCMencryptOpt.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.GCMencryptOpt.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 32,
"start_col": 0,
"start_line": 32
} | module Vale.Stdcalls.X64.GCMencryptOpt
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
open FStar.Mul
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
module GC = Vale.AES.X64.GCMencryptOpt
open Vale.AES.AES_s
open Vale.AES.GCM_s
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.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"Vale.AES.X64.GCMencryptOpt.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.GCMencryptOpt.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AES.X64.GCMencryptOpt",
"short_module": "GC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"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.Stdcalls.X64.GCMencryptOpt.fst | Vale.Stdcalls.X64.GCMencryptOpt.gcm128_pre | val gcm128_pre: (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE)
-> VSig.vale_pre dom | val gcm128_pre: (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE)
-> VSig.vale_pre dom | let gcm128_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s) | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCMencryptOpt.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 74,
"end_line": 87,
"start_col": 0,
"start_line": 56
} | module Vale.Stdcalls.X64.GCMencryptOpt
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
open FStar.Mul
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
module GC = Vale.AES.X64.GCMencryptOpt
open Vale.AES.AES_s
open Vale.AES.GCM_s
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b128 = buf_t TUInt8 TUInt128
[@__reduce__] noextract
let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq
[@__reduce__] noextract
let t128_mod_pub = TD_Buffer TUInt8 TUInt128 ({modified=true; strict_disjointness=false; taint=MS.Public})
[@__reduce__] noextract
let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let (dom: list td{List.length dom <= 20}) =
let y = [t128_no_mod; tuint64; tuint64; t128_no_mod; t128_mod_pub; t128_no_mod;
t128_no_mod; t128_no_mod; t128_mod; tuint64; t128_no_mod; t128_mod; tuint64; t128_mod; tuint64; t128_mod; t128_mod] in
assert_norm (List.length y = 17);
y
(* Need to rearrange the order of arguments *) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"Vale.AES.X64.GCMencryptOpt.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.GCMencryptOpt.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AES.X64.GCMencryptOpt",
"short_module": "GC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Words_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Vale.AsLowStar.ValeSig.vale_pre Vale.Stdcalls.X64.GCMencryptOpt.dom | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCM_s.supported_iv_LE",
"Vale.X64.Decls.va_code",
"Vale.Stdcalls.X64.GCMencryptOpt.b128",
"Vale.Stdcalls.X64.GCMencryptOpt.uint64",
"Vale.X64.Decls.va_state",
"Vale.AES.X64.GCMencryptOpt.va_req_Gcm_blocks_stdcall",
"Vale.Interop.Assumptions.win",
"Vale.AES.AES_common_s.AES_128",
"Vale.X64.MemoryAdapters.as_vale_buffer",
"Vale.Arch.HeapTypes_s.TUInt8",
"Vale.Arch.HeapTypes_s.TUInt128",
"FStar.UInt64.v",
"FStar.Ghost.reveal",
"Prims.prop"
] | [] | false | false | false | true | false | let gcm128_pre: (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE)
-> VSig.vale_pre dom =
| fun
(s: Ghost.erased (Seq.seq nat32))
(iv: Ghost.erased supported_iv_LE)
(c: V.va_code)
(auth_b: b128)
(auth_bytes: uint64)
(auth_num: uint64)
(keys_b: b128)
(iv_b: b128)
(hkeys_b: b128)
(abytes_b: b128)
(in128x6_b: b128)
(out128x6_b: b128)
(len128x6_num: uint64)
(in128_b: b128)
(out128_b: b128)
(len128_num: uint64)
(inout_b: b128)
(plain_num: uint64)
(scratch_b: b128)
(tag_b: b128)
(va_s0: V.va_state)
->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_128 (as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b) (as_vale_buffer iv_b) (Ghost.reveal iv)
(as_vale_buffer hkeys_b) (as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num) (as_vale_buffer in128_b)
(as_vale_buffer out128_b) (UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s) | false |
Vale.Stdcalls.X64.GCMencryptOpt.fst | Vale.Stdcalls.X64.GCMencryptOpt.lowstar_gcm128 | val lowstar_gcm128 (s: Ghost.erased (Seq.seq nat32)) (iv: Ghost.erased supported_iv_LE)
: lowstar_gcm128_t s iv | val lowstar_gcm128 (s: Ghost.erased (Seq.seq nat32)) (iv: Ghost.erased supported_iv_LE)
: lowstar_gcm128_t s iv | let lowstar_gcm128 (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) : lowstar_gcm128_t s iv =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.wrap_weak_stdcall
code_gcm128
dom
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win)) | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCMencryptOpt.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 81,
"end_line": 224,
"start_col": 0,
"start_line": 219
} | module Vale.Stdcalls.X64.GCMencryptOpt
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
open FStar.Mul
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
module GC = Vale.AES.X64.GCMencryptOpt
open Vale.AES.AES_s
open Vale.AES.GCM_s
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b128 = buf_t TUInt8 TUInt128
[@__reduce__] noextract
let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq
[@__reduce__] noextract
let t128_mod_pub = TD_Buffer TUInt8 TUInt128 ({modified=true; strict_disjointness=false; taint=MS.Public})
[@__reduce__] noextract
let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let (dom: list td{List.length dom <= 20}) =
let y = [t128_no_mod; tuint64; tuint64; t128_no_mod; t128_mod_pub; t128_no_mod;
t128_no_mod; t128_no_mod; t128_mod; tuint64; t128_no_mod; t128_mod; tuint64; t128_mod; tuint64; t128_mod; t128_mod] in
assert_norm (List.length y = 17);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm128_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
[@__reduce__] noextract
let gcm128_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f
#set-options "--z3rlimit 50"
[@__reduce__] noextract
let gcm128_lemma'
(s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(code:V.va_code)
(_win:bool)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm128_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\
gcm128_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\
ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\
ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b)
)) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f
(* Prove that gcm128_lemma' has the required type *)
noextract
let gcm128_lemma (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = as_t #(VSig.vale_sig_stdcall (gcm128_pre s iv) (gcm128_post s iv)) (gcm128_lemma' s iv)
noextract
let code_gcm128 = GC.va_code_Gcm_blocks_stdcall IA.win AES_128
(* Here's the type expected for the gcm wrapper *)
[@__reduce__] noextract
let lowstar_gcm128_t (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.as_lowstar_sig_t_weak_stdcall
code_gcm128
dom
[]
_
_
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win))
(* And here's the gcm wrapper itself *) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"Vale.AES.X64.GCMencryptOpt.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.GCMencryptOpt.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AES.X64.GCMencryptOpt",
"short_module": "GC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Vale.Stdcalls.X64.GCMencryptOpt.lowstar_gcm128_t s iv | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCM_s.supported_iv_LE",
"Vale.Interop.X64.wrap_weak_stdcall",
"Vale.Stdcalls.X64.GCMencryptOpt.code_gcm128",
"Vale.Stdcalls.X64.GCMencryptOpt.dom",
"Vale.AsLowStar.Wrapper.pre_rel_generic",
"Vale.Interop.X64.max_stdcall",
"Vale.Interop.X64.arg_reg_stdcall",
"Prims.Nil",
"Vale.Interop.Base.arg",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm128_pre",
"Vale.AsLowStar.Wrapper.post_rel_generic",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm128_post",
"Vale.AsLowStar.Wrapper.mk_prediction",
"Vale.Interop.X64.regs_modified_stdcall",
"Vale.Interop.X64.xmms_modified_stdcall",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm128_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",
"Vale.Stdcalls.X64.GCMencryptOpt.lowstar_gcm128_t"
] | [] | false | false | false | false | false | let lowstar_gcm128 (s: Ghost.erased (Seq.seq nat32)) (iv: Ghost.erased supported_iv_LE)
: lowstar_gcm128_t s iv =
| assert_norm (List.length dom + List.length ([] <: list arg) <= 20);
IX64.wrap_weak_stdcall code_gcm128
dom
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win)) | false |
Vale.Stdcalls.X64.GCMencryptOpt.fst | Vale.Stdcalls.X64.GCMencryptOpt.gcm128_post | val gcm128_post: Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE)
-> VSig.vale_post dom | val gcm128_post: Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE)
-> VSig.vale_post dom | let gcm128_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCMencryptOpt.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 123,
"start_col": 0,
"start_line": 90
} | module Vale.Stdcalls.X64.GCMencryptOpt
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
open FStar.Mul
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
module GC = Vale.AES.X64.GCMencryptOpt
open Vale.AES.AES_s
open Vale.AES.GCM_s
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b128 = buf_t TUInt8 TUInt128
[@__reduce__] noextract
let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq
[@__reduce__] noextract
let t128_mod_pub = TD_Buffer TUInt8 TUInt128 ({modified=true; strict_disjointness=false; taint=MS.Public})
[@__reduce__] noextract
let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let (dom: list td{List.length dom <= 20}) =
let y = [t128_no_mod; tuint64; tuint64; t128_no_mod; t128_mod_pub; t128_no_mod;
t128_no_mod; t128_no_mod; t128_mod; tuint64; t128_no_mod; t128_mod; tuint64; t128_mod; tuint64; t128_mod; t128_mod] in
assert_norm (List.length y = 17);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm128_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"Vale.AES.X64.GCMencryptOpt.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.GCMencryptOpt.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AES.X64.GCMencryptOpt",
"short_module": "GC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Words_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Vale.AsLowStar.ValeSig.vale_post Vale.Stdcalls.X64.GCMencryptOpt.dom | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCM_s.supported_iv_LE",
"Vale.X64.Decls.va_code",
"Vale.Stdcalls.X64.GCMencryptOpt.b128",
"Vale.Stdcalls.X64.GCMencryptOpt.uint64",
"Vale.X64.Decls.va_state",
"Vale.X64.Decls.va_fuel",
"Vale.AES.X64.GCMencryptOpt.va_ens_Gcm_blocks_stdcall",
"Vale.Interop.Assumptions.win",
"Vale.AES.AES_common_s.AES_128",
"Vale.X64.MemoryAdapters.as_vale_buffer",
"Vale.Arch.HeapTypes_s.TUInt8",
"Vale.Arch.HeapTypes_s.TUInt128",
"FStar.UInt64.v",
"FStar.Ghost.reveal",
"Prims.prop"
] | [] | false | false | false | true | false | let gcm128_post: Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE)
-> VSig.vale_post dom =
| fun
(s: Ghost.erased (Seq.seq nat32))
(iv: Ghost.erased supported_iv_LE)
(c: V.va_code)
(auth_b: b128)
(auth_bytes: uint64)
(auth_num: uint64)
(keys_b: b128)
(iv_b: b128)
(hkeys_b: b128)
(abytes_b: b128)
(in128x6_b: b128)
(out128x6_b: b128)
(len128x6_num: uint64)
(in128_b: b128)
(out128_b: b128)
(len128_num: uint64)
(inout_b: b128)
(plain_num: uint64)
(scratch_b: b128)
(tag_b: b128)
(va_s0: V.va_state)
(va_s1: V.va_state)
(f: V.va_fuel)
->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_128 (as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b) (as_vale_buffer iv_b) (Ghost.reveal iv)
(as_vale_buffer hkeys_b) (as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num) (as_vale_buffer in128_b)
(as_vale_buffer out128_b) (UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s) va_s1 f | false |
Vale.Stdcalls.X64.GCMencryptOpt.fst | Vale.Stdcalls.X64.GCMencryptOpt.lowstar_gcm256 | val lowstar_gcm256 (s: Ghost.erased (Seq.seq nat32)) (iv: Ghost.erased supported_iv_LE)
: lowstar_gcm256_t s iv | val lowstar_gcm256 (s: Ghost.erased (Seq.seq nat32)) (iv: Ghost.erased supported_iv_LE)
: lowstar_gcm256_t s iv | let lowstar_gcm256 (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) : lowstar_gcm256_t s iv =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.wrap_weak_stdcall
code_gcm256
dom
(W.mk_prediction code_gcm256 dom [] ((gcm256_lemma s iv) code_gcm256 IA.win)) | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCMencryptOpt.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 81,
"end_line": 396,
"start_col": 0,
"start_line": 391
} | module Vale.Stdcalls.X64.GCMencryptOpt
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
open FStar.Mul
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
module GC = Vale.AES.X64.GCMencryptOpt
open Vale.AES.AES_s
open Vale.AES.GCM_s
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b128 = buf_t TUInt8 TUInt128
[@__reduce__] noextract
let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq
[@__reduce__] noextract
let t128_mod_pub = TD_Buffer TUInt8 TUInt128 ({modified=true; strict_disjointness=false; taint=MS.Public})
[@__reduce__] noextract
let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let (dom: list td{List.length dom <= 20}) =
let y = [t128_no_mod; tuint64; tuint64; t128_no_mod; t128_mod_pub; t128_no_mod;
t128_no_mod; t128_no_mod; t128_mod; tuint64; t128_no_mod; t128_mod; tuint64; t128_mod; tuint64; t128_mod; t128_mod] in
assert_norm (List.length y = 17);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm128_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
[@__reduce__] noextract
let gcm128_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f
#set-options "--z3rlimit 50"
[@__reduce__] noextract
let gcm128_lemma'
(s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(code:V.va_code)
(_win:bool)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm128_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\
gcm128_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\
ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\
ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b)
)) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f
(* Prove that gcm128_lemma' has the required type *)
noextract
let gcm128_lemma (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = as_t #(VSig.vale_sig_stdcall (gcm128_pre s iv) (gcm128_post s iv)) (gcm128_lemma' s iv)
noextract
let code_gcm128 = GC.va_code_Gcm_blocks_stdcall IA.win AES_128
(* Here's the type expected for the gcm wrapper *)
[@__reduce__] noextract
let lowstar_gcm128_t (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.as_lowstar_sig_t_weak_stdcall
code_gcm128
dom
[]
_
_
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win))
(* And here's the gcm wrapper itself *)
noextract
let lowstar_gcm128 (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) : lowstar_gcm128_t s iv =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.wrap_weak_stdcall
code_gcm128
dom
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win))
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm256_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
[@__reduce__] noextract
let gcm256_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f
#set-options "--z3rlimit 50"
[@__reduce__] noextract
let gcm256_lemma'
(s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(code:V.va_code)
(_win:bool)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm256_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\
gcm256_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\
ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\
ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b)
)) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f
(* Prove that gcm256_lemma' has the required type *)
noextract
let gcm256_lemma (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = as_t #(VSig.vale_sig_stdcall (gcm256_pre s iv) (gcm256_post s iv)) (gcm256_lemma' s iv)
noextract
let code_gcm256 = GC.va_code_Gcm_blocks_stdcall IA.win AES_256
(* Here's the type expected for the gcm wrapper *)
[@__reduce__] noextract
let lowstar_gcm256_t (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.as_lowstar_sig_t_weak_stdcall
code_gcm256
dom
[]
_
_
(W.mk_prediction code_gcm256 dom [] ((gcm256_lemma s iv) code_gcm256 IA.win))
(* And here's the gcm wrapper itself *) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"Vale.AES.X64.GCMencryptOpt.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.GCMencryptOpt.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AES.X64.GCMencryptOpt",
"short_module": "GC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Vale.Stdcalls.X64.GCMencryptOpt.lowstar_gcm256_t s iv | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCM_s.supported_iv_LE",
"Vale.Interop.X64.wrap_weak_stdcall",
"Vale.Stdcalls.X64.GCMencryptOpt.code_gcm256",
"Vale.Stdcalls.X64.GCMencryptOpt.dom",
"Vale.AsLowStar.Wrapper.pre_rel_generic",
"Vale.Interop.X64.max_stdcall",
"Vale.Interop.X64.arg_reg_stdcall",
"Prims.Nil",
"Vale.Interop.Base.arg",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm256_pre",
"Vale.AsLowStar.Wrapper.post_rel_generic",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm256_post",
"Vale.AsLowStar.Wrapper.mk_prediction",
"Vale.Interop.X64.regs_modified_stdcall",
"Vale.Interop.X64.xmms_modified_stdcall",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm256_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",
"Vale.Stdcalls.X64.GCMencryptOpt.lowstar_gcm256_t"
] | [] | false | false | false | false | false | let lowstar_gcm256 (s: Ghost.erased (Seq.seq nat32)) (iv: Ghost.erased supported_iv_LE)
: lowstar_gcm256_t s iv =
| assert_norm (List.length dom + List.length ([] <: list arg) <= 20);
IX64.wrap_weak_stdcall code_gcm256
dom
(W.mk_prediction code_gcm256 dom [] ((gcm256_lemma s iv) code_gcm256 IA.win)) | false |
LowParse.Low.Base.fst | LowParse.Low.Base.writable | val writable (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos': nat) (h: HS.mem)
: GTot Type0 | val writable (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos': nat) (h: HS.mem)
: GTot Type0 | let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
))) | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 558,
"start_col": 0,
"start_line": 545
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: LowStar.Monotonic.Buffer.mbuffer t rrel rel ->
pos: Prims.nat ->
pos': Prims.nat ->
h: FStar.Monotonic.HyperStack.mem
-> Prims.GTot Type0 | Prims.GTot | [
"sometrivial"
] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowStar.Monotonic.Buffer.length",
"Prims.l_Forall",
"FStar.Seq.Properties.lseq",
"Prims.op_Subtraction",
"FStar.Seq.Properties.replace_subseq",
"FStar.Seq.Base.seq",
"LowStar.Monotonic.Buffer.as_seq"
] | [] | false | false | false | false | true | let writable (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos': nat) (h: HS.mem)
: GTot Type0 =
| let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==>
((forall (s1: Seq.lseq t (pos' - pos)). {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2: Seq.lseq t (pos' - pos)). {:pattern (Seq.replace_subseq s pos pos' s2)}
(Seq.replace_subseq s pos pos' s1) `rel` (Seq.replace_subseq s pos pos' s2)))) | false |
LowParse.Low.Base.fst | LowParse.Low.Base.jump_serializer | val jump_serializer
(#k #t: _)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires
(fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\ U32.v pos <= U32.v sl.len /\
(bytes_of_slice_from h sl pos) `seq_starts_with` sq))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res)) | val jump_serializer
(#k #t: _)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires
(fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\ U32.v pos <= U32.v sl.len /\
(bytes_of_slice_from h sl pos) `seq_starts_with` sq))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res)) | let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 10,
"end_line": 489,
"start_col": 0,
"start_line": 461
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s:
LowParse.Spec.Base.serializer p
{ Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } ->
j: LowParse.Low.Base.jumper p ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
x: FStar.Ghost.erased t
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.jumper",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Ghost.erased",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_exact_valid",
"FStar.Ghost.reveal",
"LowParse.Low.Base.Spec.serialize_valid_exact",
"Prims._assert",
"FStar.Seq.Base.seq",
"LowParse.Low.Base.Spec.bytes_of_slice_from_to",
"FStar.Seq.Base.slice",
"LowParse.Slice.bytes_of_slice_from",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.serialize",
"FStar.Ghost.hide",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"FStar.UInt.uint_t",
"FStar.UInt32.n",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.l_and",
"LowParse.Slice.live_slice",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.seq_starts_with",
"LowParse.Bytes.bytes",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.int",
"Prims.op_Addition"
] | [] | false | true | false | false | false | let jump_serializer
(#k #t: _)
(#p: parser k t)
(s: serializer p {k.parser_kind_subkind == Some ParserStrong})
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires
(fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\ U32.v pos <= U32.v sl.len /\
(bytes_of_slice_from h sl pos) `seq_starts_with` sq))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res)) =
| let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` (U32.uint_to_t (Ghost.reveal glen))) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') ==
Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos | false |
Vale.Stdcalls.X64.GCMencryptOpt.fst | Vale.Stdcalls.X64.GCMencryptOpt.lowstar_gcm256_t | val lowstar_gcm256_t : s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Type0 | let lowstar_gcm256_t (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.as_lowstar_sig_t_weak_stdcall
code_gcm256
dom
[]
_
_
(W.mk_prediction code_gcm256 dom [] ((gcm256_lemma s iv) code_gcm256 IA.win)) | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCMencryptOpt.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 81,
"end_line": 387,
"start_col": 0,
"start_line": 379
} | module Vale.Stdcalls.X64.GCMencryptOpt
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
open FStar.Mul
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
module GC = Vale.AES.X64.GCMencryptOpt
open Vale.AES.AES_s
open Vale.AES.GCM_s
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b128 = buf_t TUInt8 TUInt128
[@__reduce__] noextract
let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq
[@__reduce__] noextract
let t128_mod_pub = TD_Buffer TUInt8 TUInt128 ({modified=true; strict_disjointness=false; taint=MS.Public})
[@__reduce__] noextract
let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let (dom: list td{List.length dom <= 20}) =
let y = [t128_no_mod; tuint64; tuint64; t128_no_mod; t128_mod_pub; t128_no_mod;
t128_no_mod; t128_no_mod; t128_mod; tuint64; t128_no_mod; t128_mod; tuint64; t128_mod; tuint64; t128_mod; t128_mod] in
assert_norm (List.length y = 17);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm128_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
[@__reduce__] noextract
let gcm128_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f
#set-options "--z3rlimit 50"
[@__reduce__] noextract
let gcm128_lemma'
(s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(code:V.va_code)
(_win:bool)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm128_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\
gcm128_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\
ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\
ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b)
)) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f
(* Prove that gcm128_lemma' has the required type *)
noextract
let gcm128_lemma (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = as_t #(VSig.vale_sig_stdcall (gcm128_pre s iv) (gcm128_post s iv)) (gcm128_lemma' s iv)
noextract
let code_gcm128 = GC.va_code_Gcm_blocks_stdcall IA.win AES_128
(* Here's the type expected for the gcm wrapper *)
[@__reduce__] noextract
let lowstar_gcm128_t (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.as_lowstar_sig_t_weak_stdcall
code_gcm128
dom
[]
_
_
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win))
(* And here's the gcm wrapper itself *)
noextract
let lowstar_gcm128 (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) : lowstar_gcm128_t s iv =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.wrap_weak_stdcall
code_gcm128
dom
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win))
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm256_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
[@__reduce__] noextract
let gcm256_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f
#set-options "--z3rlimit 50"
[@__reduce__] noextract
let gcm256_lemma'
(s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(code:V.va_code)
(_win:bool)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm256_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\
gcm256_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\
ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\
ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b)
)) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f
(* Prove that gcm256_lemma' has the required type *)
noextract
let gcm256_lemma (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = as_t #(VSig.vale_sig_stdcall (gcm256_pre s iv) (gcm256_post s iv)) (gcm256_lemma' s iv)
noextract
let code_gcm256 = GC.va_code_Gcm_blocks_stdcall IA.win AES_256
(* Here's the type expected for the gcm 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.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"Vale.AES.X64.GCMencryptOpt.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.GCMencryptOpt.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AES.X64.GCMencryptOpt",
"short_module": "GC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCM_s.supported_iv_LE",
"Vale.Interop.X64.as_lowstar_sig_t_weak_stdcall",
"Vale.Stdcalls.X64.GCMencryptOpt.code_gcm256",
"Vale.Stdcalls.X64.GCMencryptOpt.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.GCMencryptOpt.gcm256_pre",
"Vale.AsLowStar.Wrapper.post_rel_generic",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm256_post",
"Vale.AsLowStar.Wrapper.mk_prediction",
"Vale.Interop.X64.regs_modified_stdcall",
"Vale.Interop.X64.xmms_modified_stdcall",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm256_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_gcm256_t (s: Ghost.erased (Seq.seq nat32)) (iv: Ghost.erased supported_iv_LE) =
| assert_norm (List.length dom + List.length ([] <: list arg) <= 20);
IX64.as_lowstar_sig_t_weak_stdcall code_gcm256
dom
[]
_
_
(W.mk_prediction code_gcm256 dom [] ((gcm256_lemma s iv) code_gcm256 IA.win)) | false |
|
LowParse.Low.Base.fst | LowParse.Low.Base.seq_starts_with_append_r_elim | val seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t)
: Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures
(s `seq_starts_with` s1 /\ (Seq.slice s (Seq.length s1) (Seq.length s)) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] | val seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t)
: Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures
(s `seq_starts_with` s1 /\ (Seq.slice s (Seq.length s1) (Seq.length s)) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] | let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3)) | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 61,
"end_line": 457,
"start_col": 0,
"start_line": 449
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq t -> s1: FStar.Seq.Base.seq t -> s2: FStar.Seq.Base.seq t
-> FStar.Pervasives.Lemma
(requires LowParse.Low.Base.seq_starts_with s (FStar.Seq.Base.append s1 s2))
(ensures
LowParse.Low.Base.seq_starts_with s s1 /\
LowParse.Low.Base.seq_starts_with (FStar.Seq.Base.slice s
(FStar.Seq.Base.length s1)
(FStar.Seq.Base.length s))
s2)
[SMTPat (LowParse.Low.Base.seq_starts_with s (FStar.Seq.Base.append s1 s2))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.append",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"FStar.Seq.Base.length",
"Prims.unit",
"LowParse.Low.Base.seq_starts_with",
"Prims.squash",
"Prims.l_and",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t)
: Lemma (requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures
(s `seq_starts_with` s1 /\ (Seq.slice s (Seq.length s1) (Seq.length s)) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))] =
| let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` ((s1 `Seq.append` s2) `Seq.append` s3)) | false |
LowParse.Low.Base.fst | LowParse.Low.Base.leaf_reader_ext | val leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (x: bytes -> Lemma (parse p2 x == parse p1 x)))
: Tot (leaf_reader p2) | val leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (x: bytes -> Lemma (parse p2 x == parse p1 x)))
: Tot (leaf_reader p2) | let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 12,
"end_line": 543,
"start_col": 0,
"start_line": 523
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p32: LowParse.Low.Base.leaf_reader p1 ->
p2: LowParse.Spec.Base.parser k2 t ->
lem:
(x: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures LowParse.Spec.Base.parse p2 x == LowParse.Spec.Base.parse p1 x))
-> LowParse.Low.Base.leaf_reader p2 | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.leaf_reader",
"LowParse.Bytes.bytes",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Base.parse",
"Prims.Nil",
"FStar.Pervasives.pattern",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Low.Base.Spec.valid_facts",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | false | false | false | false | let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (x: bytes -> Lemma (parse p2 x == parse p1 x)))
: Tot (leaf_reader p2) =
| fun #rrel #rel sl pos ->
let h = HST.get () in
[@@ inline_let ]let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos | false |
LowParse.Low.Base.fst | LowParse.Low.Base.read_with_comment | val read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p)
: Tot (leaf_reader p) | val read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p)
: Tot (leaf_reader p) | let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 12,
"end_line": 519,
"start_col": 0,
"start_line": 510
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Prims.string -> r: LowParse.Low.Base.leaf_reader p -> LowParse.Low.Base.leaf_reader p | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.leaf_reader",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Low.Base.comment"
] | [] | false | false | false | false | false | let read_with_comment (s: string) (#k: parser_kind) (#t: Type) (#p: parser k t) (r: leaf_reader p)
: Tot (leaf_reader p) =
| fun #rrel #rel sl pos ->
comment s;
r sl pos | false |
Vale.Stdcalls.X64.GCMencryptOpt.fst | Vale.Stdcalls.X64.GCMencryptOpt.gcm256_pre | val gcm256_pre: (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE)
-> VSig.vale_pre dom | val gcm256_pre: (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE)
-> VSig.vale_pre dom | let gcm256_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s) | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCMencryptOpt.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 74,
"end_line": 259,
"start_col": 0,
"start_line": 228
} | module Vale.Stdcalls.X64.GCMencryptOpt
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
open FStar.Mul
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
module GC = Vale.AES.X64.GCMencryptOpt
open Vale.AES.AES_s
open Vale.AES.GCM_s
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b128 = buf_t TUInt8 TUInt128
[@__reduce__] noextract
let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq
[@__reduce__] noextract
let t128_mod_pub = TD_Buffer TUInt8 TUInt128 ({modified=true; strict_disjointness=false; taint=MS.Public})
[@__reduce__] noextract
let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let (dom: list td{List.length dom <= 20}) =
let y = [t128_no_mod; tuint64; tuint64; t128_no_mod; t128_mod_pub; t128_no_mod;
t128_no_mod; t128_no_mod; t128_mod; tuint64; t128_no_mod; t128_mod; tuint64; t128_mod; tuint64; t128_mod; t128_mod] in
assert_norm (List.length y = 17);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm128_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
[@__reduce__] noextract
let gcm128_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f
#set-options "--z3rlimit 50"
[@__reduce__] noextract
let gcm128_lemma'
(s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(code:V.va_code)
(_win:bool)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm128_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\
gcm128_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\
ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\
ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b)
)) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f
(* Prove that gcm128_lemma' has the required type *)
noextract
let gcm128_lemma (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = as_t #(VSig.vale_sig_stdcall (gcm128_pre s iv) (gcm128_post s iv)) (gcm128_lemma' s iv)
noextract
let code_gcm128 = GC.va_code_Gcm_blocks_stdcall IA.win AES_128
(* Here's the type expected for the gcm wrapper *)
[@__reduce__] noextract
let lowstar_gcm128_t (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.as_lowstar_sig_t_weak_stdcall
code_gcm128
dom
[]
_
_
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win))
(* And here's the gcm wrapper itself *)
noextract
let lowstar_gcm128 (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) : lowstar_gcm128_t s iv =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.wrap_weak_stdcall
code_gcm128
dom
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win))
(* Need to rearrange the order of arguments *) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"Vale.AES.X64.GCMencryptOpt.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.GCMencryptOpt.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AES.X64.GCMencryptOpt",
"short_module": "GC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Words_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Vale.AsLowStar.ValeSig.vale_pre Vale.Stdcalls.X64.GCMencryptOpt.dom | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCM_s.supported_iv_LE",
"Vale.X64.Decls.va_code",
"Vale.Stdcalls.X64.GCMencryptOpt.b128",
"Vale.Stdcalls.X64.GCMencryptOpt.uint64",
"Vale.X64.Decls.va_state",
"Vale.AES.X64.GCMencryptOpt.va_req_Gcm_blocks_stdcall",
"Vale.Interop.Assumptions.win",
"Vale.AES.AES_common_s.AES_256",
"Vale.X64.MemoryAdapters.as_vale_buffer",
"Vale.Arch.HeapTypes_s.TUInt8",
"Vale.Arch.HeapTypes_s.TUInt128",
"FStar.UInt64.v",
"FStar.Ghost.reveal",
"Prims.prop"
] | [] | false | false | false | true | false | let gcm256_pre: (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE)
-> VSig.vale_pre dom =
| fun
(s: Ghost.erased (Seq.seq nat32))
(iv: Ghost.erased supported_iv_LE)
(c: V.va_code)
(auth_b: b128)
(auth_bytes: uint64)
(auth_num: uint64)
(keys_b: b128)
(iv_b: b128)
(hkeys_b: b128)
(abytes_b: b128)
(in128x6_b: b128)
(out128x6_b: b128)
(len128x6_num: uint64)
(in128_b: b128)
(out128_b: b128)
(len128_num: uint64)
(inout_b: b128)
(plain_num: uint64)
(scratch_b: b128)
(tag_b: b128)
(va_s0: V.va_state)
->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_256 (as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b) (as_vale_buffer iv_b) (Ghost.reveal iv)
(as_vale_buffer hkeys_b) (as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num) (as_vale_buffer in128_b)
(as_vale_buffer out128_b) (UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s) | false |
FStar.PartialMap.fsti | FStar.PartialMap.const | val const (k: eqtype) (#v: Type) (y: v) : t k v | val const (k: eqtype) (#v: Type) (y: v) : t k v | let const (k:eqtype) (#v:Type) (y:v) : t k v =
literal (fun x -> Some y) | {
"file_name": "ulib/FStar.PartialMap.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 56,
"start_col": 0,
"start_line": 55
} | (*
Copyright 2008-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: Aseem Rastogi
*)
/// A partial map, partial in the sense that selecting a key in the map may fail
/// (by returning None)
module FStar.PartialMap
/// The main map type
val t (k:eqtype) ([@@@strictly_positive] v:Type u#a) : Type u#a
/// An empty map
val empty (k:eqtype) (v:Type) : t k v
/// A constructor that constructs the map from a function
val literal (#k:eqtype) (#v:Type) (f:k -> option v) : t k v
/// Select a key from the map, may fail by returning None
val sel (#k:eqtype) (#v:Type) (m:t k v) (x:k) : option v
/// Updating a key in the map
val upd (#k:eqtype) (#v:Type) (m:t k v) (x:k) (y:v) : t k v
/// Removing a key from the map
val remove (#k:eqtype) (#v:Type) (m:t k v) (x:k) : t k v
/// Helper function to check if a key exists in the map
let contains (#k:eqtype) (#v:Type) (m:t k v) (x:k) : bool =
Some? (sel m x)
/// A constant map | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.PartialMap.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | k: Prims.eqtype -> y: v -> FStar.PartialMap.t k v | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.PartialMap.literal",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.option",
"FStar.PartialMap.t"
] | [] | false | false | false | false | false | let const (k: eqtype) (#v: Type) (y: v) : t k v =
| literal (fun x -> Some y) | false |
LowParse.Low.Base.fst | LowParse.Low.Base.writable_intro | val writable_intro:
#t: Type ->
#rrel: _ ->
#rel: _ ->
b: B.mbuffer t rrel rel ->
pos: nat ->
pos': nat ->
h: HS.mem ->
squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b) ->
f:
(s1: Seq.lseq t (pos' - pos) -> s2: Seq.lseq t (pos' - pos)
-> Lemma
(let s = B.as_seq h b in
(Seq.replace_subseq s pos pos' s1) `rel` (Seq.replace_subseq s pos pos' s2)))
-> Lemma (writable b pos pos' h) | val writable_intro:
#t: Type ->
#rrel: _ ->
#rel: _ ->
b: B.mbuffer t rrel rel ->
pos: nat ->
pos': nat ->
h: HS.mem ->
squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b) ->
f:
(s1: Seq.lseq t (pos' - pos) -> s2: Seq.lseq t (pos' - pos)
-> Lemma
(let s = B.as_seq h b in
(Seq.replace_subseq s pos pos' s1) `rel` (Seq.replace_subseq s pos pos' s2)))
-> Lemma (writable b pos pos' h) | let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 28,
"end_line": 576,
"start_col": 0,
"start_line": 560
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: LowStar.Monotonic.Buffer.mbuffer t rrel rel ->
pos: Prims.nat ->
pos': Prims.nat ->
h: FStar.Monotonic.HyperStack.mem ->
_:
Prims.squash (LowStar.Monotonic.Buffer.live h b /\ pos <= pos' /\
pos' <= LowStar.Monotonic.Buffer.length b) ->
f:
(s1: FStar.Seq.Properties.lseq t (pos' - pos) -> s2: FStar.Seq.Properties.lseq t (pos' - pos)
-> FStar.Pervasives.Lemma
(ensures
(let s = LowStar.Monotonic.Buffer.as_seq h b in
rel (FStar.Seq.Properties.replace_subseq s pos pos' s1)
(FStar.Seq.Properties.replace_subseq s pos pos' s2))))
-> FStar.Pervasives.Lemma (ensures LowParse.Low.Base.writable b pos pos' h) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"FStar.Monotonic.HyperStack.mem",
"Prims.squash",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowStar.Monotonic.Buffer.length",
"FStar.Seq.Properties.lseq",
"Prims.op_Subtraction",
"Prims.unit",
"Prims.l_True",
"FStar.Seq.Properties.replace_subseq",
"FStar.Seq.Base.seq",
"LowStar.Monotonic.Buffer.as_seq",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Classical.forall_intro_2",
"LowParse.Low.Base.writable"
] | [] | false | false | true | false | false | let writable_intro
(#t: Type)
(#rrel: _)
(#rel: _)
(b: B.mbuffer t rrel rel)
(pos: nat)
(pos': nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f:
(s1: Seq.lseq t (pos' - pos) -> s2: Seq.lseq t (pos' - pos)
-> Lemma
(let s = B.as_seq h b in
(Seq.replace_subseq s pos pos' s1) `rel` (Seq.replace_subseq s pos pos' s2))))
: Lemma (writable b pos pos' h) =
| Classical.forall_intro_2 f | false |
Vale.Stdcalls.X64.GCMencryptOpt.fst | Vale.Stdcalls.X64.GCMencryptOpt.lowstar_gcm128_t | val lowstar_gcm128_t : s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Type0 | let lowstar_gcm128_t (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.as_lowstar_sig_t_weak_stdcall
code_gcm128
dom
[]
_
_
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win)) | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCMencryptOpt.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 81,
"end_line": 215,
"start_col": 0,
"start_line": 207
} | module Vale.Stdcalls.X64.GCMencryptOpt
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
open FStar.Mul
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
module GC = Vale.AES.X64.GCMencryptOpt
open Vale.AES.AES_s
open Vale.AES.GCM_s
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b128 = buf_t TUInt8 TUInt128
[@__reduce__] noextract
let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq
[@__reduce__] noextract
let t128_mod_pub = TD_Buffer TUInt8 TUInt128 ({modified=true; strict_disjointness=false; taint=MS.Public})
[@__reduce__] noextract
let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let (dom: list td{List.length dom <= 20}) =
let y = [t128_no_mod; tuint64; tuint64; t128_no_mod; t128_mod_pub; t128_no_mod;
t128_no_mod; t128_no_mod; t128_mod; tuint64; t128_no_mod; t128_mod; tuint64; t128_mod; tuint64; t128_mod; t128_mod] in
assert_norm (List.length y = 17);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm128_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
[@__reduce__] noextract
let gcm128_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f
#set-options "--z3rlimit 50"
[@__reduce__] noextract
let gcm128_lemma'
(s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(code:V.va_code)
(_win:bool)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm128_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\
gcm128_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\
ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\
ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b)
)) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f
(* Prove that gcm128_lemma' has the required type *)
noextract
let gcm128_lemma (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = as_t #(VSig.vale_sig_stdcall (gcm128_pre s iv) (gcm128_post s iv)) (gcm128_lemma' s iv)
noextract
let code_gcm128 = GC.va_code_Gcm_blocks_stdcall IA.win AES_128
(* Here's the type expected for the gcm 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.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"Vale.AES.X64.GCMencryptOpt.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.GCMencryptOpt.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AES.X64.GCMencryptOpt",
"short_module": "GC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCM_s.supported_iv_LE",
"Vale.Interop.X64.as_lowstar_sig_t_weak_stdcall",
"Vale.Stdcalls.X64.GCMencryptOpt.code_gcm128",
"Vale.Stdcalls.X64.GCMencryptOpt.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.GCMencryptOpt.gcm128_pre",
"Vale.AsLowStar.Wrapper.post_rel_generic",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm128_post",
"Vale.AsLowStar.Wrapper.mk_prediction",
"Vale.Interop.X64.regs_modified_stdcall",
"Vale.Interop.X64.xmms_modified_stdcall",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm128_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_gcm128_t (s: Ghost.erased (Seq.seq nat32)) (iv: Ghost.erased supported_iv_LE) =
| assert_norm (List.length dom + List.length ([] <: list arg) <= 20);
IX64.as_lowstar_sig_t_weak_stdcall code_gcm128
dom
[]
_
_
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win)) | false |
|
FStar.PartialMap.fsti | FStar.PartialMap.contains | val contains (#k: eqtype) (#v: Type) (m: t k v) (x: k) : bool | val contains (#k: eqtype) (#v: Type) (m: t k v) (x: k) : bool | let contains (#k:eqtype) (#v:Type) (m:t k v) (x:k) : bool =
Some? (sel m x) | {
"file_name": "ulib/FStar.PartialMap.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 17,
"end_line": 51,
"start_col": 0,
"start_line": 50
} | (*
Copyright 2008-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: Aseem Rastogi
*)
/// A partial map, partial in the sense that selecting a key in the map may fail
/// (by returning None)
module FStar.PartialMap
/// The main map type
val t (k:eqtype) ([@@@strictly_positive] v:Type u#a) : Type u#a
/// An empty map
val empty (k:eqtype) (v:Type) : t k v
/// A constructor that constructs the map from a function
val literal (#k:eqtype) (#v:Type) (f:k -> option v) : t k v
/// Select a key from the map, may fail by returning None
val sel (#k:eqtype) (#v:Type) (m:t k v) (x:k) : option v
/// Updating a key in the map
val upd (#k:eqtype) (#v:Type) (m:t k v) (x:k) (y:v) : t k v
/// Removing a key from the map
val remove (#k:eqtype) (#v:Type) (m:t k v) (x:k) : t k v
/// Helper function to check if a key exists in the map | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.PartialMap.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | m: FStar.PartialMap.t k v -> x: k -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.eqtype",
"FStar.PartialMap.t",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.PartialMap.sel",
"Prims.bool"
] | [] | false | false | false | false | false | let contains (#k: eqtype) (#v: Type) (m: t k v) (x: k) : bool =
| Some? (sel m x) | false |
LowParse.Low.Base.fst | LowParse.Low.Base.writable_ext | val writable_ext (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos': nat) (h h': HS.mem)
: Lemma
(requires
(writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\
(B.as_seq h' b) `Seq.equal` (B.as_seq h b) /\ B.live h' b))
(ensures (writable b pos pos' h')) | val writable_ext (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos': nat) (h h': HS.mem)
: Lemma
(requires
(writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\
(B.as_seq h' b) `Seq.equal` (B.as_seq h b) /\ B.live h' b))
(ensures (writable b pos pos' h')) | let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h' | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 77,
"end_line": 676,
"start_col": 0,
"start_line": 658
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: LowStar.Monotonic.Buffer.mbuffer t rrel rel ->
pos: Prims.nat ->
pos': Prims.nat ->
h: FStar.Monotonic.HyperStack.mem ->
h': FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.writable b pos pos' h /\ pos <= pos' /\
pos' <= LowStar.Monotonic.Buffer.length b /\
FStar.Seq.Base.equal (LowStar.Monotonic.Buffer.as_seq h' b)
(LowStar.Monotonic.Buffer.as_seq h b) /\ LowStar.Monotonic.Buffer.live h' b)
(ensures LowParse.Low.Base.writable b pos pos' h') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Base.writable_replace_subseq",
"FStar.Seq.Base.slice",
"LowStar.Monotonic.Buffer.as_seq",
"Prims.unit",
"Prims.l_and",
"LowParse.Low.Base.writable",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowStar.Monotonic.Buffer.length",
"FStar.Seq.Base.equal",
"LowStar.Monotonic.Buffer.live",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let writable_ext (#t: Type) (#rrel #rel: _) (b: B.mbuffer t rrel rel) (pos pos': nat) (h h': HS.mem)
: Lemma
(requires
(writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\
(B.as_seq h' b) `Seq.equal` (B.as_seq h b) /\ B.live h' b))
(ensures (writable b pos pos' h')) =
| writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h' | false |
LowParse.Low.Base.fst | LowParse.Low.Base.accessor_compose | val accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12': accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23': accessor a23)
(sq: unit)
: Tot (accessor (gaccessor_compose a12 a23)) | val accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12': accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23': accessor a23)
(sq: unit)
: Tot (accessor (gaccessor_compose a12 a23)) | let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3 | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 6,
"end_line": 135,
"start_col": 0,
"start_line": 109
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 128,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a12': LowParse.Low.Base.accessor a12 -> a23': LowParse.Low.Base.accessor a23 -> sq: Prims.unit
-> LowParse.Low.Base.accessor (LowParse.Low.Base.Spec.gaccessor_compose a12 a23) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.Spec.clens",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Low.Base.accessor",
"Prims.unit",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.gaccessor_compose_eq",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Low.Base.Spec.slice_access_eq",
"LowParse.Low.Base.Spec.clens_compose",
"LowParse.Low.Base.Spec.gaccessor_compose",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | false | false | false | false | let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12': accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23': accessor a23)
(sq: unit)
: Tot (accessor (gaccessor_compose a12 a23)) =
| fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3 | false |
Vale.Stdcalls.X64.GCMencryptOpt.fst | Vale.Stdcalls.X64.GCMencryptOpt.gcm256_post | val gcm256_post: Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE)
-> VSig.vale_post dom | val gcm256_post: Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE)
-> VSig.vale_post dom | let gcm256_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCMencryptOpt.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 295,
"start_col": 0,
"start_line": 262
} | module Vale.Stdcalls.X64.GCMencryptOpt
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
open FStar.Mul
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
module GC = Vale.AES.X64.GCMencryptOpt
open Vale.AES.AES_s
open Vale.AES.GCM_s
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b128 = buf_t TUInt8 TUInt128
[@__reduce__] noextract
let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq
[@__reduce__] noextract
let t128_mod_pub = TD_Buffer TUInt8 TUInt128 ({modified=true; strict_disjointness=false; taint=MS.Public})
[@__reduce__] noextract
let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let (dom: list td{List.length dom <= 20}) =
let y = [t128_no_mod; tuint64; tuint64; t128_no_mod; t128_mod_pub; t128_no_mod;
t128_no_mod; t128_no_mod; t128_mod; tuint64; t128_no_mod; t128_mod; tuint64; t128_mod; tuint64; t128_mod; t128_mod] in
assert_norm (List.length y = 17);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm128_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
[@__reduce__] noextract
let gcm128_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f
#set-options "--z3rlimit 50"
[@__reduce__] noextract
let gcm128_lemma'
(s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(code:V.va_code)
(_win:bool)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm128_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\
gcm128_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\
ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\
ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b)
)) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f
(* Prove that gcm128_lemma' has the required type *)
noextract
let gcm128_lemma (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = as_t #(VSig.vale_sig_stdcall (gcm128_pre s iv) (gcm128_post s iv)) (gcm128_lemma' s iv)
noextract
let code_gcm128 = GC.va_code_Gcm_blocks_stdcall IA.win AES_128
(* Here's the type expected for the gcm wrapper *)
[@__reduce__] noextract
let lowstar_gcm128_t (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.as_lowstar_sig_t_weak_stdcall
code_gcm128
dom
[]
_
_
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win))
(* And here's the gcm wrapper itself *)
noextract
let lowstar_gcm128 (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) : lowstar_gcm128_t s iv =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.wrap_weak_stdcall
code_gcm128
dom
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win))
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm256_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"Vale.AES.X64.GCMencryptOpt.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.GCMencryptOpt.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AES.X64.GCMencryptOpt",
"short_module": "GC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Words_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Vale.AsLowStar.ValeSig.vale_post Vale.Stdcalls.X64.GCMencryptOpt.dom | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCM_s.supported_iv_LE",
"Vale.X64.Decls.va_code",
"Vale.Stdcalls.X64.GCMencryptOpt.b128",
"Vale.Stdcalls.X64.GCMencryptOpt.uint64",
"Vale.X64.Decls.va_state",
"Vale.X64.Decls.va_fuel",
"Vale.AES.X64.GCMencryptOpt.va_ens_Gcm_blocks_stdcall",
"Vale.Interop.Assumptions.win",
"Vale.AES.AES_common_s.AES_256",
"Vale.X64.MemoryAdapters.as_vale_buffer",
"Vale.Arch.HeapTypes_s.TUInt8",
"Vale.Arch.HeapTypes_s.TUInt128",
"FStar.UInt64.v",
"FStar.Ghost.reveal",
"Prims.prop"
] | [] | false | false | false | true | false | let gcm256_post: Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE)
-> VSig.vale_post dom =
| fun
(s: Ghost.erased (Seq.seq nat32))
(iv: Ghost.erased supported_iv_LE)
(c: V.va_code)
(auth_b: b128)
(auth_bytes: uint64)
(auth_num: uint64)
(keys_b: b128)
(iv_b: b128)
(hkeys_b: b128)
(abytes_b: b128)
(in128x6_b: b128)
(out128x6_b: b128)
(len128x6_num: uint64)
(in128_b: b128)
(out128_b: b128)
(len128_num: uint64)
(inout_b: b128)
(plain_num: uint64)
(scratch_b: b128)
(tag_b: b128)
(va_s0: V.va_state)
(va_s1: V.va_state)
(f: V.va_fuel)
->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_256 (as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b) (as_vale_buffer iv_b) (Ghost.reveal iv)
(as_vale_buffer hkeys_b) (as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num) (as_vale_buffer in128_b)
(as_vale_buffer out128_b) (UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s) va_s1 f | false |
LowParse.Low.Base.fst | LowParse.Low.Base.writable_replace_subseq_elim | val writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(h: HS.mem)
(sl': Seq.seq t)
: Lemma
(requires
(writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)
)
(ensures
(let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s')) | val writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(h: HS.mem)
(sl': Seq.seq t)
: Lemma
(requires
(writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)
)
(ensures
(let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s')) | let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl) | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 57,
"end_line": 623,
"start_col": 0,
"start_line": 602
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: LowStar.Monotonic.Buffer.mbuffer t rrel rel ->
pos: Prims.nat ->
pos': Prims.nat ->
h: FStar.Monotonic.HyperStack.mem ->
sl': FStar.Seq.Base.seq t
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.writable b pos pos' h /\ pos <= pos' /\
pos' <= LowStar.Monotonic.Buffer.length b /\ FStar.Seq.Base.length sl' == pos' - pos)
(ensures
(let s = LowStar.Monotonic.Buffer.as_seq h b in
let s' = FStar.Seq.Properties.replace_subseq s pos pos' sl' in
rel s s')) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"FStar.Monotonic.HyperStack.mem",
"FStar.Seq.Base.seq",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Properties.replace_subseq",
"FStar.Seq.Base.slice",
"LowStar.Monotonic.Buffer.as_seq",
"Prims.unit",
"Prims.l_and",
"LowParse.Low.Base.writable",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowStar.Monotonic.Buffer.length",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.op_Subtraction",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(h: HS.mem)
(sl': Seq.seq t)
: Lemma
(requires
(writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)
)
(ensures
(let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s')) =
| let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` (Seq.replace_subseq s pos pos' sl)) | false |
LowParse.Low.Base.fst | LowParse.Low.Base.mbuffer_upd | val mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires
(fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\ Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\ Ghost.reveal pos' <= B.length b))
(ensures
(fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v)) | val mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires
(fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\ Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\ Ghost.reveal pos' <= B.length b))
(ensures
(fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v)) | let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 14,
"end_line": 766,
"start_col": 0,
"start_line": 743
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: LowStar.Monotonic.Buffer.mbuffer t rrel rel ->
pos: FStar.Ghost.erased Prims.nat ->
pos': FStar.Ghost.erased Prims.nat ->
i: FStar.UInt32.t ->
v: t
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.Ghost.erased",
"Prims.nat",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.upd'",
"Prims.unit",
"LowStar.Monotonic.Buffer.g_upd_seq_as_seq",
"FStar.Seq.Base.upd",
"LowStar.Monotonic.Buffer.as_seq",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.g_upd_modifies_strong",
"LowParse.Low.Base.writable_upd",
"FStar.Ghost.reveal",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.l_and",
"LowParse.Low.Base.writable",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"LowStar.Monotonic.Buffer.length",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_buffer_from_to",
"FStar.UInt32.add",
"FStar.UInt32.__uint_to_t",
"Prims.eq2",
"FStar.Seq.Base.seq"
] | [] | false | true | false | false | false | let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires
(fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\ Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\ Ghost.reveal pos' <= B.length b))
(ensures
(fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v)) =
| let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v | false |
LowParse.Low.Base.fst | LowParse.Low.Base.writable_upd_seq | val writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(sl': Seq.seq t)
(h: HS.mem)
: Lemma
(requires
(writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)
)
(ensures
(let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\ writable b pos pos' (B.g_upd_seq b s' h))) | val writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(sl': Seq.seq t)
(h: HS.mem)
: Lemma
(requires
(writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)
)
(ensures
(let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\ writable b pos pos' (B.g_upd_seq b s' h))) | let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h' | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 45,
"end_line": 697,
"start_col": 0,
"start_line": 678
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: LowStar.Monotonic.Buffer.mbuffer t rrel rel ->
pos: Prims.nat ->
pos': Prims.nat ->
sl': FStar.Seq.Base.seq t ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.writable b pos pos' h /\ pos <= pos' /\
pos' <= LowStar.Monotonic.Buffer.length b /\ FStar.Seq.Base.length sl' == pos' - pos)
(ensures
(let s = LowStar.Monotonic.Buffer.as_seq h b in
let s' = FStar.Seq.Properties.replace_subseq s pos pos' sl' in
rel s s' /\
LowParse.Low.Base.writable b pos pos' (LowStar.Monotonic.Buffer.g_upd_seq b s' h))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"FStar.Seq.Base.seq",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Base.writable_replace_subseq",
"Prims.unit",
"LowStar.Monotonic.Buffer.g_upd_seq_as_seq",
"LowStar.Monotonic.Buffer.g_upd_seq",
"FStar.Seq.Properties.replace_subseq",
"LowStar.Monotonic.Buffer.as_seq",
"Prims.l_and",
"LowParse.Low.Base.writable",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowStar.Monotonic.Buffer.length",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.op_Subtraction",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(sl': Seq.seq t)
(h: HS.mem)
: Lemma
(requires
(writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos)
)
(ensures
(let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\ writable b pos pos' (B.g_upd_seq b s' h))) =
| let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h;
writable_replace_subseq b pos pos' h sl' h' | false |
LowParse.Low.Base.fst | LowParse.Low.Base.compl_t | val compl_t : t: Type -> Type | let compl_t (t: Type) = U32.t -> t -> U32.t -> Tot (B.spred byte) | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 65,
"end_line": 2008,
"start_col": 0,
"start_line": 2008
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
()
inline_for_extraction
let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len
#push-options "--z3rlimit 32 --fuel 2 --ifuel 1"
inline_for_extraction
let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
(x: Ghost.erased t) ->
HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
(#rrel_out #rel_out: _)
(sl_out : slice rrel_out rel_out)
(pos_out : U32.t)
: HST.Stack U32.t
(requires (fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\
valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out
))
(ensures (fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
//B.fresh_frame_modifies h0 h1;
let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\ (
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow
)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))
inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then begin
assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2
end else
L.append_l_nil (L.filter f (G.reveal l1))
)
;
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out'
#pop-options
#push-options "--z3rlimit 64 --fuel 2 --ifuel 1"
inline_for_extraction
let list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(i: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos' /\
U32.v i < L.length (contents_list p h sl pos pos')
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid_list p h sl pos res /\
valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos1 = BF.alloca pos 1ul in
let bk = BF.alloca 0ul 1ul in
let h2 = HST.get () in
valid_list_nil p h0 sl pos;
let _ : bool = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
let k = Seq.index (B.as_seq h bk) 0 in
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bpos1 /\
B.live h bk /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v k /\
U32.v k <= U32.v i
)
(fun h _ _ _ h' ->
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1);
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk);
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
let pos1 = Seq.index (B.as_seq h bpos1) 0 in
B.live h bpos1 /\
valid p h0 sl pos1 /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v i /\
contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)
)
(fun _ _ ->
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 ->
let k = B.index bk 0ul in
if k = i
then begin
B.upd bpos1 0ul pos1;
valid_list_cons_recip p h0 sl pos1 pos';
list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i);
valid_list_append p h0 sl pos pos1 pos' ;
assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i));
false
end else begin
B.upd bk 0ul (k `U32.add` 1ul);
let h = HST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h;
valid_list_snoc p h0 sl pos pos1;
assert (valid p h0 sl pos1);
assert (pos2 == get_valid_pos p h0 sl pos1);
assert (valid_list p h0 sl pos pos2);
list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1];
true
end
)
in
let res = B.index bpos1 0ul in
HST.pop_frame ();
res
inline_for_extraction
let list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\
valid p h sl res /\ (
let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\
f x == true /\
L.find f l == Some x
)
)))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bres = BF.alloca 0ul 1ul in
let h2 = HST.get () in
let not_found = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\
valid_list p h0 sl pos1 pos' /\
l2 == contents_list p h0 sl pos1 pos' /\
L.find f (contents_list p h0 sl pos pos') == L.find f l2
)
(fun h _ _ _ h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\ (
let res = Seq.index (B.as_seq h bres) 0 in
U32.v pos <= U32.v res /\
valid p h0 sl res /\ (
let x = contents p h0 sl res in
U32.v res + content_length p h0 sl res <= U32.v pos' /\
f x == true /\
L.find f (contents_list p h0 sl pos pos') == Some x
)))
(fun h h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun pos1 pos2 ->
if f' sl pos1
then begin
B.upd bres 0ul pos1;
false
end
else true
)
in
let res =
if not_found
then pos'
else B.index bres 0ul
in
HST.pop_frame ();
res
#pop-options
let rec list_existsb_find
(#a: Type)
(f: (a -> Tot bool))
(l: list a)
: Lemma
(L.existsb f l == Some? (L.find f l))
= match l with
| [] -> ()
| x :: q ->
if f x
then ()
else list_existsb_find f q
inline_for_extraction
noextract
let list_existsb
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack bool
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == L.existsb f (contents_list p h sl pos pos')
))
= let h = HST.get () in
list_existsb_find f (contents_list p h sl pos pos');
let posn = list_find j f f' sl pos pos' in
posn <> pos'
#push-options "--fuel 2 --ifuel 1 --z3rlimit 256 --query_stats"
inline_for_extraction
noextract
let list_flatten_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot (list t2))) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2_ res /\
contents_list p2 h' sl2 pos2_ res == y
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= let hz = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos2_ = BF.alloca pos2 1ul in
let h2 = HST.get () in
valid_list_nil p2 hz sl2 pos2;
let fits = list_fold_left_gen
p1
j1
sl1
pos1 pos1'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2))
(fun h ll lr _ ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
B.live h bpos2_ /\ (
let pos2_ = Seq.index (B.as_seq h bpos2_) 0 in
contents_list p1 h0 sl1 pos1 pos1' == ll `List.Tot.append` lr /\
valid_list p2 h sl2 pos2 pos2_ /\
contents_list p2 h sl2 pos2 pos2_ == List.Tot.flatten (List.Tot.map f ll) /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(fun h _ _ _ h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
U32.v pos2 + serialized_list_length s2 (List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1'))) > U32.v sl2.len
)
(fun h h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1l pos1r ->
let pos2_ = B.index bpos2_ 0ul in
let h = HST.get () in
writable_weaken sl2.base (U32.v pos2) (U32.v sl2.len) h (U32.v pos2_) (U32.v sl2.len);
valid_pos_frame_strong p1 h0 sl1 pos1l pos1r (loc_slice_from sl2 pos2) hz;
let res = f' pos1l pos2_ in
let fits = not (res = max_uint32) in
if fits then begin
B.upd bpos2_ 0ul res;
let h' = HST.get () in
writable_modifies sl2.base (U32.v pos2) (U32.v sl2.len) h (B.loc_region_only true (HS.get_tip h1)) h' ;
List.Tot.append_assoc (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l] (contents_list p1 h0 sl1 pos1r pos1');
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l];
valid_list_snoc p1 h0 sl1 pos1 pos1l;
valid_list_append p2 h' sl2 pos2 pos2_ res;
valid_list_nil p2 h' sl2 res;
valid_list_append p2 h' sl2 pos2_ res res
end else begin
let h' = HST.get () in
valid_list_cons p1 h0 sl1 pos1l pos1' ;
valid_list_append p1 h0 sl1 pos1 pos1l pos1' ;
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) (contents_list p1 h0 sl1 pos1l pos1');
serialized_list_length_append s2 (L.flatten (L.map f (contents_list p1 h0 sl1 pos1 pos1l))) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1l pos1')));
serialized_list_length_append s2 (f (contents p1 h0 sl1 pos1l)) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1r pos1')));
valid_list_serialized_list_length s2 h' sl2 pos2 pos2_
end;
fits
)
in
let res =
if fits
then B.index bpos2_ 0ul
else max_uint32
in
HST.pop_frame ();
res
#pop-options
#push-options "--z3rlimit 16 --query_stats"
inline_for_extraction
noextract
let list_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot t2)) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_length s2 y > U32.v sl2.len
else
valid_content_pos p2 h' sl2 pos2_ y res
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1') in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= list_map_list_flatten_map f (contents_list p1 h0 sl1 pos1 pos1');
list_flatten_map
j1
s2
(fun x -> [f x])
h0
sl1 pos1 pos1'
sl2 pos2
(fun pos1 pos2 ->
let res = f' pos1 pos2 in
let h = HST.get () in
if res = max_uint32
then begin
serialized_list_length_nil s2;
serialized_list_length_cons s2 (f (contents p1 h0 sl1 pos1)) []
end
else begin
valid_list_nil p2 h sl2 res;
valid_list_cons p2 h sl2 pos2 res
end;
res
)
(* Example: trivial printers *)
inline_for_extraction
let print_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(print: ((#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack unit (requires (fun h -> valid p h sl pos)) (ensures (fun h _ h' -> B.modifies B.loc_none h h'))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h _ h' ->
B.modifies B.loc_none h h'
))
= let h0 = HST.get () in
list_fold_left
p
j
sl
pos pos'
h0
(Ghost.hide B.loc_none)
(fun _ _ _ _ -> True)
(fun _ _ _ _ _ -> ())
(fun pos1 _ _ _ _ ->
print sl pos1
)
(* Monotonicity *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Type -> Type | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.spred",
"LowParse.Bytes.byte"
] | [] | false | false | false | true | true | let compl_t (t: Type) =
| U32.t -> t -> U32.t -> Tot (B.spred byte) | false |
|
LowParse.Low.Base.fst | LowParse.Low.Base.writable_modifies | val writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(h: HS.mem)
(l: B.loc)
(h': HS.mem)
: Lemma
(requires
(writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\
B.modifies (l
`B.loc_union`
(B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')))
h
h' /\ B.loc_disjoint l (B.loc_buffer b))) (ensures (writable b pos pos' h')) | val writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(h: HS.mem)
(l: B.loc)
(h': HS.mem)
: Lemma
(requires
(writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\
B.modifies (l
`B.loc_union`
(B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')))
h
h' /\ B.loc_disjoint l (B.loc_buffer b))) (ensures (writable b pos pos' h')) | let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h' | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 78,
"end_line": 739,
"start_col": 0,
"start_line": 719
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl') | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: LowStar.Monotonic.Buffer.mbuffer t rrel rel ->
pos: Prims.nat ->
pos': Prims.nat ->
h: FStar.Monotonic.HyperStack.mem ->
l: LowStar.Monotonic.Buffer.loc ->
h': FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.writable b pos pos' h /\ pos <= pos' /\
pos' <= LowStar.Monotonic.Buffer.length b /\
LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_union l
(LowStar.Monotonic.Buffer.loc_buffer_from_to b
(FStar.UInt32.uint_to_t pos)
(FStar.UInt32.uint_to_t pos')))
h
h' /\ LowStar.Monotonic.Buffer.loc_disjoint l (LowStar.Monotonic.Buffer.loc_buffer b))
(ensures LowParse.Low.Base.writable b pos pos' h') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Monotonic.Buffer.loc",
"LowParse.Low.Base.writable_replace_subseq",
"FStar.Seq.Base.slice",
"LowStar.Monotonic.Buffer.as_seq",
"Prims.unit",
"LowStar.Monotonic.Buffer.modifies_buffer_from_to_elim",
"FStar.UInt32.uint_to_t",
"LowStar.Monotonic.Buffer.len",
"LowStar.Monotonic.Buffer.loc_union",
"LowStar.Monotonic.Buffer.loc_buffer_from_to",
"FStar.UInt32.__uint_to_t",
"Prims.l_and",
"LowParse.Low.Base.writable",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowStar.Monotonic.Buffer.length",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowStar.Monotonic.Buffer.loc_buffer",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(h: HS.mem)
(l: B.loc)
(h': HS.mem)
: Lemma
(requires
(writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\
B.modifies (l
`B.loc_union`
(B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')))
h
h' /\ B.loc_disjoint l (B.loc_buffer b))) (ensures (writable b pos pos' h')) =
| B.modifies_buffer_from_to_elim b
0ul
(U32.uint_to_t pos)
(l `B.loc_union` (B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')))
h
h';
B.modifies_buffer_from_to_elim b
(U32.uint_to_t pos')
(B.len b)
(l `B.loc_union` (B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')))
h
h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h' | false |
LowParse.Low.Base.fst | LowParse.Low.Base.leaf_writer_strong_of_serializer32 | val leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s) | val leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s) | let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos' | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 6,
"end_line": 931,
"start_col": 0,
"start_line": 910
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s32: LowParse.Low.Base.serializer32 s ->
u692:
Prims.squash (Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong)
-> LowParse.Low.Base.leaf_writer_strong s | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.serializer32",
"Prims.squash",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Base.parse_strong_prefix",
"LowParse.Bytes.bytes",
"LowParse.Low.Base.Spec.bytes_of_slice_from_to",
"LowParse.Slice.bytes_of_slice_from",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.UInt32.add",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"LowParse.Low.Base.Spec.serialized_length_eq",
"LowParse.Low.Base.leaf_writer_strong"
] | [] | false | false | false | false | false | let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s) =
| fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@@ inline_let ]let pos' = pos `U32.add` len in
let h = HST.get () in
[@@ inline_let ]let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos' | false |
LowParse.Low.Base.fst | LowParse.Low.Base.serializer32_of_leaf_writer_strong_constant_size | val serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u:
squash (k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz))
: Tot (serializer32 s) | val serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u:
squash (k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz))
: Tot (serializer32 s) | let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 981,
"start_col": 0,
"start_line": 957
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s32: LowParse.Low.Base.leaf_writer_strong s ->
sz: FStar.UInt32.t ->
u721:
Prims.squash (Mkparser_kind'?.parser_kind_subkind k ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
Mkparser_kind'?.parser_kind_high k ==
FStar.Pervasives.Native.Some (Mkparser_kind'?.parser_kind_low k) /\
Mkparser_kind'?.parser_kind_low k == FStar.UInt32.v sz)
-> LowParse.Low.Base.serializer32 s | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.leaf_writer_strong",
"FStar.UInt32.t",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"Prims.nat",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.srel",
"LowParse.Bytes.byte",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_exact_serialize",
"LowParse.Slice.srel_of_buffer_srel",
"LowParse.Slice.make_slice",
"FStar.UInt32.add",
"LowParse.Low.Base.Spec.valid_valid_exact",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.UInt32.sub",
"LowParse.Low.Base.Spec.serialized_length_eq",
"LowParse.Low.Base.serializer32"
] | [] | false | false | false | false | false | let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u:
squash (k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz))
: Tot (serializer32 s) =
| fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@@ inline_let ]let len = pos' `U32.sub` pos in
let h = HST.get () in
[@@ inline_let ]let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len | false |
LowParse.Low.Base.fst | LowParse.Low.Base.serialize32_ext | val serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes). parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2)) | val serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes). parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2)) | let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 39,
"end_line": 858,
"start_col": 0,
"start_line": 847
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p1: LowParse.Spec.Base.parser k1 t1 ->
s1: LowParse.Spec.Base.serializer p1 ->
s1': LowParse.Low.Base.serializer32 s1 ->
p2: LowParse.Spec.Base.parser k2 t2 ->
u659:
Prims.squash (t1 == t2 /\
(forall (input: LowParse.Bytes.bytes).
LowParse.Spec.Base.parse p1 input == LowParse.Spec.Base.parse p2 input))
-> LowParse.Low.Base.serializer32 (LowParse.Spec.Base.serialize_ext p1 s1 p2) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.serializer32",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"Prims.l_Forall",
"LowParse.Bytes.bytes",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"LowParse.Spec.Base.parse",
"LowStar.Monotonic.Buffer.srel",
"LowParse.Bytes.byte",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"LowParse.Spec.Base.serialize_ext"
] | [] | false | false | false | false | false | let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes). parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2)) =
| fun x #rrel #rel b pos -> s1' x b pos | false |
LowParse.Low.Base.fst | LowParse.Low.Base.irepr_pos | val irepr_pos
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(#s: slice rrel rel)
(#compl: compl_t t)
(x: irepr p s compl)
: Tot U32.t | val irepr_pos
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(#s: slice rrel rel)
(#compl: compl_t t)
(x: irepr p s compl)
: Tot U32.t | let irepr_pos
(#t: Type) (#k: parser_kind) (#p: parser k t) (#rrel #rel: _) (#s: slice rrel rel) (#compl: compl_t t) (x: irepr p s compl) : Tot U32.t =
IRepr?.pos x | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 14,
"end_line": 2062,
"start_col": 0,
"start_line": 2060
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
()
inline_for_extraction
let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len
#push-options "--z3rlimit 32 --fuel 2 --ifuel 1"
inline_for_extraction
let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
(x: Ghost.erased t) ->
HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
(#rrel_out #rel_out: _)
(sl_out : slice rrel_out rel_out)
(pos_out : U32.t)
: HST.Stack U32.t
(requires (fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\
valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out
))
(ensures (fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
//B.fresh_frame_modifies h0 h1;
let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\ (
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow
)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))
inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then begin
assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2
end else
L.append_l_nil (L.filter f (G.reveal l1))
)
;
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out'
#pop-options
#push-options "--z3rlimit 64 --fuel 2 --ifuel 1"
inline_for_extraction
let list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(i: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos' /\
U32.v i < L.length (contents_list p h sl pos pos')
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid_list p h sl pos res /\
valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos1 = BF.alloca pos 1ul in
let bk = BF.alloca 0ul 1ul in
let h2 = HST.get () in
valid_list_nil p h0 sl pos;
let _ : bool = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
let k = Seq.index (B.as_seq h bk) 0 in
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bpos1 /\
B.live h bk /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v k /\
U32.v k <= U32.v i
)
(fun h _ _ _ h' ->
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1);
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk);
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
let pos1 = Seq.index (B.as_seq h bpos1) 0 in
B.live h bpos1 /\
valid p h0 sl pos1 /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v i /\
contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)
)
(fun _ _ ->
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 ->
let k = B.index bk 0ul in
if k = i
then begin
B.upd bpos1 0ul pos1;
valid_list_cons_recip p h0 sl pos1 pos';
list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i);
valid_list_append p h0 sl pos pos1 pos' ;
assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i));
false
end else begin
B.upd bk 0ul (k `U32.add` 1ul);
let h = HST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h;
valid_list_snoc p h0 sl pos pos1;
assert (valid p h0 sl pos1);
assert (pos2 == get_valid_pos p h0 sl pos1);
assert (valid_list p h0 sl pos pos2);
list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1];
true
end
)
in
let res = B.index bpos1 0ul in
HST.pop_frame ();
res
inline_for_extraction
let list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\
valid p h sl res /\ (
let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\
f x == true /\
L.find f l == Some x
)
)))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bres = BF.alloca 0ul 1ul in
let h2 = HST.get () in
let not_found = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\
valid_list p h0 sl pos1 pos' /\
l2 == contents_list p h0 sl pos1 pos' /\
L.find f (contents_list p h0 sl pos pos') == L.find f l2
)
(fun h _ _ _ h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\ (
let res = Seq.index (B.as_seq h bres) 0 in
U32.v pos <= U32.v res /\
valid p h0 sl res /\ (
let x = contents p h0 sl res in
U32.v res + content_length p h0 sl res <= U32.v pos' /\
f x == true /\
L.find f (contents_list p h0 sl pos pos') == Some x
)))
(fun h h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun pos1 pos2 ->
if f' sl pos1
then begin
B.upd bres 0ul pos1;
false
end
else true
)
in
let res =
if not_found
then pos'
else B.index bres 0ul
in
HST.pop_frame ();
res
#pop-options
let rec list_existsb_find
(#a: Type)
(f: (a -> Tot bool))
(l: list a)
: Lemma
(L.existsb f l == Some? (L.find f l))
= match l with
| [] -> ()
| x :: q ->
if f x
then ()
else list_existsb_find f q
inline_for_extraction
noextract
let list_existsb
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack bool
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == L.existsb f (contents_list p h sl pos pos')
))
= let h = HST.get () in
list_existsb_find f (contents_list p h sl pos pos');
let posn = list_find j f f' sl pos pos' in
posn <> pos'
#push-options "--fuel 2 --ifuel 1 --z3rlimit 256 --query_stats"
inline_for_extraction
noextract
let list_flatten_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot (list t2))) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2_ res /\
contents_list p2 h' sl2 pos2_ res == y
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= let hz = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos2_ = BF.alloca pos2 1ul in
let h2 = HST.get () in
valid_list_nil p2 hz sl2 pos2;
let fits = list_fold_left_gen
p1
j1
sl1
pos1 pos1'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2))
(fun h ll lr _ ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
B.live h bpos2_ /\ (
let pos2_ = Seq.index (B.as_seq h bpos2_) 0 in
contents_list p1 h0 sl1 pos1 pos1' == ll `List.Tot.append` lr /\
valid_list p2 h sl2 pos2 pos2_ /\
contents_list p2 h sl2 pos2 pos2_ == List.Tot.flatten (List.Tot.map f ll) /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(fun h _ _ _ h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
U32.v pos2 + serialized_list_length s2 (List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1'))) > U32.v sl2.len
)
(fun h h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1l pos1r ->
let pos2_ = B.index bpos2_ 0ul in
let h = HST.get () in
writable_weaken sl2.base (U32.v pos2) (U32.v sl2.len) h (U32.v pos2_) (U32.v sl2.len);
valid_pos_frame_strong p1 h0 sl1 pos1l pos1r (loc_slice_from sl2 pos2) hz;
let res = f' pos1l pos2_ in
let fits = not (res = max_uint32) in
if fits then begin
B.upd bpos2_ 0ul res;
let h' = HST.get () in
writable_modifies sl2.base (U32.v pos2) (U32.v sl2.len) h (B.loc_region_only true (HS.get_tip h1)) h' ;
List.Tot.append_assoc (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l] (contents_list p1 h0 sl1 pos1r pos1');
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l];
valid_list_snoc p1 h0 sl1 pos1 pos1l;
valid_list_append p2 h' sl2 pos2 pos2_ res;
valid_list_nil p2 h' sl2 res;
valid_list_append p2 h' sl2 pos2_ res res
end else begin
let h' = HST.get () in
valid_list_cons p1 h0 sl1 pos1l pos1' ;
valid_list_append p1 h0 sl1 pos1 pos1l pos1' ;
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) (contents_list p1 h0 sl1 pos1l pos1');
serialized_list_length_append s2 (L.flatten (L.map f (contents_list p1 h0 sl1 pos1 pos1l))) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1l pos1')));
serialized_list_length_append s2 (f (contents p1 h0 sl1 pos1l)) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1r pos1')));
valid_list_serialized_list_length s2 h' sl2 pos2 pos2_
end;
fits
)
in
let res =
if fits
then B.index bpos2_ 0ul
else max_uint32
in
HST.pop_frame ();
res
#pop-options
#push-options "--z3rlimit 16 --query_stats"
inline_for_extraction
noextract
let list_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot t2)) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_length s2 y > U32.v sl2.len
else
valid_content_pos p2 h' sl2 pos2_ y res
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1') in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= list_map_list_flatten_map f (contents_list p1 h0 sl1 pos1 pos1');
list_flatten_map
j1
s2
(fun x -> [f x])
h0
sl1 pos1 pos1'
sl2 pos2
(fun pos1 pos2 ->
let res = f' pos1 pos2 in
let h = HST.get () in
if res = max_uint32
then begin
serialized_list_length_nil s2;
serialized_list_length_cons s2 (f (contents p1 h0 sl1 pos1)) []
end
else begin
valid_list_nil p2 h sl2 res;
valid_list_cons p2 h sl2 pos2 res
end;
res
)
(* Example: trivial printers *)
inline_for_extraction
let print_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(print: ((#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack unit (requires (fun h -> valid p h sl pos)) (ensures (fun h _ h' -> B.modifies B.loc_none h h'))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h _ h' ->
B.modifies B.loc_none h h'
))
= let h0 = HST.get () in
list_fold_left
p
j
sl
pos pos'
h0
(Ghost.hide B.loc_none)
(fun _ _ _ _ -> True)
(fun _ _ _ _ _ -> ())
(fun pos1 _ _ _ _ ->
print sl pos1
)
(* Monotonicity *)
inline_for_extraction
let compl_t (t: Type) = U32.t -> t -> U32.t -> Tot (B.spred byte)
let wvalid
(#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos' : Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
: GTot prop
=
U32.v pos <= U32.v (Ghost.reveal gpos') /\
U32.v (Ghost.reveal gpos') <= U32.v s.len /\
U32.v s.len <= Seq.length x /\
parse p (Seq.slice x (U32.v pos) (U32.v s.len)) == Some (Ghost.reveal gv, U32.v (Ghost.reveal gpos') - U32.v pos) /\
compl pos (Ghost.reveal gv) (Ghost.reveal gpos') x
let wvalid_valid_content_pos
(#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos' : Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
(h: HS.mem)
: Lemma
(requires (
wvalid p s compl pos gpos' gv x /\
live_slice h s /\
x == B.as_seq h s.base
))
(ensures (
valid_content_pos p h s pos gv gpos'
))
=
valid_facts p h s pos
inline_for_extraction
noeq
type irepr (#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel) (compl: compl_t t) =
| IRepr:
(pos: U32.t) ->
(gpos' : Ghost.erased U32.t) ->
(gv: Ghost.erased t) ->
(irepr_correct: squash (
U32.v pos <= U32.v (Ghost.reveal gpos') /\
U32.v (Ghost.reveal gpos') <= U32.v s.len /\
B.witnessed s.base (wvalid p s compl pos gpos' gv)
)) ->
irepr p s compl | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: LowParse.Low.Base.irepr p s compl -> FStar.UInt32.t | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Low.Base.compl_t",
"LowParse.Low.Base.irepr",
"LowParse.Low.Base.__proj__IRepr__item__pos",
"FStar.UInt32.t"
] | [] | false | false | false | false | false | let irepr_pos
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(#s: slice rrel rel)
(#compl: compl_t t)
(x: irepr p s compl)
: Tot U32.t =
| IRepr?.pos x | false |
LowParse.Low.Base.fst | LowParse.Low.Base.irepr_pos' | val irepr_pos'
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(#s: slice rrel rel)
(#compl: compl_t t)
(x: irepr p s compl)
: Ghost U32.t (requires True) (ensures (fun y -> True)) | val irepr_pos'
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(#s: slice rrel rel)
(#compl: compl_t t)
(x: irepr p s compl)
: Ghost U32.t (requires True) (ensures (fun y -> True)) | let irepr_pos'
(#t: Type) (#k: parser_kind) (#p: parser k t) (#rrel #rel: _) (#s: slice rrel rel) (#compl: compl_t t) (x: irepr p s compl) : Ghost U32.t
(requires True)
(ensures (fun y -> True))
= Ghost.reveal (IRepr?.gpos' x) | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 31,
"end_line": 2068,
"start_col": 0,
"start_line": 2064
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
()
inline_for_extraction
let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len
#push-options "--z3rlimit 32 --fuel 2 --ifuel 1"
inline_for_extraction
let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
(x: Ghost.erased t) ->
HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
(#rrel_out #rel_out: _)
(sl_out : slice rrel_out rel_out)
(pos_out : U32.t)
: HST.Stack U32.t
(requires (fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\
valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out
))
(ensures (fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
//B.fresh_frame_modifies h0 h1;
let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\ (
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow
)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))
inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then begin
assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2
end else
L.append_l_nil (L.filter f (G.reveal l1))
)
;
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out'
#pop-options
#push-options "--z3rlimit 64 --fuel 2 --ifuel 1"
inline_for_extraction
let list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(i: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos' /\
U32.v i < L.length (contents_list p h sl pos pos')
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid_list p h sl pos res /\
valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos1 = BF.alloca pos 1ul in
let bk = BF.alloca 0ul 1ul in
let h2 = HST.get () in
valid_list_nil p h0 sl pos;
let _ : bool = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
let k = Seq.index (B.as_seq h bk) 0 in
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bpos1 /\
B.live h bk /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v k /\
U32.v k <= U32.v i
)
(fun h _ _ _ h' ->
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1);
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk);
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
let pos1 = Seq.index (B.as_seq h bpos1) 0 in
B.live h bpos1 /\
valid p h0 sl pos1 /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v i /\
contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)
)
(fun _ _ ->
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 ->
let k = B.index bk 0ul in
if k = i
then begin
B.upd bpos1 0ul pos1;
valid_list_cons_recip p h0 sl pos1 pos';
list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i);
valid_list_append p h0 sl pos pos1 pos' ;
assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i));
false
end else begin
B.upd bk 0ul (k `U32.add` 1ul);
let h = HST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h;
valid_list_snoc p h0 sl pos pos1;
assert (valid p h0 sl pos1);
assert (pos2 == get_valid_pos p h0 sl pos1);
assert (valid_list p h0 sl pos pos2);
list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1];
true
end
)
in
let res = B.index bpos1 0ul in
HST.pop_frame ();
res
inline_for_extraction
let list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\
valid p h sl res /\ (
let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\
f x == true /\
L.find f l == Some x
)
)))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bres = BF.alloca 0ul 1ul in
let h2 = HST.get () in
let not_found = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\
valid_list p h0 sl pos1 pos' /\
l2 == contents_list p h0 sl pos1 pos' /\
L.find f (contents_list p h0 sl pos pos') == L.find f l2
)
(fun h _ _ _ h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\ (
let res = Seq.index (B.as_seq h bres) 0 in
U32.v pos <= U32.v res /\
valid p h0 sl res /\ (
let x = contents p h0 sl res in
U32.v res + content_length p h0 sl res <= U32.v pos' /\
f x == true /\
L.find f (contents_list p h0 sl pos pos') == Some x
)))
(fun h h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun pos1 pos2 ->
if f' sl pos1
then begin
B.upd bres 0ul pos1;
false
end
else true
)
in
let res =
if not_found
then pos'
else B.index bres 0ul
in
HST.pop_frame ();
res
#pop-options
let rec list_existsb_find
(#a: Type)
(f: (a -> Tot bool))
(l: list a)
: Lemma
(L.existsb f l == Some? (L.find f l))
= match l with
| [] -> ()
| x :: q ->
if f x
then ()
else list_existsb_find f q
inline_for_extraction
noextract
let list_existsb
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack bool
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == L.existsb f (contents_list p h sl pos pos')
))
= let h = HST.get () in
list_existsb_find f (contents_list p h sl pos pos');
let posn = list_find j f f' sl pos pos' in
posn <> pos'
#push-options "--fuel 2 --ifuel 1 --z3rlimit 256 --query_stats"
inline_for_extraction
noextract
let list_flatten_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot (list t2))) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2_ res /\
contents_list p2 h' sl2 pos2_ res == y
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= let hz = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos2_ = BF.alloca pos2 1ul in
let h2 = HST.get () in
valid_list_nil p2 hz sl2 pos2;
let fits = list_fold_left_gen
p1
j1
sl1
pos1 pos1'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2))
(fun h ll lr _ ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
B.live h bpos2_ /\ (
let pos2_ = Seq.index (B.as_seq h bpos2_) 0 in
contents_list p1 h0 sl1 pos1 pos1' == ll `List.Tot.append` lr /\
valid_list p2 h sl2 pos2 pos2_ /\
contents_list p2 h sl2 pos2 pos2_ == List.Tot.flatten (List.Tot.map f ll) /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(fun h _ _ _ h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
U32.v pos2 + serialized_list_length s2 (List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1'))) > U32.v sl2.len
)
(fun h h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1l pos1r ->
let pos2_ = B.index bpos2_ 0ul in
let h = HST.get () in
writable_weaken sl2.base (U32.v pos2) (U32.v sl2.len) h (U32.v pos2_) (U32.v sl2.len);
valid_pos_frame_strong p1 h0 sl1 pos1l pos1r (loc_slice_from sl2 pos2) hz;
let res = f' pos1l pos2_ in
let fits = not (res = max_uint32) in
if fits then begin
B.upd bpos2_ 0ul res;
let h' = HST.get () in
writable_modifies sl2.base (U32.v pos2) (U32.v sl2.len) h (B.loc_region_only true (HS.get_tip h1)) h' ;
List.Tot.append_assoc (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l] (contents_list p1 h0 sl1 pos1r pos1');
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l];
valid_list_snoc p1 h0 sl1 pos1 pos1l;
valid_list_append p2 h' sl2 pos2 pos2_ res;
valid_list_nil p2 h' sl2 res;
valid_list_append p2 h' sl2 pos2_ res res
end else begin
let h' = HST.get () in
valid_list_cons p1 h0 sl1 pos1l pos1' ;
valid_list_append p1 h0 sl1 pos1 pos1l pos1' ;
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) (contents_list p1 h0 sl1 pos1l pos1');
serialized_list_length_append s2 (L.flatten (L.map f (contents_list p1 h0 sl1 pos1 pos1l))) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1l pos1')));
serialized_list_length_append s2 (f (contents p1 h0 sl1 pos1l)) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1r pos1')));
valid_list_serialized_list_length s2 h' sl2 pos2 pos2_
end;
fits
)
in
let res =
if fits
then B.index bpos2_ 0ul
else max_uint32
in
HST.pop_frame ();
res
#pop-options
#push-options "--z3rlimit 16 --query_stats"
inline_for_extraction
noextract
let list_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot t2)) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_length s2 y > U32.v sl2.len
else
valid_content_pos p2 h' sl2 pos2_ y res
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1') in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= list_map_list_flatten_map f (contents_list p1 h0 sl1 pos1 pos1');
list_flatten_map
j1
s2
(fun x -> [f x])
h0
sl1 pos1 pos1'
sl2 pos2
(fun pos1 pos2 ->
let res = f' pos1 pos2 in
let h = HST.get () in
if res = max_uint32
then begin
serialized_list_length_nil s2;
serialized_list_length_cons s2 (f (contents p1 h0 sl1 pos1)) []
end
else begin
valid_list_nil p2 h sl2 res;
valid_list_cons p2 h sl2 pos2 res
end;
res
)
(* Example: trivial printers *)
inline_for_extraction
let print_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(print: ((#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack unit (requires (fun h -> valid p h sl pos)) (ensures (fun h _ h' -> B.modifies B.loc_none h h'))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h _ h' ->
B.modifies B.loc_none h h'
))
= let h0 = HST.get () in
list_fold_left
p
j
sl
pos pos'
h0
(Ghost.hide B.loc_none)
(fun _ _ _ _ -> True)
(fun _ _ _ _ _ -> ())
(fun pos1 _ _ _ _ ->
print sl pos1
)
(* Monotonicity *)
inline_for_extraction
let compl_t (t: Type) = U32.t -> t -> U32.t -> Tot (B.spred byte)
let wvalid
(#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos' : Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
: GTot prop
=
U32.v pos <= U32.v (Ghost.reveal gpos') /\
U32.v (Ghost.reveal gpos') <= U32.v s.len /\
U32.v s.len <= Seq.length x /\
parse p (Seq.slice x (U32.v pos) (U32.v s.len)) == Some (Ghost.reveal gv, U32.v (Ghost.reveal gpos') - U32.v pos) /\
compl pos (Ghost.reveal gv) (Ghost.reveal gpos') x
let wvalid_valid_content_pos
(#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos' : Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
(h: HS.mem)
: Lemma
(requires (
wvalid p s compl pos gpos' gv x /\
live_slice h s /\
x == B.as_seq h s.base
))
(ensures (
valid_content_pos p h s pos gv gpos'
))
=
valid_facts p h s pos
inline_for_extraction
noeq
type irepr (#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel) (compl: compl_t t) =
| IRepr:
(pos: U32.t) ->
(gpos' : Ghost.erased U32.t) ->
(gv: Ghost.erased t) ->
(irepr_correct: squash (
U32.v pos <= U32.v (Ghost.reveal gpos') /\
U32.v (Ghost.reveal gpos') <= U32.v s.len /\
B.witnessed s.base (wvalid p s compl pos gpos' gv)
)) ->
irepr p s compl
inline_for_extraction
let irepr_pos
(#t: Type) (#k: parser_kind) (#p: parser k t) (#rrel #rel: _) (#s: slice rrel rel) (#compl: compl_t t) (x: irepr p s compl) : Tot U32.t =
IRepr?.pos x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: LowParse.Low.Base.irepr p s compl -> Prims.Ghost FStar.UInt32.t | Prims.Ghost | [] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Low.Base.compl_t",
"LowParse.Low.Base.irepr",
"FStar.Ghost.reveal",
"FStar.UInt32.t",
"LowParse.Low.Base.__proj__IRepr__item__gpos'",
"Prims.l_True"
] | [] | false | false | false | false | false | let irepr_pos'
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(#s: slice rrel rel)
(#compl: compl_t t)
(x: irepr p s compl)
: Ghost U32.t (requires True) (ensures (fun y -> True)) =
| Ghost.reveal (IRepr?.gpos' x) | false |
LowParse.Low.Base.fst | LowParse.Low.Base.list_existsb_find | val list_existsb_find (#a: Type) (f: (a -> Tot bool)) (l: list a)
: Lemma (L.existsb f l == Some? (L.find f l)) | val list_existsb_find (#a: Type) (f: (a -> Tot bool)) (l: list a)
: Lemma (L.existsb f l == Some? (L.find f l)) | let rec list_existsb_find
(#a: Type)
(f: (a -> Tot bool))
(l: list a)
: Lemma
(L.existsb f l == Some? (L.find f l))
= match l with
| [] -> ()
| x :: q ->
if f x
then ()
else list_existsb_find f q | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 30,
"end_line": 1706,
"start_col": 0,
"start_line": 1695
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
()
inline_for_extraction
let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len
#push-options "--z3rlimit 32 --fuel 2 --ifuel 1"
inline_for_extraction
let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
(x: Ghost.erased t) ->
HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
(#rrel_out #rel_out: _)
(sl_out : slice rrel_out rel_out)
(pos_out : U32.t)
: HST.Stack U32.t
(requires (fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\
valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out
))
(ensures (fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
//B.fresh_frame_modifies h0 h1;
let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\ (
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow
)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))
inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then begin
assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2
end else
L.append_l_nil (L.filter f (G.reveal l1))
)
;
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out'
#pop-options
#push-options "--z3rlimit 64 --fuel 2 --ifuel 1"
inline_for_extraction
let list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(i: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos' /\
U32.v i < L.length (contents_list p h sl pos pos')
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid_list p h sl pos res /\
valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos1 = BF.alloca pos 1ul in
let bk = BF.alloca 0ul 1ul in
let h2 = HST.get () in
valid_list_nil p h0 sl pos;
let _ : bool = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
let k = Seq.index (B.as_seq h bk) 0 in
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bpos1 /\
B.live h bk /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v k /\
U32.v k <= U32.v i
)
(fun h _ _ _ h' ->
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1);
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk);
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
let pos1 = Seq.index (B.as_seq h bpos1) 0 in
B.live h bpos1 /\
valid p h0 sl pos1 /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v i /\
contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)
)
(fun _ _ ->
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 ->
let k = B.index bk 0ul in
if k = i
then begin
B.upd bpos1 0ul pos1;
valid_list_cons_recip p h0 sl pos1 pos';
list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i);
valid_list_append p h0 sl pos pos1 pos' ;
assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i));
false
end else begin
B.upd bk 0ul (k `U32.add` 1ul);
let h = HST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h;
valid_list_snoc p h0 sl pos pos1;
assert (valid p h0 sl pos1);
assert (pos2 == get_valid_pos p h0 sl pos1);
assert (valid_list p h0 sl pos pos2);
list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1];
true
end
)
in
let res = B.index bpos1 0ul in
HST.pop_frame ();
res
inline_for_extraction
let list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\
valid p h sl res /\ (
let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\
f x == true /\
L.find f l == Some x
)
)))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bres = BF.alloca 0ul 1ul in
let h2 = HST.get () in
let not_found = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\
valid_list p h0 sl pos1 pos' /\
l2 == contents_list p h0 sl pos1 pos' /\
L.find f (contents_list p h0 sl pos pos') == L.find f l2
)
(fun h _ _ _ h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\ (
let res = Seq.index (B.as_seq h bres) 0 in
U32.v pos <= U32.v res /\
valid p h0 sl res /\ (
let x = contents p h0 sl res in
U32.v res + content_length p h0 sl res <= U32.v pos' /\
f x == true /\
L.find f (contents_list p h0 sl pos pos') == Some x
)))
(fun h h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun pos1 pos2 ->
if f' sl pos1
then begin
B.upd bres 0ul pos1;
false
end
else true
)
in
let res =
if not_found
then pos'
else B.index bres 0ul
in
HST.pop_frame ();
res
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: a -> Prims.bool) -> l: Prims.list a
-> FStar.Pervasives.Lemma
(ensures FStar.List.Tot.Base.existsb f l == Some? (FStar.List.Tot.Base.find f l)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.bool",
"Prims.list",
"LowParse.Low.Base.list_existsb_find",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.List.Tot.Base.existsb",
"FStar.Pervasives.Native.uu___is_Some",
"Prims.b2t",
"FStar.List.Tot.Base.find",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_existsb_find (#a: Type) (f: (a -> Tot bool)) (l: list a)
: Lemma (L.existsb f l == Some? (L.find f l)) =
| match l with
| [] -> ()
| x :: q -> if f x then () else list_existsb_find f q | false |
LowParse.Low.Base.fst | LowParse.Low.Base.writable_upd | val writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma (requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures
(let s = B.as_seq h b in
s `rel` (Seq.upd s i v) /\ writable b pos pos' (B.g_upd b i v h))) | val writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma (requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures
(let s = B.as_seq h b in
s `rel` (Seq.upd s i v) /\ writable b pos pos' (B.g_upd b i v h))) | let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl') | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 70,
"end_line": 717,
"start_col": 0,
"start_line": 699
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: LowStar.Monotonic.Buffer.mbuffer t rrel rel ->
pos: Prims.nat ->
pos': Prims.nat ->
h: FStar.Monotonic.HyperStack.mem ->
i: Prims.nat ->
v: t
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.writable b pos pos' h /\ pos <= i /\ i < pos' /\
pos' <= LowStar.Monotonic.Buffer.length b)
(ensures
(let s = LowStar.Monotonic.Buffer.as_seq h b in
rel s (FStar.Seq.Base.upd s i v) /\
LowParse.Low.Base.writable b pos pos' (LowStar.Monotonic.Buffer.g_upd b i v h))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"FStar.Monotonic.HyperStack.mem",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.upd",
"FStar.Seq.Properties.replace_subseq",
"Prims.unit",
"LowParse.Low.Base.writable_upd_seq",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.slice",
"Prims.op_Subtraction",
"LowStar.Monotonic.Buffer.as_seq",
"Prims.l_and",
"LowParse.Low.Base.writable",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"LowStar.Monotonic.Buffer.length",
"Prims.squash",
"LowStar.Monotonic.Buffer.g_upd",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma (requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures
(let s = B.as_seq h b in
s `rel` (Seq.upd s i v) /\ writable b pos pos' (B.g_upd b i v h))) =
| let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert ((Seq.upd s i v) `Seq.equal` (Seq.replace_subseq s pos pos' sl')) | false |
LowParse.Low.Base.fst | LowParse.Low.Base.writable_weaken | val writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(h: HS.mem)
(lpos lpos': nat)
: Lemma
(requires
(writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\
pos' <= B.length b)) (ensures (writable b lpos lpos' h)) | val writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(h: HS.mem)
(lpos lpos': nat)
: Lemma
(requires
(writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\
pos' <= B.length b)) (ensures (writable b lpos lpos' h)) | let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
) | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 598,
"start_col": 0,
"start_line": 580
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: LowStar.Monotonic.Buffer.mbuffer t rrel rel ->
pos: Prims.nat ->
pos': Prims.nat ->
h: FStar.Monotonic.HyperStack.mem ->
lpos: Prims.nat ->
lpos': Prims.nat
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\
pos' <= LowStar.Monotonic.Buffer.length b)
(ensures LowParse.Low.Base.writable b lpos lpos' h) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Base.writable_intro",
"FStar.Seq.Properties.lseq",
"Prims.op_Subtraction",
"Prims._assert",
"Prims.unit",
"FStar.Seq.Base.equal",
"FStar.Seq.Properties.replace_subseq",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.slice",
"LowStar.Monotonic.Buffer.as_seq",
"Prims.l_and",
"LowParse.Low.Base.writable",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowStar.Monotonic.Buffer.length",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(h: HS.mem)
(lpos lpos': nat)
: Lemma
(requires
(writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\
pos' <= B.length b)) (ensures (writable b lpos lpos' h)) =
| writable_intro b
lpos
lpos'
h
()
(fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 =
Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1)
in
let j2 =
Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2)
in
assert ((Seq.replace_subseq s lpos lpos' s1) `Seq.equal` j1);
assert ((Seq.replace_subseq s lpos lpos' s2) `Seq.equal` j2);
assert (j1 `rel` j2)) | false |
LowParse.Low.Base.fst | LowParse.Low.Base.irepr_v | val irepr_v
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(#s: slice rrel rel)
(#compl: compl_t t)
(x: irepr p s compl)
: GTot t | val irepr_v
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(#s: slice rrel rel)
(#compl: compl_t t)
(x: irepr p s compl)
: GTot t | let irepr_v
(#t: Type) (#k: parser_kind) (#p: parser k t) (#rrel #rel: _) (#s: slice rrel rel) (#compl: compl_t t) (x: irepr p s compl) : GTot t
= Ghost.reveal (IRepr?.gv x) | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 28,
"end_line": 2084,
"start_col": 0,
"start_line": 2082
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
()
inline_for_extraction
let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len
#push-options "--z3rlimit 32 --fuel 2 --ifuel 1"
inline_for_extraction
let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
(x: Ghost.erased t) ->
HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
(#rrel_out #rel_out: _)
(sl_out : slice rrel_out rel_out)
(pos_out : U32.t)
: HST.Stack U32.t
(requires (fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\
valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out
))
(ensures (fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
//B.fresh_frame_modifies h0 h1;
let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\ (
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow
)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))
inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then begin
assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2
end else
L.append_l_nil (L.filter f (G.reveal l1))
)
;
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out'
#pop-options
#push-options "--z3rlimit 64 --fuel 2 --ifuel 1"
inline_for_extraction
let list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(i: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos' /\
U32.v i < L.length (contents_list p h sl pos pos')
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid_list p h sl pos res /\
valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos1 = BF.alloca pos 1ul in
let bk = BF.alloca 0ul 1ul in
let h2 = HST.get () in
valid_list_nil p h0 sl pos;
let _ : bool = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
let k = Seq.index (B.as_seq h bk) 0 in
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bpos1 /\
B.live h bk /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v k /\
U32.v k <= U32.v i
)
(fun h _ _ _ h' ->
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1);
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk);
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
let pos1 = Seq.index (B.as_seq h bpos1) 0 in
B.live h bpos1 /\
valid p h0 sl pos1 /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v i /\
contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)
)
(fun _ _ ->
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 ->
let k = B.index bk 0ul in
if k = i
then begin
B.upd bpos1 0ul pos1;
valid_list_cons_recip p h0 sl pos1 pos';
list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i);
valid_list_append p h0 sl pos pos1 pos' ;
assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i));
false
end else begin
B.upd bk 0ul (k `U32.add` 1ul);
let h = HST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h;
valid_list_snoc p h0 sl pos pos1;
assert (valid p h0 sl pos1);
assert (pos2 == get_valid_pos p h0 sl pos1);
assert (valid_list p h0 sl pos pos2);
list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1];
true
end
)
in
let res = B.index bpos1 0ul in
HST.pop_frame ();
res
inline_for_extraction
let list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\
valid p h sl res /\ (
let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\
f x == true /\
L.find f l == Some x
)
)))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bres = BF.alloca 0ul 1ul in
let h2 = HST.get () in
let not_found = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\
valid_list p h0 sl pos1 pos' /\
l2 == contents_list p h0 sl pos1 pos' /\
L.find f (contents_list p h0 sl pos pos') == L.find f l2
)
(fun h _ _ _ h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\ (
let res = Seq.index (B.as_seq h bres) 0 in
U32.v pos <= U32.v res /\
valid p h0 sl res /\ (
let x = contents p h0 sl res in
U32.v res + content_length p h0 sl res <= U32.v pos' /\
f x == true /\
L.find f (contents_list p h0 sl pos pos') == Some x
)))
(fun h h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun pos1 pos2 ->
if f' sl pos1
then begin
B.upd bres 0ul pos1;
false
end
else true
)
in
let res =
if not_found
then pos'
else B.index bres 0ul
in
HST.pop_frame ();
res
#pop-options
let rec list_existsb_find
(#a: Type)
(f: (a -> Tot bool))
(l: list a)
: Lemma
(L.existsb f l == Some? (L.find f l))
= match l with
| [] -> ()
| x :: q ->
if f x
then ()
else list_existsb_find f q
inline_for_extraction
noextract
let list_existsb
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack bool
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == L.existsb f (contents_list p h sl pos pos')
))
= let h = HST.get () in
list_existsb_find f (contents_list p h sl pos pos');
let posn = list_find j f f' sl pos pos' in
posn <> pos'
#push-options "--fuel 2 --ifuel 1 --z3rlimit 256 --query_stats"
inline_for_extraction
noextract
let list_flatten_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot (list t2))) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2_ res /\
contents_list p2 h' sl2 pos2_ res == y
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= let hz = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos2_ = BF.alloca pos2 1ul in
let h2 = HST.get () in
valid_list_nil p2 hz sl2 pos2;
let fits = list_fold_left_gen
p1
j1
sl1
pos1 pos1'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2))
(fun h ll lr _ ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
B.live h bpos2_ /\ (
let pos2_ = Seq.index (B.as_seq h bpos2_) 0 in
contents_list p1 h0 sl1 pos1 pos1' == ll `List.Tot.append` lr /\
valid_list p2 h sl2 pos2 pos2_ /\
contents_list p2 h sl2 pos2 pos2_ == List.Tot.flatten (List.Tot.map f ll) /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(fun h _ _ _ h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
U32.v pos2 + serialized_list_length s2 (List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1'))) > U32.v sl2.len
)
(fun h h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1l pos1r ->
let pos2_ = B.index bpos2_ 0ul in
let h = HST.get () in
writable_weaken sl2.base (U32.v pos2) (U32.v sl2.len) h (U32.v pos2_) (U32.v sl2.len);
valid_pos_frame_strong p1 h0 sl1 pos1l pos1r (loc_slice_from sl2 pos2) hz;
let res = f' pos1l pos2_ in
let fits = not (res = max_uint32) in
if fits then begin
B.upd bpos2_ 0ul res;
let h' = HST.get () in
writable_modifies sl2.base (U32.v pos2) (U32.v sl2.len) h (B.loc_region_only true (HS.get_tip h1)) h' ;
List.Tot.append_assoc (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l] (contents_list p1 h0 sl1 pos1r pos1');
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l];
valid_list_snoc p1 h0 sl1 pos1 pos1l;
valid_list_append p2 h' sl2 pos2 pos2_ res;
valid_list_nil p2 h' sl2 res;
valid_list_append p2 h' sl2 pos2_ res res
end else begin
let h' = HST.get () in
valid_list_cons p1 h0 sl1 pos1l pos1' ;
valid_list_append p1 h0 sl1 pos1 pos1l pos1' ;
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) (contents_list p1 h0 sl1 pos1l pos1');
serialized_list_length_append s2 (L.flatten (L.map f (contents_list p1 h0 sl1 pos1 pos1l))) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1l pos1')));
serialized_list_length_append s2 (f (contents p1 h0 sl1 pos1l)) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1r pos1')));
valid_list_serialized_list_length s2 h' sl2 pos2 pos2_
end;
fits
)
in
let res =
if fits
then B.index bpos2_ 0ul
else max_uint32
in
HST.pop_frame ();
res
#pop-options
#push-options "--z3rlimit 16 --query_stats"
inline_for_extraction
noextract
let list_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot t2)) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_length s2 y > U32.v sl2.len
else
valid_content_pos p2 h' sl2 pos2_ y res
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1') in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= list_map_list_flatten_map f (contents_list p1 h0 sl1 pos1 pos1');
list_flatten_map
j1
s2
(fun x -> [f x])
h0
sl1 pos1 pos1'
sl2 pos2
(fun pos1 pos2 ->
let res = f' pos1 pos2 in
let h = HST.get () in
if res = max_uint32
then begin
serialized_list_length_nil s2;
serialized_list_length_cons s2 (f (contents p1 h0 sl1 pos1)) []
end
else begin
valid_list_nil p2 h sl2 res;
valid_list_cons p2 h sl2 pos2 res
end;
res
)
(* Example: trivial printers *)
inline_for_extraction
let print_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(print: ((#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack unit (requires (fun h -> valid p h sl pos)) (ensures (fun h _ h' -> B.modifies B.loc_none h h'))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h _ h' ->
B.modifies B.loc_none h h'
))
= let h0 = HST.get () in
list_fold_left
p
j
sl
pos pos'
h0
(Ghost.hide B.loc_none)
(fun _ _ _ _ -> True)
(fun _ _ _ _ _ -> ())
(fun pos1 _ _ _ _ ->
print sl pos1
)
(* Monotonicity *)
inline_for_extraction
let compl_t (t: Type) = U32.t -> t -> U32.t -> Tot (B.spred byte)
let wvalid
(#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos' : Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
: GTot prop
=
U32.v pos <= U32.v (Ghost.reveal gpos') /\
U32.v (Ghost.reveal gpos') <= U32.v s.len /\
U32.v s.len <= Seq.length x /\
parse p (Seq.slice x (U32.v pos) (U32.v s.len)) == Some (Ghost.reveal gv, U32.v (Ghost.reveal gpos') - U32.v pos) /\
compl pos (Ghost.reveal gv) (Ghost.reveal gpos') x
let wvalid_valid_content_pos
(#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos' : Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
(h: HS.mem)
: Lemma
(requires (
wvalid p s compl pos gpos' gv x /\
live_slice h s /\
x == B.as_seq h s.base
))
(ensures (
valid_content_pos p h s pos gv gpos'
))
=
valid_facts p h s pos
inline_for_extraction
noeq
type irepr (#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel) (compl: compl_t t) =
| IRepr:
(pos: U32.t) ->
(gpos' : Ghost.erased U32.t) ->
(gv: Ghost.erased t) ->
(irepr_correct: squash (
U32.v pos <= U32.v (Ghost.reveal gpos') /\
U32.v (Ghost.reveal gpos') <= U32.v s.len /\
B.witnessed s.base (wvalid p s compl pos gpos' gv)
)) ->
irepr p s compl
inline_for_extraction
let irepr_pos
(#t: Type) (#k: parser_kind) (#p: parser k t) (#rrel #rel: _) (#s: slice rrel rel) (#compl: compl_t t) (x: irepr p s compl) : Tot U32.t =
IRepr?.pos x
let irepr_pos'
(#t: Type) (#k: parser_kind) (#p: parser k t) (#rrel #rel: _) (#s: slice rrel rel) (#compl: compl_t t) (x: irepr p s compl) : Ghost U32.t
(requires True)
(ensures (fun y -> True))
= Ghost.reveal (IRepr?.gpos' x)
#push-options "--ifuel 1 --fuel 2"
let irepr_pos'_post
(#t: Type) (#k: parser_kind) (#p: parser k t) (#rrel #rel: _) (#s: slice rrel rel) (#compl: compl_t t) (x: irepr p s compl) : Lemma
(requires True)
(ensures (
let y = irepr_pos' x in
U32.v (irepr_pos x) <= U32.v y /\ U32.v y <= U32.v s.len
))
[SMTPat (irepr_pos' x)]
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: LowParse.Low.Base.irepr p s compl -> Prims.GTot t | Prims.GTot | [
"sometrivial"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Low.Base.compl_t",
"LowParse.Low.Base.irepr",
"FStar.Ghost.reveal",
"LowParse.Low.Base.__proj__IRepr__item__gv"
] | [] | false | false | false | false | false | let irepr_v
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(#s: slice rrel rel)
(#compl: compl_t t)
(x: irepr p s compl)
: GTot t =
| Ghost.reveal (IRepr?.gv x) | false |
LowParse.Low.Base.fst | LowParse.Low.Base.writable_replace_subseq | val writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(h: HS.mem)
(sl': Seq.seq t)
(h': HS.mem)
: Lemma
(requires
(writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos /\
(B.as_seq h' b) `Seq.equal` (Seq.replace_subseq (B.as_seq h b) pos pos' sl') /\
B.live h' b))
(ensures
(let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\ writable b pos pos' h')) | val writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(h: HS.mem)
(sl': Seq.seq t)
(h': HS.mem)
: Lemma
(requires
(writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos /\
(B.as_seq h' b) `Seq.equal` (Seq.replace_subseq (B.as_seq h b) pos pos' sl') /\
B.live h' b))
(ensures
(let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\ writable b pos pos' h')) | let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
) | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 656,
"start_col": 0,
"start_line": 625
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: LowStar.Monotonic.Buffer.mbuffer t rrel rel ->
pos: Prims.nat ->
pos': Prims.nat ->
h: FStar.Monotonic.HyperStack.mem ->
sl': FStar.Seq.Base.seq t ->
h': FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.writable b pos pos' h /\ pos <= pos' /\
pos' <= LowStar.Monotonic.Buffer.length b /\ FStar.Seq.Base.length sl' == pos' - pos /\
FStar.Seq.Base.equal (LowStar.Monotonic.Buffer.as_seq h' b)
(FStar.Seq.Properties.replace_subseq (LowStar.Monotonic.Buffer.as_seq h b) pos pos' sl') /\
LowStar.Monotonic.Buffer.live h' b)
(ensures
(let s = LowStar.Monotonic.Buffer.as_seq h b in
let s' = FStar.Seq.Properties.replace_subseq s pos pos' sl' in
rel s s' /\ LowParse.Low.Base.writable b pos pos' h')) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"FStar.Monotonic.HyperStack.mem",
"FStar.Seq.Base.seq",
"LowParse.Low.Base.writable_intro",
"FStar.Seq.Properties.lseq",
"Prims.op_Subtraction",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Properties.replace_subseq",
"Prims.unit",
"FStar.Seq.Base.slice",
"LowStar.Monotonic.Buffer.as_seq",
"Prims.l_and",
"LowParse.Low.Base.writable",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowStar.Monotonic.Buffer.length",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"LowStar.Monotonic.Buffer.live",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos': nat)
(h: HS.mem)
(sl': Seq.seq t)
(h': HS.mem)
: Lemma
(requires
(writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos /\
(B.as_seq h' b) `Seq.equal` (Seq.replace_subseq (B.as_seq h b) pos pos' sl') /\
B.live h' b))
(ensures
(let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\ writable b pos pos' h')) =
| let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` (Seq.replace_subseq s pos pos' sl));
assert (s' `Seq.equal` (Seq.replace_subseq s pos pos' sl'));
writable_intro b
pos
pos'
h'
()
(fun s1 s2 ->
assert ((Seq.replace_subseq s' pos pos' s1) `Seq.equal` (Seq.replace_subseq s pos pos' s1));
assert ((Seq.replace_subseq s' pos pos' s2) `Seq.equal` (Seq.replace_subseq s pos pos' s2))) | false |
LowParse.Low.Base.fst | LowParse.Low.Base.frame_serializer32 | val frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel #rel: _)
(b: B.mbuffer byte rrel rel)
(posl posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\ U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\ U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h))
(ensures
(fun h len h' ->
Seq.length (serialize s x) == U32.v len /\
(B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
(Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len))
`Seq.equal`
(serialize s x) /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
(Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos))
`Seq.equal`
(Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos)) /\
(Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)))
`Seq.equal`
(Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)))))) | val frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel #rel: _)
(b: B.mbuffer byte rrel rel)
(posl posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\ U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\ U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h))
(ensures
(fun h len h' ->
Seq.length (serialize s x) == U32.v len /\
(B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
(Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len))
`Seq.equal`
(serialize s x) /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
(Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos))
`Seq.equal`
(Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos)) /\
(Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)))
`Seq.equal`
(Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)))))) | let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 907,
"start_col": 0,
"start_line": 861
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s32: LowParse.Low.Base.serializer32 s ->
x: t ->
b: LowStar.Monotonic.Buffer.mbuffer LowParse.Bytes.byte rrel rel ->
posl: FStar.Ghost.erased FStar.UInt32.t ->
posr: FStar.Ghost.erased FStar.UInt32.t ->
pos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.serializer32",
"LowStar.Monotonic.Buffer.srel",
"LowParse.Bytes.byte",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.Ghost.erased",
"FStar.UInt32.t",
"Prims.unit",
"LowStar.Monotonic.Buffer.modifies_buffer_from_to_elim",
"FStar.Ghost.reveal",
"LowStar.Monotonic.Buffer.loc_buffer_from_to",
"LowStar.Monotonic.Buffer.loc_disjoint_loc_buffer_from_to",
"LowStar.Monotonic.Buffer.loc_includes_loc_buffer_from_to",
"LowParse.Low.Base.writable_modifies",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.loc_none",
"FStar.UInt32.add",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.writable_weaken",
"Prims.op_Addition",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.serialize",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowStar.Monotonic.Buffer.length",
"LowParse.Low.Base.writable",
"FStar.Seq.Base.seq",
"LowStar.Monotonic.Buffer.as_seq",
"Prims.nat",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"LowStar.Monotonic.Buffer.modifies",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice"
] | [] | false | true | false | false | false | let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel #rel: _)
(b: B.mbuffer byte rrel rel)
(posl posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\ U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\ U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h))
(ensures
(fun h len h' ->
Seq.length (serialize s x) == U32.v len /\
(B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
(Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len))
`Seq.equal`
(serialize s x) /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
(Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos))
`Seq.equal`
(Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos)) /\
(Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)))
`Seq.equal`
(Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)))))) =
| let h0 = HST.get () in
writable_weaken b
(U32.v (Ghost.reveal posl))
(U32.v (Ghost.reveal posr))
h0
(U32.v pos)
(U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res | false |
LowParse.Low.Base.fst | LowParse.Low.Base.leaf_writer_weak_of_strong_constant_size | val leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u:
squash (k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32))
: Tot (leaf_writer_weak s) | val leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u:
squash (k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32))
: Tot (leaf_writer_weak s) | let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 954,
"start_col": 0,
"start_line": 934
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s32: LowParse.Low.Base.leaf_writer_strong s ->
sz: FStar.UInt32.t ->
u707:
Prims.squash (Mkparser_kind'?.parser_kind_high k ==
FStar.Pervasives.Native.Some (Mkparser_kind'?.parser_kind_low k) /\
Mkparser_kind'?.parser_kind_low k == FStar.UInt32.v sz /\
Mkparser_kind'?.parser_kind_low k < FStar.UInt32.v LowParse.Low.ErrorCode.max_uint32)
-> LowParse.Low.Base.leaf_writer_weak s | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.leaf_writer_strong",
"FStar.UInt32.t",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"Prims.nat",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"FStar.UInt32.v",
"Prims.op_LessThan",
"LowParse.Low.ErrorCode.max_uint32",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.lt",
"FStar.UInt32.sub",
"LowParse.Slice.__proj__Mkslice__item__len",
"Prims.bool",
"Prims.unit",
"LowParse.Low.Base.writable_weaken",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"Prims.op_Addition",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.leaf_writer_weak"
] | [] | false | false | false | false | false | let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u:
squash (k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32))
: Tot (leaf_writer_weak s) =
| fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos | false |
LowParse.Low.Base.fst | LowParse.Low.Base.copy_weak_with_length | val copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1)
(spos spos': U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\
live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)))
(ensures
(fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\
(if dpos' = max_uint32
then U32.v dpos + content_length p h src spos > U32.v dst.len
else valid_content_pos p h' dst dpos (contents p h src spos) dpos'))) | val copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1)
(spos spos': U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\
live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)))
(ensures
(fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\
(if dpos' = max_uint32
then U32.v dpos + content_length p h src spos > U32.v dst.len
else valid_content_pos p h' dst dpos (contents p h src spos) dpos'))) | let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 44,
"end_line": 1108,
"start_col": 0,
"start_line": 1079
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: LowParse.Spec.Base.parser k t ->
src: LowParse.Slice.slice rrel1 rel1 ->
spos: FStar.UInt32.t ->
spos': FStar.UInt32.t ->
dst: LowParse.Slice.slice rrel2 rel2 ->
dpos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.UInt32.lt",
"FStar.UInt32.sub",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.ErrorCode.max_uint32",
"Prims.bool",
"LowParse.Low.Base.copy_strong",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.Spec.valid_pos",
"LowParse.Slice.live_slice",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"Prims.op_LessThan",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"Prims.op_Addition",
"Prims.op_Subtraction",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowParse.Slice.loc_slice_from_to",
"LowParse.Slice.loc_slice_from",
"LowStar.Monotonic.Buffer.modifies",
"Prims.op_Equality",
"Prims.op_GreaterThan",
"LowParse.Low.Base.Spec.content_length",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Low.Base.Spec.contents",
"Prims.logical"
] | [] | false | true | false | false | false | let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1)
(spos spos': U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\
live_slice h dst /\ U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)))
(ensures
(fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\
(if dpos' = max_uint32
then U32.v dpos + content_length p h src spos > U32.v dst.len
else valid_content_pos p h' dst dpos (contents p h src spos) dpos'))) =
| if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos | false |
LowParse.Low.Base.fst | LowParse.Low.Base.copy_strong' | val copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1)
(spos: U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\
(let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos)
(loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen))))))
(ensures
(fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos')) | val copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1)
(spos: U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\
(let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos)
(loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen))))))
(ensures
(fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos')) | let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 39,
"end_line": 1076,
"start_col": 0,
"start_line": 1051
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
j: LowParse.Low.Base.jumper p ->
src: LowParse.Slice.slice rrel1 rel1 ->
spos: FStar.UInt32.t ->
dst: LowParse.Slice.slice rrel2 rel2 ->
dpos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.copy_strong",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.Spec.valid",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Slice.live_slice",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowParse.Slice.loc_slice_from",
"LowParse.Slice.loc_slice_from_to",
"FStar.UInt32.add",
"FStar.UInt32.uint_to_t",
"Prims.nat",
"LowParse.Low.Base.Spec.content_length",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Low.Base.Spec.contents"
] | [] | false | true | false | false | false | let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1)
(spos: U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\
(let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\ live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos)
(loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen))))))
(ensures
(fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos')) =
| let spos' = j src spos in
copy_strong p src spos spos' dst dpos | false |
LowParse.Low.Base.fst | LowParse.Low.Base.list_existsb | val list_existsb
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f':
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos))))
)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos': U32.t)
: HST.Stack bool
(requires (fun h -> valid_list p h sl pos pos'))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ res == L.existsb f (contents_list p h sl pos pos'))) | val list_existsb
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f':
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos))))
)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos': U32.t)
: HST.Stack bool
(requires (fun h -> valid_list p h sl pos pos'))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ res == L.existsb f (contents_list p h sl pos pos'))) | let list_existsb
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack bool
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == L.existsb f (contents_list p h sl pos pos')
))
= let h = HST.get () in
list_existsb_find f (contents_list p h sl pos pos');
let posn = list_find j f f' sl pos pos' in
posn <> pos' | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 14,
"end_line": 1742,
"start_col": 0,
"start_line": 1710
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
()
inline_for_extraction
let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len
#push-options "--z3rlimit 32 --fuel 2 --ifuel 1"
inline_for_extraction
let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
(x: Ghost.erased t) ->
HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
(#rrel_out #rel_out: _)
(sl_out : slice rrel_out rel_out)
(pos_out : U32.t)
: HST.Stack U32.t
(requires (fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\
valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out
))
(ensures (fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
//B.fresh_frame_modifies h0 h1;
let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\ (
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow
)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))
inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then begin
assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2
end else
L.append_l_nil (L.filter f (G.reveal l1))
)
;
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out'
#pop-options
#push-options "--z3rlimit 64 --fuel 2 --ifuel 1"
inline_for_extraction
let list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(i: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos' /\
U32.v i < L.length (contents_list p h sl pos pos')
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid_list p h sl pos res /\
valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos1 = BF.alloca pos 1ul in
let bk = BF.alloca 0ul 1ul in
let h2 = HST.get () in
valid_list_nil p h0 sl pos;
let _ : bool = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
let k = Seq.index (B.as_seq h bk) 0 in
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bpos1 /\
B.live h bk /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v k /\
U32.v k <= U32.v i
)
(fun h _ _ _ h' ->
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1);
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk);
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
let pos1 = Seq.index (B.as_seq h bpos1) 0 in
B.live h bpos1 /\
valid p h0 sl pos1 /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v i /\
contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)
)
(fun _ _ ->
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 ->
let k = B.index bk 0ul in
if k = i
then begin
B.upd bpos1 0ul pos1;
valid_list_cons_recip p h0 sl pos1 pos';
list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i);
valid_list_append p h0 sl pos pos1 pos' ;
assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i));
false
end else begin
B.upd bk 0ul (k `U32.add` 1ul);
let h = HST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h;
valid_list_snoc p h0 sl pos pos1;
assert (valid p h0 sl pos1);
assert (pos2 == get_valid_pos p h0 sl pos1);
assert (valid_list p h0 sl pos pos2);
list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1];
true
end
)
in
let res = B.index bpos1 0ul in
HST.pop_frame ();
res
inline_for_extraction
let list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\
valid p h sl res /\ (
let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\
f x == true /\
L.find f l == Some x
)
)))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bres = BF.alloca 0ul 1ul in
let h2 = HST.get () in
let not_found = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\
valid_list p h0 sl pos1 pos' /\
l2 == contents_list p h0 sl pos1 pos' /\
L.find f (contents_list p h0 sl pos pos') == L.find f l2
)
(fun h _ _ _ h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\ (
let res = Seq.index (B.as_seq h bres) 0 in
U32.v pos <= U32.v res /\
valid p h0 sl res /\ (
let x = contents p h0 sl res in
U32.v res + content_length p h0 sl res <= U32.v pos' /\
f x == true /\
L.find f (contents_list p h0 sl pos pos') == Some x
)))
(fun h h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun pos1 pos2 ->
if f' sl pos1
then begin
B.upd bres 0ul pos1;
false
end
else true
)
in
let res =
if not_found
then pos'
else B.index bres 0ul
in
HST.pop_frame ();
res
#pop-options
let rec list_existsb_find
(#a: Type)
(f: (a -> Tot bool))
(l: list a)
: Lemma
(L.existsb f l == Some? (L.find f l))
= match l with
| [] -> ()
| x :: q ->
if f x
then ()
else list_existsb_find f q
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
j: LowParse.Low.Base.jumper p ->
f: (_: t -> Prims.bool) ->
f':
(sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.bool) ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.bool | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"Prims.bool",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Base.Spec.valid",
"Prims.l_and",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.eq2",
"LowParse.Low.Base.Spec.contents",
"Prims.op_disEquality",
"LowParse.Low.Base.list_find",
"Prims.unit",
"LowParse.Low.Base.list_existsb_find",
"LowParse.Low.Base.Spec.contents_list",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.Spec.valid_list",
"FStar.List.Tot.Base.existsb"
] | [] | false | true | false | false | false | let list_existsb
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f':
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos))))
)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos': U32.t)
: HST.Stack bool
(requires (fun h -> valid_list p h sl pos pos'))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ res == L.existsb f (contents_list p h sl pos pos'))) =
| let h = HST.get () in
list_existsb_find f (contents_list p h sl pos pos');
let posn = list_find j f f' sl pos pos' in
posn <> pos' | false |
LowParse.Low.Base.fst | LowParse.Low.Base.print_list | val print_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(print:
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack unit
(requires (fun h -> valid p h sl pos))
(ensures (fun h _ h' -> B.modifies B.loc_none h h'))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h _ h' -> B.modifies B.loc_none h h')) | val print_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(print:
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack unit
(requires (fun h -> valid p h sl pos))
(ensures (fun h _ h' -> B.modifies B.loc_none h h'))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h _ h' -> B.modifies B.loc_none h h')) | let print_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(print: ((#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack unit (requires (fun h -> valid p h sl pos)) (ensures (fun h _ h' -> B.modifies B.loc_none h h'))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h _ h' ->
B.modifies B.loc_none h h'
))
= let h0 = HST.get () in
list_fold_left
p
j
sl
pos pos'
h0
(Ghost.hide B.loc_none)
(fun _ _ _ _ -> True)
(fun _ _ _ _ _ -> ())
(fun pos1 _ _ _ _ ->
print sl pos1
) | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 2002,
"start_col": 0,
"start_line": 1974
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
()
inline_for_extraction
let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len
#push-options "--z3rlimit 32 --fuel 2 --ifuel 1"
inline_for_extraction
let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
(x: Ghost.erased t) ->
HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
(#rrel_out #rel_out: _)
(sl_out : slice rrel_out rel_out)
(pos_out : U32.t)
: HST.Stack U32.t
(requires (fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\
valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out
))
(ensures (fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
//B.fresh_frame_modifies h0 h1;
let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\ (
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow
)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))
inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then begin
assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2
end else
L.append_l_nil (L.filter f (G.reveal l1))
)
;
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out'
#pop-options
#push-options "--z3rlimit 64 --fuel 2 --ifuel 1"
inline_for_extraction
let list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(i: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos' /\
U32.v i < L.length (contents_list p h sl pos pos')
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid_list p h sl pos res /\
valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos1 = BF.alloca pos 1ul in
let bk = BF.alloca 0ul 1ul in
let h2 = HST.get () in
valid_list_nil p h0 sl pos;
let _ : bool = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
let k = Seq.index (B.as_seq h bk) 0 in
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bpos1 /\
B.live h bk /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v k /\
U32.v k <= U32.v i
)
(fun h _ _ _ h' ->
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1);
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk);
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
let pos1 = Seq.index (B.as_seq h bpos1) 0 in
B.live h bpos1 /\
valid p h0 sl pos1 /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v i /\
contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)
)
(fun _ _ ->
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 ->
let k = B.index bk 0ul in
if k = i
then begin
B.upd bpos1 0ul pos1;
valid_list_cons_recip p h0 sl pos1 pos';
list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i);
valid_list_append p h0 sl pos pos1 pos' ;
assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i));
false
end else begin
B.upd bk 0ul (k `U32.add` 1ul);
let h = HST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h;
valid_list_snoc p h0 sl pos pos1;
assert (valid p h0 sl pos1);
assert (pos2 == get_valid_pos p h0 sl pos1);
assert (valid_list p h0 sl pos pos2);
list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1];
true
end
)
in
let res = B.index bpos1 0ul in
HST.pop_frame ();
res
inline_for_extraction
let list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\
valid p h sl res /\ (
let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\
f x == true /\
L.find f l == Some x
)
)))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bres = BF.alloca 0ul 1ul in
let h2 = HST.get () in
let not_found = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\
valid_list p h0 sl pos1 pos' /\
l2 == contents_list p h0 sl pos1 pos' /\
L.find f (contents_list p h0 sl pos pos') == L.find f l2
)
(fun h _ _ _ h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\ (
let res = Seq.index (B.as_seq h bres) 0 in
U32.v pos <= U32.v res /\
valid p h0 sl res /\ (
let x = contents p h0 sl res in
U32.v res + content_length p h0 sl res <= U32.v pos' /\
f x == true /\
L.find f (contents_list p h0 sl pos pos') == Some x
)))
(fun h h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun pos1 pos2 ->
if f' sl pos1
then begin
B.upd bres 0ul pos1;
false
end
else true
)
in
let res =
if not_found
then pos'
else B.index bres 0ul
in
HST.pop_frame ();
res
#pop-options
let rec list_existsb_find
(#a: Type)
(f: (a -> Tot bool))
(l: list a)
: Lemma
(L.existsb f l == Some? (L.find f l))
= match l with
| [] -> ()
| x :: q ->
if f x
then ()
else list_existsb_find f q
inline_for_extraction
noextract
let list_existsb
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack bool
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == L.existsb f (contents_list p h sl pos pos')
))
= let h = HST.get () in
list_existsb_find f (contents_list p h sl pos pos');
let posn = list_find j f f' sl pos pos' in
posn <> pos'
#push-options "--fuel 2 --ifuel 1 --z3rlimit 256 --query_stats"
inline_for_extraction
noextract
let list_flatten_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot (list t2))) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2_ res /\
contents_list p2 h' sl2 pos2_ res == y
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= let hz = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos2_ = BF.alloca pos2 1ul in
let h2 = HST.get () in
valid_list_nil p2 hz sl2 pos2;
let fits = list_fold_left_gen
p1
j1
sl1
pos1 pos1'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2))
(fun h ll lr _ ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
B.live h bpos2_ /\ (
let pos2_ = Seq.index (B.as_seq h bpos2_) 0 in
contents_list p1 h0 sl1 pos1 pos1' == ll `List.Tot.append` lr /\
valid_list p2 h sl2 pos2 pos2_ /\
contents_list p2 h sl2 pos2 pos2_ == List.Tot.flatten (List.Tot.map f ll) /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(fun h _ _ _ h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
U32.v pos2 + serialized_list_length s2 (List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1'))) > U32.v sl2.len
)
(fun h h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1l pos1r ->
let pos2_ = B.index bpos2_ 0ul in
let h = HST.get () in
writable_weaken sl2.base (U32.v pos2) (U32.v sl2.len) h (U32.v pos2_) (U32.v sl2.len);
valid_pos_frame_strong p1 h0 sl1 pos1l pos1r (loc_slice_from sl2 pos2) hz;
let res = f' pos1l pos2_ in
let fits = not (res = max_uint32) in
if fits then begin
B.upd bpos2_ 0ul res;
let h' = HST.get () in
writable_modifies sl2.base (U32.v pos2) (U32.v sl2.len) h (B.loc_region_only true (HS.get_tip h1)) h' ;
List.Tot.append_assoc (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l] (contents_list p1 h0 sl1 pos1r pos1');
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l];
valid_list_snoc p1 h0 sl1 pos1 pos1l;
valid_list_append p2 h' sl2 pos2 pos2_ res;
valid_list_nil p2 h' sl2 res;
valid_list_append p2 h' sl2 pos2_ res res
end else begin
let h' = HST.get () in
valid_list_cons p1 h0 sl1 pos1l pos1' ;
valid_list_append p1 h0 sl1 pos1 pos1l pos1' ;
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) (contents_list p1 h0 sl1 pos1l pos1');
serialized_list_length_append s2 (L.flatten (L.map f (contents_list p1 h0 sl1 pos1 pos1l))) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1l pos1')));
serialized_list_length_append s2 (f (contents p1 h0 sl1 pos1l)) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1r pos1')));
valid_list_serialized_list_length s2 h' sl2 pos2 pos2_
end;
fits
)
in
let res =
if fits
then B.index bpos2_ 0ul
else max_uint32
in
HST.pop_frame ();
res
#pop-options
#push-options "--z3rlimit 16 --query_stats"
inline_for_extraction
noextract
let list_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot t2)) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_length s2 y > U32.v sl2.len
else
valid_content_pos p2 h' sl2 pos2_ y res
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1') in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= list_map_list_flatten_map f (contents_list p1 h0 sl1 pos1 pos1');
list_flatten_map
j1
s2
(fun x -> [f x])
h0
sl1 pos1 pos1'
sl2 pos2
(fun pos1 pos2 ->
let res = f' pos1 pos2 in
let h = HST.get () in
if res = max_uint32
then begin
serialized_list_length_nil s2;
serialized_list_length_cons s2 (f (contents p1 h0 sl1 pos1)) []
end
else begin
valid_list_nil p2 h sl2 res;
valid_list_cons p2 h sl2 pos2 res
end;
res
)
(* Example: trivial printers *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
j: LowParse.Low.Base.jumper p ->
print:
(sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit) ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Base.Spec.valid",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"LowParse.Low.Base.list_fold_left",
"FStar.Ghost.hide",
"LowStar.Monotonic.Buffer.loc",
"Prims.list",
"Prims.l_True",
"FStar.Ghost.erased",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.Spec.valid_list"
] | [] | false | true | false | false | false | let print_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(print:
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack unit
(requires (fun h -> valid p h sl pos))
(ensures (fun h _ h' -> B.modifies B.loc_none h h'))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos': U32.t)
: HST.Stack unit
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h _ h' -> B.modifies B.loc_none h h')) =
| let h0 = HST.get () in
list_fold_left p j sl pos pos' h0 (Ghost.hide B.loc_none) (fun _ _ _ _ -> True)
(fun _ _ _ _ _ -> ()) (fun pos1 _ _ _ _ -> print sl pos1) | false |
LowParse.Low.Base.fst | LowParse.Low.Base.blit_strong | val blit_strong
(#a: Type)
(#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src: U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst len: U32.t)
: HST.Stack unit
(requires
(fun h ->
B.live h src /\ B.live h dst /\ U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len))
(B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst)
(U32.v idx_dst)
(U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures
(fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len))) | val blit_strong
(#a: Type)
(#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src: U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst len: U32.t)
: HST.Stack unit
(requires
(fun h ->
B.live h src /\ B.live h dst /\ U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len))
(B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst)
(U32.v idx_dst)
(U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures
(fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len))) | let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h' | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 89,
"end_line": 1009,
"start_col": 0,
"start_line": 984
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
src: LowStar.Monotonic.Buffer.mbuffer a rrel1 rel1 ->
idx_src: FStar.UInt32.t ->
dst: LowStar.Monotonic.Buffer.mbuffer a rrel2 rel2 ->
idx_dst: FStar.UInt32.t ->
len: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.modifies_loc_buffer_from_to_intro",
"FStar.UInt32.add",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowStar.Monotonic.Buffer.blit",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.length",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowStar.Monotonic.Buffer.loc_buffer_from_to",
"LowStar.Monotonic.Buffer.as_seq",
"FStar.Seq.Properties.replace_subseq",
"FStar.Seq.Base.slice",
"LowStar.Monotonic.Buffer.modifies",
"Prims.eq2",
"FStar.Seq.Base.seq"
] | [] | false | true | false | false | false | let blit_strong
(#a: Type)
(#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src: U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst len: U32.t)
: HST.Stack unit
(requires
(fun h ->
B.live h src /\ B.live h dst /\ U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len))
(B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst)
(U32.v idx_dst)
(U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures
(fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len))) =
| let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h' | false |
LowParse.Low.Base.fst | LowParse.Low.Base.wvalid | val wvalid
(#t: Type)
(#k: parser_kind)
(p: parser k t)
(#rrel #rel: _)
(s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos': Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
: GTot prop | val wvalid
(#t: Type)
(#k: parser_kind)
(p: parser k t)
(#rrel #rel: _)
(s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos': Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
: GTot prop | let wvalid
(#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos' : Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
: GTot prop
=
U32.v pos <= U32.v (Ghost.reveal gpos') /\
U32.v (Ghost.reveal gpos') <= U32.v s.len /\
U32.v s.len <= Seq.length x /\
parse p (Seq.slice x (U32.v pos) (U32.v s.len)) == Some (Ghost.reveal gv, U32.v (Ghost.reveal gpos') - U32.v pos) /\
compl pos (Ghost.reveal gv) (Ghost.reveal gpos') x | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 52,
"end_line": 2023,
"start_col": 0,
"start_line": 2010
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
()
inline_for_extraction
let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len
#push-options "--z3rlimit 32 --fuel 2 --ifuel 1"
inline_for_extraction
let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
(x: Ghost.erased t) ->
HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
(#rrel_out #rel_out: _)
(sl_out : slice rrel_out rel_out)
(pos_out : U32.t)
: HST.Stack U32.t
(requires (fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\
valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out
))
(ensures (fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
//B.fresh_frame_modifies h0 h1;
let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\ (
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow
)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))
inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then begin
assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2
end else
L.append_l_nil (L.filter f (G.reveal l1))
)
;
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out'
#pop-options
#push-options "--z3rlimit 64 --fuel 2 --ifuel 1"
inline_for_extraction
let list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(i: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos' /\
U32.v i < L.length (contents_list p h sl pos pos')
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid_list p h sl pos res /\
valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos1 = BF.alloca pos 1ul in
let bk = BF.alloca 0ul 1ul in
let h2 = HST.get () in
valid_list_nil p h0 sl pos;
let _ : bool = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
let k = Seq.index (B.as_seq h bk) 0 in
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bpos1 /\
B.live h bk /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v k /\
U32.v k <= U32.v i
)
(fun h _ _ _ h' ->
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1);
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk);
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
let pos1 = Seq.index (B.as_seq h bpos1) 0 in
B.live h bpos1 /\
valid p h0 sl pos1 /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v i /\
contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)
)
(fun _ _ ->
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 ->
let k = B.index bk 0ul in
if k = i
then begin
B.upd bpos1 0ul pos1;
valid_list_cons_recip p h0 sl pos1 pos';
list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i);
valid_list_append p h0 sl pos pos1 pos' ;
assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i));
false
end else begin
B.upd bk 0ul (k `U32.add` 1ul);
let h = HST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h;
valid_list_snoc p h0 sl pos pos1;
assert (valid p h0 sl pos1);
assert (pos2 == get_valid_pos p h0 sl pos1);
assert (valid_list p h0 sl pos pos2);
list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1];
true
end
)
in
let res = B.index bpos1 0ul in
HST.pop_frame ();
res
inline_for_extraction
let list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\
valid p h sl res /\ (
let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\
f x == true /\
L.find f l == Some x
)
)))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bres = BF.alloca 0ul 1ul in
let h2 = HST.get () in
let not_found = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\
valid_list p h0 sl pos1 pos' /\
l2 == contents_list p h0 sl pos1 pos' /\
L.find f (contents_list p h0 sl pos pos') == L.find f l2
)
(fun h _ _ _ h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\ (
let res = Seq.index (B.as_seq h bres) 0 in
U32.v pos <= U32.v res /\
valid p h0 sl res /\ (
let x = contents p h0 sl res in
U32.v res + content_length p h0 sl res <= U32.v pos' /\
f x == true /\
L.find f (contents_list p h0 sl pos pos') == Some x
)))
(fun h h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun pos1 pos2 ->
if f' sl pos1
then begin
B.upd bres 0ul pos1;
false
end
else true
)
in
let res =
if not_found
then pos'
else B.index bres 0ul
in
HST.pop_frame ();
res
#pop-options
let rec list_existsb_find
(#a: Type)
(f: (a -> Tot bool))
(l: list a)
: Lemma
(L.existsb f l == Some? (L.find f l))
= match l with
| [] -> ()
| x :: q ->
if f x
then ()
else list_existsb_find f q
inline_for_extraction
noextract
let list_existsb
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack bool
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == L.existsb f (contents_list p h sl pos pos')
))
= let h = HST.get () in
list_existsb_find f (contents_list p h sl pos pos');
let posn = list_find j f f' sl pos pos' in
posn <> pos'
#push-options "--fuel 2 --ifuel 1 --z3rlimit 256 --query_stats"
inline_for_extraction
noextract
let list_flatten_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot (list t2))) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2_ res /\
contents_list p2 h' sl2 pos2_ res == y
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= let hz = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos2_ = BF.alloca pos2 1ul in
let h2 = HST.get () in
valid_list_nil p2 hz sl2 pos2;
let fits = list_fold_left_gen
p1
j1
sl1
pos1 pos1'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2))
(fun h ll lr _ ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
B.live h bpos2_ /\ (
let pos2_ = Seq.index (B.as_seq h bpos2_) 0 in
contents_list p1 h0 sl1 pos1 pos1' == ll `List.Tot.append` lr /\
valid_list p2 h sl2 pos2 pos2_ /\
contents_list p2 h sl2 pos2 pos2_ == List.Tot.flatten (List.Tot.map f ll) /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(fun h _ _ _ h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
U32.v pos2 + serialized_list_length s2 (List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1'))) > U32.v sl2.len
)
(fun h h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1l pos1r ->
let pos2_ = B.index bpos2_ 0ul in
let h = HST.get () in
writable_weaken sl2.base (U32.v pos2) (U32.v sl2.len) h (U32.v pos2_) (U32.v sl2.len);
valid_pos_frame_strong p1 h0 sl1 pos1l pos1r (loc_slice_from sl2 pos2) hz;
let res = f' pos1l pos2_ in
let fits = not (res = max_uint32) in
if fits then begin
B.upd bpos2_ 0ul res;
let h' = HST.get () in
writable_modifies sl2.base (U32.v pos2) (U32.v sl2.len) h (B.loc_region_only true (HS.get_tip h1)) h' ;
List.Tot.append_assoc (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l] (contents_list p1 h0 sl1 pos1r pos1');
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l];
valid_list_snoc p1 h0 sl1 pos1 pos1l;
valid_list_append p2 h' sl2 pos2 pos2_ res;
valid_list_nil p2 h' sl2 res;
valid_list_append p2 h' sl2 pos2_ res res
end else begin
let h' = HST.get () in
valid_list_cons p1 h0 sl1 pos1l pos1' ;
valid_list_append p1 h0 sl1 pos1 pos1l pos1' ;
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) (contents_list p1 h0 sl1 pos1l pos1');
serialized_list_length_append s2 (L.flatten (L.map f (contents_list p1 h0 sl1 pos1 pos1l))) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1l pos1')));
serialized_list_length_append s2 (f (contents p1 h0 sl1 pos1l)) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1r pos1')));
valid_list_serialized_list_length s2 h' sl2 pos2 pos2_
end;
fits
)
in
let res =
if fits
then B.index bpos2_ 0ul
else max_uint32
in
HST.pop_frame ();
res
#pop-options
#push-options "--z3rlimit 16 --query_stats"
inline_for_extraction
noextract
let list_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot t2)) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_length s2 y > U32.v sl2.len
else
valid_content_pos p2 h' sl2 pos2_ y res
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1') in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= list_map_list_flatten_map f (contents_list p1 h0 sl1 pos1 pos1');
list_flatten_map
j1
s2
(fun x -> [f x])
h0
sl1 pos1 pos1'
sl2 pos2
(fun pos1 pos2 ->
let res = f' pos1 pos2 in
let h = HST.get () in
if res = max_uint32
then begin
serialized_list_length_nil s2;
serialized_list_length_cons s2 (f (contents p1 h0 sl1 pos1)) []
end
else begin
valid_list_nil p2 h sl2 res;
valid_list_cons p2 h sl2 pos2 res
end;
res
)
(* Example: trivial printers *)
inline_for_extraction
let print_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(print: ((#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack unit (requires (fun h -> valid p h sl pos)) (ensures (fun h _ h' -> B.modifies B.loc_none h h'))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h _ h' ->
B.modifies B.loc_none h h'
))
= let h0 = HST.get () in
list_fold_left
p
j
sl
pos pos'
h0
(Ghost.hide B.loc_none)
(fun _ _ _ _ -> True)
(fun _ _ _ _ _ -> ())
(fun pos1 _ _ _ _ ->
print sl pos1
)
(* Monotonicity *)
inline_for_extraction
let compl_t (t: Type) = U32.t -> t -> U32.t -> Tot (B.spred byte) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: LowParse.Spec.Base.parser k t ->
s: LowParse.Slice.slice rrel rel ->
compl: LowParse.Low.Base.compl_t t ->
pos: FStar.UInt32.t ->
gpos': FStar.Ghost.erased FStar.UInt32.t ->
gv: FStar.Ghost.erased t ->
x: FStar.Seq.Base.seq LowParse.Bytes.byte
-> Prims.GTot Prims.prop | Prims.GTot | [
"sometrivial"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Low.Base.compl_t",
"FStar.UInt32.t",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"FStar.Ghost.reveal",
"LowParse.Slice.__proj__Mkslice__item__len",
"FStar.Seq.Base.length",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Base.consumed_length",
"FStar.Seq.Base.slice",
"LowParse.Spec.Base.parse",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.Mktuple2",
"Prims.op_Subtraction",
"Prims.prop"
] | [] | false | false | false | false | true | let wvalid
(#t: Type)
(#k: parser_kind)
(p: parser k t)
(#rrel #rel: _)
(s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos': Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
: GTot prop =
| U32.v pos <= U32.v (Ghost.reveal gpos') /\ U32.v (Ghost.reveal gpos') <= U32.v s.len /\
U32.v s.len <= Seq.length x /\
parse p (Seq.slice x (U32.v pos) (U32.v s.len)) ==
Some (Ghost.reveal gv, U32.v (Ghost.reveal gpos') - U32.v pos) /\
compl pos (Ghost.reveal gv) (Ghost.reveal gpos') x | false |
LowParse.Low.Base.fst | LowParse.Low.Base.copy_strong | val copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1)
(spos spos': U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\ live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos')
(loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))))
(ensures
(fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos)) | val copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1)
(spos spos': U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\ live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos')
(loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))))
(ensures
(fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos)) | let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos' | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 7,
"end_line": 1046,
"start_col": 0,
"start_line": 1014
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: LowParse.Spec.Base.parser k t ->
src: LowParse.Slice.slice rrel1 rel1 ->
spos: FStar.UInt32.t ->
spos': FStar.UInt32.t ->
dst: LowParse.Slice.slice rrel2 rel2 ->
dpos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Base.parse_strong_prefix",
"LowParse.Slice.bytes_of_slice_from",
"FStar.UInt32.add",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.blit_strong",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"LowParse.Low.Base.writable_replace_subseq_elim",
"FStar.UInt32.v",
"Prims.op_Addition",
"Prims.op_Subtraction",
"FStar.Seq.Base.slice",
"LowStar.Monotonic.Buffer.as_seq",
"FStar.UInt32.sub",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.Spec.valid_pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Slice.live_slice",
"LowParse.Low.Base.writable",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowParse.Slice.loc_slice_from_to",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Low.Base.Spec.contents"
] | [] | false | true | false | false | false | let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1)
(spos spos': U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
k.parser_kind_subkind == Some ParserStrong /\ valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\ live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos')
(loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))))
(ensures
(fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos)) =
| let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base
(U32.v dpos)
(U32.v dpos + (U32.v spos' - U32.v spos))
h0
(Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@@ inline_let ]let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos' | false |
LowParse.Low.Base.fst | LowParse.Low.Base.wvalid_valid_content_pos | val wvalid_valid_content_pos
(#t: Type)
(#k: parser_kind)
(p: parser k t)
(#rrel #rel: _)
(s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos': Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
(h: HS.mem)
: Lemma (requires (wvalid p s compl pos gpos' gv x /\ live_slice h s /\ x == B.as_seq h s.base))
(ensures (valid_content_pos p h s pos gv gpos')) | val wvalid_valid_content_pos
(#t: Type)
(#k: parser_kind)
(p: parser k t)
(#rrel #rel: _)
(s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos': Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
(h: HS.mem)
: Lemma (requires (wvalid p s compl pos gpos' gv x /\ live_slice h s /\ x == B.as_seq h s.base))
(ensures (valid_content_pos p h s pos gv gpos')) | let wvalid_valid_content_pos
(#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos' : Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
(h: HS.mem)
: Lemma
(requires (
wvalid p s compl pos gpos' gv x /\
live_slice h s /\
x == B.as_seq h s.base
))
(ensures (
valid_content_pos p h s pos gv gpos'
))
=
valid_facts p h s pos | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 23,
"end_line": 2043,
"start_col": 0,
"start_line": 2025
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
()
inline_for_extraction
let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len
#push-options "--z3rlimit 32 --fuel 2 --ifuel 1"
inline_for_extraction
let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
(x: Ghost.erased t) ->
HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
(#rrel_out #rel_out: _)
(sl_out : slice rrel_out rel_out)
(pos_out : U32.t)
: HST.Stack U32.t
(requires (fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\
valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out
))
(ensures (fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
//B.fresh_frame_modifies h0 h1;
let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\ (
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow
)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))
inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then begin
assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2
end else
L.append_l_nil (L.filter f (G.reveal l1))
)
;
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out'
#pop-options
#push-options "--z3rlimit 64 --fuel 2 --ifuel 1"
inline_for_extraction
let list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(i: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos' /\
U32.v i < L.length (contents_list p h sl pos pos')
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid_list p h sl pos res /\
valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos1 = BF.alloca pos 1ul in
let bk = BF.alloca 0ul 1ul in
let h2 = HST.get () in
valid_list_nil p h0 sl pos;
let _ : bool = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
let k = Seq.index (B.as_seq h bk) 0 in
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bpos1 /\
B.live h bk /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v k /\
U32.v k <= U32.v i
)
(fun h _ _ _ h' ->
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1);
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk);
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
let pos1 = Seq.index (B.as_seq h bpos1) 0 in
B.live h bpos1 /\
valid p h0 sl pos1 /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v i /\
contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)
)
(fun _ _ ->
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 ->
let k = B.index bk 0ul in
if k = i
then begin
B.upd bpos1 0ul pos1;
valid_list_cons_recip p h0 sl pos1 pos';
list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i);
valid_list_append p h0 sl pos pos1 pos' ;
assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i));
false
end else begin
B.upd bk 0ul (k `U32.add` 1ul);
let h = HST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h;
valid_list_snoc p h0 sl pos pos1;
assert (valid p h0 sl pos1);
assert (pos2 == get_valid_pos p h0 sl pos1);
assert (valid_list p h0 sl pos pos2);
list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1];
true
end
)
in
let res = B.index bpos1 0ul in
HST.pop_frame ();
res
inline_for_extraction
let list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\
valid p h sl res /\ (
let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\
f x == true /\
L.find f l == Some x
)
)))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bres = BF.alloca 0ul 1ul in
let h2 = HST.get () in
let not_found = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\
valid_list p h0 sl pos1 pos' /\
l2 == contents_list p h0 sl pos1 pos' /\
L.find f (contents_list p h0 sl pos pos') == L.find f l2
)
(fun h _ _ _ h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\ (
let res = Seq.index (B.as_seq h bres) 0 in
U32.v pos <= U32.v res /\
valid p h0 sl res /\ (
let x = contents p h0 sl res in
U32.v res + content_length p h0 sl res <= U32.v pos' /\
f x == true /\
L.find f (contents_list p h0 sl pos pos') == Some x
)))
(fun h h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun pos1 pos2 ->
if f' sl pos1
then begin
B.upd bres 0ul pos1;
false
end
else true
)
in
let res =
if not_found
then pos'
else B.index bres 0ul
in
HST.pop_frame ();
res
#pop-options
let rec list_existsb_find
(#a: Type)
(f: (a -> Tot bool))
(l: list a)
: Lemma
(L.existsb f l == Some? (L.find f l))
= match l with
| [] -> ()
| x :: q ->
if f x
then ()
else list_existsb_find f q
inline_for_extraction
noextract
let list_existsb
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack bool
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == L.existsb f (contents_list p h sl pos pos')
))
= let h = HST.get () in
list_existsb_find f (contents_list p h sl pos pos');
let posn = list_find j f f' sl pos pos' in
posn <> pos'
#push-options "--fuel 2 --ifuel 1 --z3rlimit 256 --query_stats"
inline_for_extraction
noextract
let list_flatten_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot (list t2))) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2_ res /\
contents_list p2 h' sl2 pos2_ res == y
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= let hz = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos2_ = BF.alloca pos2 1ul in
let h2 = HST.get () in
valid_list_nil p2 hz sl2 pos2;
let fits = list_fold_left_gen
p1
j1
sl1
pos1 pos1'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2))
(fun h ll lr _ ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
B.live h bpos2_ /\ (
let pos2_ = Seq.index (B.as_seq h bpos2_) 0 in
contents_list p1 h0 sl1 pos1 pos1' == ll `List.Tot.append` lr /\
valid_list p2 h sl2 pos2 pos2_ /\
contents_list p2 h sl2 pos2 pos2_ == List.Tot.flatten (List.Tot.map f ll) /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(fun h _ _ _ h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
U32.v pos2 + serialized_list_length s2 (List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1'))) > U32.v sl2.len
)
(fun h h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1l pos1r ->
let pos2_ = B.index bpos2_ 0ul in
let h = HST.get () in
writable_weaken sl2.base (U32.v pos2) (U32.v sl2.len) h (U32.v pos2_) (U32.v sl2.len);
valid_pos_frame_strong p1 h0 sl1 pos1l pos1r (loc_slice_from sl2 pos2) hz;
let res = f' pos1l pos2_ in
let fits = not (res = max_uint32) in
if fits then begin
B.upd bpos2_ 0ul res;
let h' = HST.get () in
writable_modifies sl2.base (U32.v pos2) (U32.v sl2.len) h (B.loc_region_only true (HS.get_tip h1)) h' ;
List.Tot.append_assoc (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l] (contents_list p1 h0 sl1 pos1r pos1');
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l];
valid_list_snoc p1 h0 sl1 pos1 pos1l;
valid_list_append p2 h' sl2 pos2 pos2_ res;
valid_list_nil p2 h' sl2 res;
valid_list_append p2 h' sl2 pos2_ res res
end else begin
let h' = HST.get () in
valid_list_cons p1 h0 sl1 pos1l pos1' ;
valid_list_append p1 h0 sl1 pos1 pos1l pos1' ;
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) (contents_list p1 h0 sl1 pos1l pos1');
serialized_list_length_append s2 (L.flatten (L.map f (contents_list p1 h0 sl1 pos1 pos1l))) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1l pos1')));
serialized_list_length_append s2 (f (contents p1 h0 sl1 pos1l)) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1r pos1')));
valid_list_serialized_list_length s2 h' sl2 pos2 pos2_
end;
fits
)
in
let res =
if fits
then B.index bpos2_ 0ul
else max_uint32
in
HST.pop_frame ();
res
#pop-options
#push-options "--z3rlimit 16 --query_stats"
inline_for_extraction
noextract
let list_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot t2)) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_length s2 y > U32.v sl2.len
else
valid_content_pos p2 h' sl2 pos2_ y res
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1') in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= list_map_list_flatten_map f (contents_list p1 h0 sl1 pos1 pos1');
list_flatten_map
j1
s2
(fun x -> [f x])
h0
sl1 pos1 pos1'
sl2 pos2
(fun pos1 pos2 ->
let res = f' pos1 pos2 in
let h = HST.get () in
if res = max_uint32
then begin
serialized_list_length_nil s2;
serialized_list_length_cons s2 (f (contents p1 h0 sl1 pos1)) []
end
else begin
valid_list_nil p2 h sl2 res;
valid_list_cons p2 h sl2 pos2 res
end;
res
)
(* Example: trivial printers *)
inline_for_extraction
let print_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(print: ((#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack unit (requires (fun h -> valid p h sl pos)) (ensures (fun h _ h' -> B.modifies B.loc_none h h'))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h _ h' ->
B.modifies B.loc_none h h'
))
= let h0 = HST.get () in
list_fold_left
p
j
sl
pos pos'
h0
(Ghost.hide B.loc_none)
(fun _ _ _ _ -> True)
(fun _ _ _ _ _ -> ())
(fun pos1 _ _ _ _ ->
print sl pos1
)
(* Monotonicity *)
inline_for_extraction
let compl_t (t: Type) = U32.t -> t -> U32.t -> Tot (B.spred byte)
let wvalid
(#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos' : Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
: GTot prop
=
U32.v pos <= U32.v (Ghost.reveal gpos') /\
U32.v (Ghost.reveal gpos') <= U32.v s.len /\
U32.v s.len <= Seq.length x /\
parse p (Seq.slice x (U32.v pos) (U32.v s.len)) == Some (Ghost.reveal gv, U32.v (Ghost.reveal gpos') - U32.v pos) /\
compl pos (Ghost.reveal gv) (Ghost.reveal gpos') x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: LowParse.Spec.Base.parser k t ->
s: LowParse.Slice.slice rrel rel ->
compl: LowParse.Low.Base.compl_t t ->
pos: FStar.UInt32.t ->
gpos': FStar.Ghost.erased FStar.UInt32.t ->
gv: FStar.Ghost.erased t ->
x: FStar.Seq.Base.seq LowParse.Bytes.byte ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.wvalid p s compl pos gpos' gv x /\ LowParse.Slice.live_slice h s /\
x == LowStar.Monotonic.Buffer.as_seq h (Mkslice?.base s))
(ensures
LowParse.Low.Base.Spec.valid_content_pos p
h
s
pos
(FStar.Ghost.reveal gv)
(FStar.Ghost.reveal gpos')) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Low.Base.compl_t",
"FStar.UInt32.t",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Base.Spec.valid_facts",
"Prims.unit",
"Prims.l_and",
"LowParse.Low.Base.wvalid",
"LowParse.Slice.live_slice",
"Prims.eq2",
"LowStar.Monotonic.Buffer.as_seq",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"Prims.squash",
"LowParse.Low.Base.Spec.valid_content_pos",
"FStar.Ghost.reveal",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let wvalid_valid_content_pos
(#t: Type)
(#k: parser_kind)
(p: parser k t)
(#rrel #rel: _)
(s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos': Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
(h: HS.mem)
: Lemma (requires (wvalid p s compl pos gpos' gv x /\ live_slice h s /\ x == B.as_seq h s.base))
(ensures (valid_content_pos p h s pos gv gpos')) =
| valid_facts p h s pos | false |
LowParse.Low.Base.fst | LowParse.Low.Base.list_fold_left | val list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos': U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc {B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos')})
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame:
(h: HS.mem -> l1: list t -> l2: list t -> pos1: U32.t -> h': HS.mem
-> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1))
(ensures (inv h' l1 l2 pos1))))
(body:
(
pos1: U32.t ->
pos2: U32.t ->
l1: Ghost.erased (list t) ->
x: Ghost.erased t ->
l2: Ghost.erased (list t)
-> HST.Stack unit
(requires
(fun h ->
B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\ U32.v pos <= U32.v pos1 /\
U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos')
(loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' ==
(Ghost.reveal l1)
`L.append`
(Ghost.reveal x :: Ghost.reveal l2)))
(ensures
(fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h'
((Ghost.reveal l1) `L.append` [contents p h0 sl pos1])
(Ghost.reveal l2)
pos2))))
: HST.Stack unit
(requires
(fun h ->
h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos))
(ensures
(fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\ inv h' (contents_list p h sl pos pos') [] pos')) | val list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos': U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc {B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos')})
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame:
(h: HS.mem -> l1: list t -> l2: list t -> pos1: U32.t -> h': HS.mem
-> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1))
(ensures (inv h' l1 l2 pos1))))
(body:
(
pos1: U32.t ->
pos2: U32.t ->
l1: Ghost.erased (list t) ->
x: Ghost.erased t ->
l2: Ghost.erased (list t)
-> HST.Stack unit
(requires
(fun h ->
B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\ U32.v pos <= U32.v pos1 /\
U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos')
(loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' ==
(Ghost.reveal l1)
`L.append`
(Ghost.reveal x :: Ghost.reveal l2)))
(ensures
(fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h'
((Ghost.reveal l1) `L.append` [contents p h0 sl pos1])
(Ghost.reveal l2)
pos2))))
: HST.Stack unit
(requires
(fun h ->
h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos))
(ensures
(fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\ inv h' (contents_list p h sl pos pos') [] pos')) | let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
() | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 4,
"end_line": 1357,
"start_col": 0,
"start_line": 1286
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: LowParse.Spec.Base.parser k t ->
j: LowParse.Low.Base.jumper p ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t ->
h0: FStar.Monotonic.HyperStack.mem ->
l:
FStar.Ghost.erased LowStar.Monotonic.Buffer.loc
{ LowStar.Monotonic.Buffer.loc_disjoint (FStar.Ghost.reveal l)
(LowParse.Slice.loc_slice_from_to sl pos pos') } ->
inv:
(_: FStar.Monotonic.HyperStack.mem -> _: Prims.list t -> _: Prims.list t -> _: FStar.UInt32.t
-> Prims.GTot Type0) ->
inv_frame:
(
h: FStar.Monotonic.HyperStack.mem ->
l1: Prims.list t ->
l2: Prims.list t ->
pos1: FStar.UInt32.t ->
h': FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_unused_in h0) h h' /\
inv h l1 l2 pos1) (ensures inv h' l1 l2 pos1)) ->
body:
(
pos1: FStar.UInt32.t ->
pos2: FStar.UInt32.t ->
l1: FStar.Ghost.erased (Prims.list t) ->
x: FStar.Ghost.erased t ->
l2: FStar.Ghost.erased (Prims.list t)
-> FStar.HyperStack.ST.Stack Prims.unit)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"FStar.Ghost.erased",
"LowStar.Monotonic.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_disjoint",
"FStar.Ghost.reveal",
"LowParse.Slice.loc_slice_from_to",
"Prims.list",
"Prims.unit",
"Prims.l_and",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_unused_in",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"LowParse.Low.Base.Spec.valid_list",
"LowParse.Low.Base.Spec.valid_content_pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.loc_includes",
"Prims.Cons",
"Prims.eq2",
"LowParse.Low.Base.Spec.contents_list",
"FStar.List.Tot.Base.append",
"LowParse.Low.Base.Spec.contents",
"Prims.bool",
"LowParse.Low.Base.list_fold_left_gen",
"Prims.l_False",
"FStar.Ghost.hide",
"LowParse.Low.Base.Spec.valid_list_append",
"LowParse.Low.Base.Spec.valid_list_cons",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos': U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc {B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos')})
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame:
(h: HS.mem -> l1: list t -> l2: list t -> pos1: U32.t -> h': HS.mem
-> Lemma (requires (B.modifies (B.loc_unused_in h0) h h' /\ inv h l1 l2 pos1))
(ensures (inv h' l1 l2 pos1))))
(body:
(
pos1: U32.t ->
pos2: U32.t ->
l1: Ghost.erased (list t) ->
x: Ghost.erased t ->
l2: Ghost.erased (list t)
-> HST.Stack unit
(requires
(fun h ->
B.modifies (Ghost.reveal l) h0 h /\ valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\ U32.v pos <= U32.v pos1 /\
U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos')
(loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' ==
(Ghost.reveal l1)
`L.append`
(Ghost.reveal x :: Ghost.reveal l2)))
(ensures
(fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h'
((Ghost.reveal l1) `L.append` [contents p h0 sl pos1])
(Ghost.reveal l2)
pos2))))
: HST.Stack unit
(requires
(fun h ->
h == h0 /\ valid_list p h sl pos pos' /\ inv h [] (contents_list p h sl pos pos') pos))
(ensures
(fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\ inv h' (contents_list p h sl pos pos') [] pos')) =
| let _ =
list_fold_left_gen p j sl pos pos' h0 l inv inv_frame (fun _ -> False) (fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'));
true)
in
() | false |
LowParse.Low.Base.fst | LowParse.Low.Base.copy_weak | val copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos: U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ live_slice h dst /\
U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos))
(loc_slice_from dst dpos)))
(ensures
(fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\
(if dpos' = max_uint32
then U32.v dpos + content_length p h src spos > U32.v dst.len
else valid_content_pos p h' dst dpos (contents p h src spos) dpos'))) | val copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos: U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ live_slice h dst /\
U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos))
(loc_slice_from dst dpos)))
(ensures
(fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\
(if dpos' = max_uint32
then U32.v dpos + content_length p h src spos > U32.v dst.len
else valid_content_pos p h' dst dpos (contents p h src spos) dpos'))) | let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 49,
"end_line": 1140,
"start_col": 0,
"start_line": 1111
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: LowParse.Spec.Base.parser k t ->
jmp: LowParse.Low.Base.jumper p ->
src: LowParse.Slice.slice rrel1 rel1 ->
spos: FStar.UInt32.t ->
dst: LowParse.Slice.slice rrel2 rel2 ->
dpos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.copy_weak_with_length",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.Spec.valid",
"LowParse.Slice.live_slice",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"Prims.op_LessThan",
"LowParse.Low.ErrorCode.max_uint32",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"Prims.op_Addition",
"LowParse.Low.Base.Spec.content_length",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowParse.Slice.loc_slice_from_to",
"LowParse.Low.Base.Spec.get_valid_pos",
"LowParse.Slice.loc_slice_from",
"LowStar.Monotonic.Buffer.modifies",
"Prims.op_Equality",
"Prims.op_GreaterThan",
"Prims.bool",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Low.Base.Spec.contents",
"Prims.logical"
] | [] | false | true | false | false | false | let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos: U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
k.parser_kind_subkind == Some ParserStrong /\ valid p h src spos /\ live_slice h dst /\
U32.v dpos <= U32.v dst.len /\ U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos))
(loc_slice_from dst dpos)))
(ensures
(fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\
(if dpos' = max_uint32
then U32.v dpos + content_length p h src spos > U32.v dst.len
else valid_content_pos p h' dst dpos (contents p h src spos) dpos'))) =
| let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos | false |
Vale.Test.X64.Args.fsti | Vale.Test.X64.Args.va_req_Test | val va_req_Test
(va_b0: va_code)
(va_s0: va_state)
(win: bool)
(arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64)
: prop | val va_req_Test
(va_b0: va_code)
(va_s0: va_state)
(win: bool)
(arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64)
: prop | let va_req_Test (va_b0:va_code) (va_s0:va_state) (win:bool) (arg0:buffer64) (arg1:buffer64)
(arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) :
prop =
(va_require_total va_b0 (va_code_Test win) va_s0 /\ va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 ==
Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap
(va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\ (win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0))
/\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16)
(va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 +
32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64
(va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRcx va_s0 else
va_get_reg64 rRdi va_s0) arg0 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else
va_get_reg64 rRsi va_s0) arg1 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR8 va_s0 else
va_get_reg64 rRdx va_s0) arg2 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR9 va_s0 else
va_get_reg64 rRcx va_s0) arg3 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) arg4 0
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win
then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)
else va_get_reg64 rR9 va_s0) arg5 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) arg6 0 (va_get_mem_layout va_s0) Secret
/\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) arg7 0 (va_get_mem_layout va_s0) Secret) | {
"file_name": "obj/Vale.Test.X64.Args.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 100,
"end_line": 50,
"start_col": 0,
"start_line": 19
} | module Vale.Test.X64.Args
open Vale.Arch.HeapImpl
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.Stack_i
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
#set-options "--z3rlimit 20"
//-- Test
val va_code_Test : win:bool -> Tot va_code | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Test.X64.Args.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Test.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Test.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
va_b0: Vale.X64.Decls.va_code ->
va_s0: Vale.X64.Decls.va_state ->
win: Prims.bool ->
arg0: Vale.X64.Memory.buffer64 ->
arg1: Vale.X64.Memory.buffer64 ->
arg2: Vale.X64.Memory.buffer64 ->
arg3: Vale.X64.Memory.buffer64 ->
arg4: Vale.X64.Memory.buffer64 ->
arg5: Vale.X64.Memory.buffer64 ->
arg6: Vale.X64.Memory.buffer64 ->
arg7: Vale.X64.Memory.buffer64
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Decls.va_code",
"Vale.X64.Decls.va_state",
"Prims.bool",
"Vale.X64.Memory.buffer64",
"Prims.l_and",
"Vale.X64.Decls.va_require_total",
"Vale.Test.X64.Args.va_code_Test",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Prims.eq2",
"Vale.Def.Words_s.nat64",
"Vale.X64.Decls.va_get_reg64",
"Vale.X64.Machine_s.rRsp",
"Vale.X64.Stack_i.init_rsp",
"Vale.X64.Decls.va_get_stack",
"Vale.X64.Memory.is_initial_heap",
"Vale.X64.Decls.va_get_mem_layout",
"Vale.X64.Decls.va_get_mem",
"Prims.l_imp",
"Vale.X64.Stack_i.valid_src_stack64",
"Prims.op_Addition",
"Prims.l_not",
"Vale.X64.Decls.validSrcAddrs64",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Machine_s.rRdi",
"Prims.int",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.X64.Machine_s.rRdx",
"Vale.X64.Machine_s.rRsi",
"Vale.X64.Machine_s.rR8",
"Vale.X64.Machine_s.rR9",
"Vale.X64.Stack_i.load_stack64",
"Prims.prop"
] | [] | false | false | false | true | true | let va_req_Test
(va_b0: va_code)
(va_s0: va_state)
(win: bool)
(arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64)
: prop =
| (va_require_total va_b0 (va_code_Test win) va_s0 /\ va_get_ok va_s0 /\
va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\
Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\
(win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) /\
(~win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\
(~win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(if win then va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0)
arg0
0
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0)
arg1
0
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(if win then va_get_reg64 rR8 va_s0 else va_get_reg64 rRdx va_s0)
arg2
0
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(if win then va_get_reg64 rR9 va_s0 else va_get_reg64 rRcx va_s0)
arg3
0
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(if win
then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)
else va_get_reg64 rR8 va_s0)
arg4
0
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(if win
then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)
else va_get_reg64 rR9 va_s0)
arg5
0
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(if win
then
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0)
else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0))
arg6
0
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(if win
then
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)
else Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0))
arg7
0
(va_get_mem_layout va_s0)
Secret) | false |
LowParse.Low.Base.fst | LowParse.Low.Base.recall_valid_gen | val recall_valid_gen
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(#s: slice rrel rel)
(#compl: compl_t t)
(i: irepr p s compl)
: HST.Stack unit
(requires (fun h -> B.recallable s.base \/ live_slice h s))
(ensures
(fun h _ h' ->
h' == h /\ live_slice h s /\
valid_content_pos p h s (irepr_pos i) (irepr_v i) (irepr_pos' i) /\
compl (irepr_pos i) (irepr_v i) (irepr_pos' i) (B.as_seq h s.base))) | val recall_valid_gen
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(#s: slice rrel rel)
(#compl: compl_t t)
(i: irepr p s compl)
: HST.Stack unit
(requires (fun h -> B.recallable s.base \/ live_slice h s))
(ensures
(fun h _ h' ->
h' == h /\ live_slice h s /\
valid_content_pos p h s (irepr_pos i) (irepr_v i) (irepr_pos' i) /\
compl (irepr_pos i) (irepr_v i) (irepr_pos' i) (B.as_seq h s.base))) | let recall_valid_gen
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(#s: slice rrel rel)
(#compl: compl_t t)
(i: irepr p s compl)
: HST.Stack unit
(requires (fun h -> B.recallable s.base \/ live_slice h s))
(ensures (fun h _ h' ->
h' == h /\
live_slice h s /\
valid_content_pos p h s (irepr_pos i) (irepr_v i) (irepr_pos' i) /\
compl (irepr_pos i) (irepr_v i) (irepr_pos' i) (B.as_seq h s.base)
))
= let h = HST.get () in
B.recall_p s.base (wvalid p s compl (irepr_pos i) (IRepr?.gpos' i) (IRepr?.gv i));
wvalid_valid_content_pos p s compl (irepr_pos i) (IRepr?.gpos' i) (IRepr?.gv i) (B.as_seq h s.base) h | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 103,
"end_line": 2135,
"start_col": 0,
"start_line": 2117
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
()
inline_for_extraction
let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len
#push-options "--z3rlimit 32 --fuel 2 --ifuel 1"
inline_for_extraction
let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
(x: Ghost.erased t) ->
HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
(#rrel_out #rel_out: _)
(sl_out : slice rrel_out rel_out)
(pos_out : U32.t)
: HST.Stack U32.t
(requires (fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\
valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out
))
(ensures (fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
//B.fresh_frame_modifies h0 h1;
let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\ (
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow
)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))
inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then begin
assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2
end else
L.append_l_nil (L.filter f (G.reveal l1))
)
;
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out'
#pop-options
#push-options "--z3rlimit 64 --fuel 2 --ifuel 1"
inline_for_extraction
let list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(i: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos' /\
U32.v i < L.length (contents_list p h sl pos pos')
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid_list p h sl pos res /\
valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos1 = BF.alloca pos 1ul in
let bk = BF.alloca 0ul 1ul in
let h2 = HST.get () in
valid_list_nil p h0 sl pos;
let _ : bool = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
let k = Seq.index (B.as_seq h bk) 0 in
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bpos1 /\
B.live h bk /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v k /\
U32.v k <= U32.v i
)
(fun h _ _ _ h' ->
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1);
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk);
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
let pos1 = Seq.index (B.as_seq h bpos1) 0 in
B.live h bpos1 /\
valid p h0 sl pos1 /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v i /\
contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)
)
(fun _ _ ->
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 ->
let k = B.index bk 0ul in
if k = i
then begin
B.upd bpos1 0ul pos1;
valid_list_cons_recip p h0 sl pos1 pos';
list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i);
valid_list_append p h0 sl pos pos1 pos' ;
assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i));
false
end else begin
B.upd bk 0ul (k `U32.add` 1ul);
let h = HST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h;
valid_list_snoc p h0 sl pos pos1;
assert (valid p h0 sl pos1);
assert (pos2 == get_valid_pos p h0 sl pos1);
assert (valid_list p h0 sl pos pos2);
list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1];
true
end
)
in
let res = B.index bpos1 0ul in
HST.pop_frame ();
res
inline_for_extraction
let list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\
valid p h sl res /\ (
let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\
f x == true /\
L.find f l == Some x
)
)))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bres = BF.alloca 0ul 1ul in
let h2 = HST.get () in
let not_found = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\
valid_list p h0 sl pos1 pos' /\
l2 == contents_list p h0 sl pos1 pos' /\
L.find f (contents_list p h0 sl pos pos') == L.find f l2
)
(fun h _ _ _ h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\ (
let res = Seq.index (B.as_seq h bres) 0 in
U32.v pos <= U32.v res /\
valid p h0 sl res /\ (
let x = contents p h0 sl res in
U32.v res + content_length p h0 sl res <= U32.v pos' /\
f x == true /\
L.find f (contents_list p h0 sl pos pos') == Some x
)))
(fun h h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun pos1 pos2 ->
if f' sl pos1
then begin
B.upd bres 0ul pos1;
false
end
else true
)
in
let res =
if not_found
then pos'
else B.index bres 0ul
in
HST.pop_frame ();
res
#pop-options
let rec list_existsb_find
(#a: Type)
(f: (a -> Tot bool))
(l: list a)
: Lemma
(L.existsb f l == Some? (L.find f l))
= match l with
| [] -> ()
| x :: q ->
if f x
then ()
else list_existsb_find f q
inline_for_extraction
noextract
let list_existsb
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack bool
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == L.existsb f (contents_list p h sl pos pos')
))
= let h = HST.get () in
list_existsb_find f (contents_list p h sl pos pos');
let posn = list_find j f f' sl pos pos' in
posn <> pos'
#push-options "--fuel 2 --ifuel 1 --z3rlimit 256 --query_stats"
inline_for_extraction
noextract
let list_flatten_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot (list t2))) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2_ res /\
contents_list p2 h' sl2 pos2_ res == y
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= let hz = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos2_ = BF.alloca pos2 1ul in
let h2 = HST.get () in
valid_list_nil p2 hz sl2 pos2;
let fits = list_fold_left_gen
p1
j1
sl1
pos1 pos1'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2))
(fun h ll lr _ ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
B.live h bpos2_ /\ (
let pos2_ = Seq.index (B.as_seq h bpos2_) 0 in
contents_list p1 h0 sl1 pos1 pos1' == ll `List.Tot.append` lr /\
valid_list p2 h sl2 pos2 pos2_ /\
contents_list p2 h sl2 pos2 pos2_ == List.Tot.flatten (List.Tot.map f ll) /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(fun h _ _ _ h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
U32.v pos2 + serialized_list_length s2 (List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1'))) > U32.v sl2.len
)
(fun h h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1l pos1r ->
let pos2_ = B.index bpos2_ 0ul in
let h = HST.get () in
writable_weaken sl2.base (U32.v pos2) (U32.v sl2.len) h (U32.v pos2_) (U32.v sl2.len);
valid_pos_frame_strong p1 h0 sl1 pos1l pos1r (loc_slice_from sl2 pos2) hz;
let res = f' pos1l pos2_ in
let fits = not (res = max_uint32) in
if fits then begin
B.upd bpos2_ 0ul res;
let h' = HST.get () in
writable_modifies sl2.base (U32.v pos2) (U32.v sl2.len) h (B.loc_region_only true (HS.get_tip h1)) h' ;
List.Tot.append_assoc (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l] (contents_list p1 h0 sl1 pos1r pos1');
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l];
valid_list_snoc p1 h0 sl1 pos1 pos1l;
valid_list_append p2 h' sl2 pos2 pos2_ res;
valid_list_nil p2 h' sl2 res;
valid_list_append p2 h' sl2 pos2_ res res
end else begin
let h' = HST.get () in
valid_list_cons p1 h0 sl1 pos1l pos1' ;
valid_list_append p1 h0 sl1 pos1 pos1l pos1' ;
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) (contents_list p1 h0 sl1 pos1l pos1');
serialized_list_length_append s2 (L.flatten (L.map f (contents_list p1 h0 sl1 pos1 pos1l))) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1l pos1')));
serialized_list_length_append s2 (f (contents p1 h0 sl1 pos1l)) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1r pos1')));
valid_list_serialized_list_length s2 h' sl2 pos2 pos2_
end;
fits
)
in
let res =
if fits
then B.index bpos2_ 0ul
else max_uint32
in
HST.pop_frame ();
res
#pop-options
#push-options "--z3rlimit 16 --query_stats"
inline_for_extraction
noextract
let list_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot t2)) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_length s2 y > U32.v sl2.len
else
valid_content_pos p2 h' sl2 pos2_ y res
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1') in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= list_map_list_flatten_map f (contents_list p1 h0 sl1 pos1 pos1');
list_flatten_map
j1
s2
(fun x -> [f x])
h0
sl1 pos1 pos1'
sl2 pos2
(fun pos1 pos2 ->
let res = f' pos1 pos2 in
let h = HST.get () in
if res = max_uint32
then begin
serialized_list_length_nil s2;
serialized_list_length_cons s2 (f (contents p1 h0 sl1 pos1)) []
end
else begin
valid_list_nil p2 h sl2 res;
valid_list_cons p2 h sl2 pos2 res
end;
res
)
(* Example: trivial printers *)
inline_for_extraction
let print_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(print: ((#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack unit (requires (fun h -> valid p h sl pos)) (ensures (fun h _ h' -> B.modifies B.loc_none h h'))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h _ h' ->
B.modifies B.loc_none h h'
))
= let h0 = HST.get () in
list_fold_left
p
j
sl
pos pos'
h0
(Ghost.hide B.loc_none)
(fun _ _ _ _ -> True)
(fun _ _ _ _ _ -> ())
(fun pos1 _ _ _ _ ->
print sl pos1
)
(* Monotonicity *)
inline_for_extraction
let compl_t (t: Type) = U32.t -> t -> U32.t -> Tot (B.spred byte)
let wvalid
(#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos' : Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
: GTot prop
=
U32.v pos <= U32.v (Ghost.reveal gpos') /\
U32.v (Ghost.reveal gpos') <= U32.v s.len /\
U32.v s.len <= Seq.length x /\
parse p (Seq.slice x (U32.v pos) (U32.v s.len)) == Some (Ghost.reveal gv, U32.v (Ghost.reveal gpos') - U32.v pos) /\
compl pos (Ghost.reveal gv) (Ghost.reveal gpos') x
let wvalid_valid_content_pos
(#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos' : Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
(h: HS.mem)
: Lemma
(requires (
wvalid p s compl pos gpos' gv x /\
live_slice h s /\
x == B.as_seq h s.base
))
(ensures (
valid_content_pos p h s pos gv gpos'
))
=
valid_facts p h s pos
inline_for_extraction
noeq
type irepr (#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel) (compl: compl_t t) =
| IRepr:
(pos: U32.t) ->
(gpos' : Ghost.erased U32.t) ->
(gv: Ghost.erased t) ->
(irepr_correct: squash (
U32.v pos <= U32.v (Ghost.reveal gpos') /\
U32.v (Ghost.reveal gpos') <= U32.v s.len /\
B.witnessed s.base (wvalid p s compl pos gpos' gv)
)) ->
irepr p s compl
inline_for_extraction
let irepr_pos
(#t: Type) (#k: parser_kind) (#p: parser k t) (#rrel #rel: _) (#s: slice rrel rel) (#compl: compl_t t) (x: irepr p s compl) : Tot U32.t =
IRepr?.pos x
let irepr_pos'
(#t: Type) (#k: parser_kind) (#p: parser k t) (#rrel #rel: _) (#s: slice rrel rel) (#compl: compl_t t) (x: irepr p s compl) : Ghost U32.t
(requires True)
(ensures (fun y -> True))
= Ghost.reveal (IRepr?.gpos' x)
#push-options "--ifuel 1 --fuel 2"
let irepr_pos'_post
(#t: Type) (#k: parser_kind) (#p: parser k t) (#rrel #rel: _) (#s: slice rrel rel) (#compl: compl_t t) (x: irepr p s compl) : Lemma
(requires True)
(ensures (
let y = irepr_pos' x in
U32.v (irepr_pos x) <= U32.v y /\ U32.v y <= U32.v s.len
))
[SMTPat (irepr_pos' x)]
= ()
let irepr_v
(#t: Type) (#k: parser_kind) (#p: parser k t) (#rrel #rel: _) (#s: slice rrel rel) (#compl: compl_t t) (x: irepr p s compl) : GTot t
= Ghost.reveal (IRepr?.gv x)
inline_for_extraction
let witness_valid_gen
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
: HST.Stack (irepr p s compl)
(requires (fun h ->
valid p h s pos /\
B.stable_on (wvalid p s compl pos (Ghost.hide (get_valid_pos p h s pos)) (Ghost.hide (contents p h s pos))) (buffer_srel_of_srel rel) /\
compl pos (contents p h s pos) (get_valid_pos p h s pos) (B.as_seq h s.base)
))
(ensures (fun h res h' ->
h' == h /\
irepr_pos res == pos /\
valid_content_pos p h s pos (irepr_v res) (irepr_pos' res)
))
= let h = HST.get () in
[@inline_let]
let gpos' = Ghost.hide (get_valid_pos p h s pos) in
[@inline_let]
let gv = Ghost.hide (contents p h s pos) in
[@inline_let]
let _ = valid_facts p h s pos in
B.witness_p s.base (wvalid p s compl pos gpos' gv);
IRepr pos gpos' gv () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: LowParse.Low.Base.irepr p s compl -> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Low.Base.compl_t",
"LowParse.Low.Base.irepr",
"LowParse.Low.Base.wvalid_valid_content_pos",
"LowParse.Low.Base.irepr_pos",
"LowParse.Low.Base.__proj__IRepr__item__gpos'",
"LowParse.Low.Base.__proj__IRepr__item__gv",
"LowStar.Monotonic.Buffer.as_seq",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"Prims.unit",
"LowStar.Monotonic.Buffer.recall_p",
"LowParse.Low.Base.wvalid",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.l_or",
"LowStar.Monotonic.Buffer.recallable",
"LowParse.Slice.live_slice",
"Prims.l_and",
"Prims.eq2",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Low.Base.irepr_v",
"LowParse.Low.Base.irepr_pos'"
] | [] | false | true | false | false | false | let recall_valid_gen
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(#s: slice rrel rel)
(#compl: compl_t t)
(i: irepr p s compl)
: HST.Stack unit
(requires (fun h -> B.recallable s.base \/ live_slice h s))
(ensures
(fun h _ h' ->
h' == h /\ live_slice h s /\
valid_content_pos p h s (irepr_pos i) (irepr_v i) (irepr_pos' i) /\
compl (irepr_pos i) (irepr_v i) (irepr_pos' i) (B.as_seq h s.base))) =
| let h = HST.get () in
B.recall_p s.base (wvalid p s compl (irepr_pos i) (IRepr?.gpos' i) (IRepr?.gv i));
wvalid_valid_content_pos p
s
compl
(irepr_pos i)
(IRepr?.gpos' i)
(IRepr?.gv i)
(B.as_seq h s.base)
h | false |
Vale.Test.X64.Args.fsti | Vale.Test.X64.Args.va_ens_Test | val va_ens_Test
(va_b0: va_code)
(va_s0: va_state)
(win: bool)
(arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64)
(va_sM: va_state)
(va_fM: va_fuel)
: prop | val va_ens_Test
(va_b0: va_code)
(va_s0: va_state)
(win: bool)
(arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64)
(va_sM: va_state)
(va_fM: va_fuel)
: prop | let va_ens_Test (va_b0:va_code) (va_s0:va_state) (win:bool) (arg0:buffer64) (arg1:buffer64)
(arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64)
(va_sM:va_state) (va_fM:va_fuel) : prop =
(va_req_Test va_b0 va_s0 win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 /\ va_ensure_total va_b0
va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\
va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0 /\ va_get_reg64 rRbp va_sM == va_get_reg64
rRbp va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\ va_get_reg64 rR13 va_sM ==
va_get_reg64 rR13 va_s0 /\ va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0 /\ va_get_reg64
rR15 va_sM == va_get_reg64 rR15 va_s0 /\ (win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi
va_s0) /\ (win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\ (win ==> va_get_xmm 6
va_sM == va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==>
va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0)
/\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM ==
va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==>
va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14
va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ Vale.X64.Decls.modifies_mem
loc_none (va_get_mem va_s0) (va_get_mem va_sM) /\ va_state_eq va_sM (va_update_mem_layout va_sM
(va_update_mem_heaplet 0 va_sM (va_update_flags va_sM (va_update_xmm 15 va_sM (va_update_xmm 14
va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10
va_sM (va_update_xmm 9 va_sM (va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6
va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2
va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR15 va_sM
(va_update_reg64 rR14 va_sM (va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM
(va_update_reg64 rR11 va_sM (va_update_reg64 rR10 va_sM (va_update_reg64 rR9 va_sM
(va_update_reg64 rR8 va_sM (va_update_reg64 rRsp va_sM (va_update_reg64 rRbp va_sM
(va_update_reg64 rRdi va_sM (va_update_reg64 rRsi va_sM (va_update_reg64 rRdx va_sM
(va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM
(va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))))))))))))))))))))))))))))))) | {
"file_name": "obj/Vale.Test.X64.Args.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 88,
"end_line": 78,
"start_col": 0,
"start_line": 51
} | module Vale.Test.X64.Args
open Vale.Arch.HeapImpl
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.Stack_i
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
#set-options "--z3rlimit 20"
//-- Test
val va_code_Test : win:bool -> Tot va_code
val va_codegen_success_Test : win:bool -> Tot va_pbool
let va_req_Test (va_b0:va_code) (va_s0:va_state) (win:bool) (arg0:buffer64) (arg1:buffer64)
(arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) :
prop =
(va_require_total va_b0 (va_code_Test win) va_s0 /\ va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 ==
Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap
(va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\ (win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0))
/\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16)
(va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 +
32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64
(va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRcx va_s0 else
va_get_reg64 rRdi va_s0) arg0 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else
va_get_reg64 rRsi va_s0) arg1 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR8 va_s0 else
va_get_reg64 rRdx va_s0) arg2 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR9 va_s0 else
va_get_reg64 rRcx va_s0) arg3 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) arg4 0
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win
then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)
else va_get_reg64 rR9 va_s0) arg5 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) arg6 0 (va_get_mem_layout va_s0) Secret
/\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Test.X64.Args.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Test.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Test.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
va_b0: Vale.X64.Decls.va_code ->
va_s0: Vale.X64.Decls.va_state ->
win: Prims.bool ->
arg0: Vale.X64.Memory.buffer64 ->
arg1: Vale.X64.Memory.buffer64 ->
arg2: Vale.X64.Memory.buffer64 ->
arg3: Vale.X64.Memory.buffer64 ->
arg4: Vale.X64.Memory.buffer64 ->
arg5: Vale.X64.Memory.buffer64 ->
arg6: Vale.X64.Memory.buffer64 ->
arg7: Vale.X64.Memory.buffer64 ->
va_sM: Vale.X64.Decls.va_state ->
va_fM: Vale.X64.Decls.va_fuel
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Vale.X64.Decls.va_code",
"Vale.X64.Decls.va_state",
"Prims.bool",
"Vale.X64.Memory.buffer64",
"Vale.X64.Decls.va_fuel",
"Prims.l_and",
"Vale.Test.X64.Args.va_req_Test",
"Vale.X64.Decls.va_ensure_total",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Prims.eq2",
"Vale.Def.Types_s.nat64",
"Vale.X64.Decls.va_get_reg64",
"Vale.X64.Machine_s.rRsp",
"Vale.X64.Machine_s.rRbx",
"Vale.X64.Machine_s.rRbp",
"Vale.X64.Machine_s.rR12",
"Vale.X64.Machine_s.rR13",
"Vale.X64.Machine_s.rR14",
"Vale.X64.Machine_s.rR15",
"Prims.l_imp",
"Vale.X64.Machine_s.rRdi",
"Vale.X64.Machine_s.rRsi",
"Vale.X64.Decls.quad32",
"Vale.X64.Decls.va_get_xmm",
"Vale.X64.Decls.modifies_mem",
"Vale.X64.Memory.loc_none",
"Vale.X64.Decls.va_get_mem",
"Vale.X64.Decls.va_state_eq",
"Vale.X64.Decls.va_update_mem_layout",
"Vale.X64.Decls.va_update_mem_heaplet",
"Vale.X64.Decls.va_update_flags",
"Vale.X64.Decls.va_update_xmm",
"Vale.X64.Decls.va_update_reg64",
"Vale.X64.Machine_s.rR11",
"Vale.X64.Machine_s.rR10",
"Vale.X64.Machine_s.rR9",
"Vale.X64.Machine_s.rR8",
"Vale.X64.Machine_s.rRdx",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Machine_s.rRax",
"Vale.X64.Decls.va_update_ok",
"Vale.X64.Decls.va_update_mem",
"Prims.prop"
] | [] | false | false | false | true | true | let va_ens_Test
(va_b0: va_code)
(va_s0: va_state)
(win: bool)
(arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64)
(va_sM: va_state)
(va_fM: va_fuel)
: prop =
| (va_req_Test va_b0 va_s0 win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 /\
va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\
va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0 /\
va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0 /\
va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\
va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0 /\
va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0 /\
va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0 /\
(win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0) /\
(win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\
(win ==> va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\
(win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\
(win ==> va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\
(win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0) /\
(win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\
(win ==> va_get_xmm 11 va_sM == va_get_xmm 11 va_s0) /\
(win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\
(win ==> va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\
(win ==> va_get_xmm 14 va_sM == va_get_xmm 14 va_s0) /\
(win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\
Vale.X64.Decls.modifies_mem loc_none (va_get_mem va_s0) (va_get_mem va_sM) /\
va_state_eq va_sM
(va_update_mem_layout va_sM
(va_update_mem_heaplet 0
va_sM
(va_update_flags va_sM
(va_update_xmm 15
va_sM
(va_update_xmm 14
va_sM
(va_update_xmm 13
va_sM
(va_update_xmm 12
va_sM
(va_update_xmm 11
va_sM
(va_update_xmm 10
va_sM
(va_update_xmm 9
va_sM
(va_update_xmm 8
va_sM
(va_update_xmm 7
va_sM
(va_update_xmm 6
va_sM
(va_update_xmm 5
va_sM
(va_update_xmm 4
va_sM
(va_update_xmm 3
va_sM
(va_update_xmm 2
va_sM
(va_update_xmm 1
va_sM
(va_update_xmm 0
va_sM
(va_update_reg64 rR15
va_sM
(va_update_reg64
rR14
va_sM
(va_update_reg64
rR13
va_sM
(va_update_reg64
rR12
va_sM
(va_update_reg64
rR11
va_sM
(
va_update_reg64
rR10
va_sM
(
va_update_reg64
rR9
va_sM
(
va_update_reg64
rR8
va_sM
(
va_update_reg64
rRsp
va_sM
(
va_update_reg64
rRbp
va_sM
(
va_update_reg64
rRdi
va_sM
(
va_update_reg64
rRsi
va_sM
(
va_update_reg64
rRdx
va_sM
(
va_update_reg64
rRcx
va_sM
(
va_update_reg64
rRbx
va_sM
(
va_update_reg64
rRax
va_sM
(
va_update_ok
va_sM
(
va_update_mem
va_sM
va_s0
)
)
)
)
)
)
)
)
)
)
)
)
)
))
))))))))))))
))))))))))) | false |
Vale.Test.X64.Args.fsti | Vale.Test.X64.Args.va_wp_Test | val va_wp_Test
(win: bool)
(arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_Test
(win: bool)
(arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_Test (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64)
(arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) (va_s0:va_state) (va_k:(va_state
-> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\
Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0))
/\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8)
(va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 +
32 + 8 + 16) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64
rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64
(va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rRcx va_s0)
(fun _ -> va_get_reg64 rRdi va_s0)) arg0 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rRdx va_s0)
(fun _ -> va_get_reg64 rRsi va_s0)) arg1 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rR8 va_s0)
(fun _ -> va_get_reg64 rRdx va_s0)) arg2 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rR9 va_s0)
(fun _ -> va_get_reg64 rRcx va_s0)) arg3 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) (fun
_ -> va_get_reg64 rR8 va_s0)) arg4 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) (fun
_ -> va_get_reg64 rR9 va_s0)) arg5 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0))
(fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack
va_s0))) arg6 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem
va_s0) (va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 +
24) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8
+ 8) (va_get_stack va_s0))) arg7 0 (va_get_mem_layout va_s0) Secret /\ (forall
(va_x_mem:vale_heap) (va_x_rax:nat64) (va_x_rbx:nat64) (va_x_rcx:nat64) (va_x_rdx:nat64)
(va_x_rsi:nat64) (va_x_rdi:nat64) (va_x_rbp:nat64) (va_x_rsp:nat64) (va_x_r8:nat64)
(va_x_r9:nat64) (va_x_r10:nat64) (va_x_r11:nat64) (va_x_r12:nat64) (va_x_r13:nat64)
(va_x_r14:nat64) (va_x_r15:nat64) (va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32)
(va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32) (va_x_xmm7:quad32)
(va_x_xmm8:quad32) (va_x_xmm9:quad32) (va_x_xmm10:quad32) (va_x_xmm11:quad32)
(va_x_xmm12:quad32) (va_x_xmm13:quad32) (va_x_xmm14:quad32) (va_x_xmm15:quad32)
(va_x_efl:Vale.X64.Flags.t) (va_x_heap0:vale_heap) (va_x_memLayout:vale_heap_layout) . let
va_sM = va_upd_mem_layout va_x_memLayout (va_upd_mem_heaplet 0 va_x_heap0 (va_upd_flags
va_x_efl (va_upd_xmm 15 va_x_xmm15 (va_upd_xmm 14 va_x_xmm14 (va_upd_xmm 13 va_x_xmm13
(va_upd_xmm 12 va_x_xmm12 (va_upd_xmm 11 va_x_xmm11 (va_upd_xmm 10 va_x_xmm10 (va_upd_xmm 9
va_x_xmm9 (va_upd_xmm 8 va_x_xmm8 (va_upd_xmm 7 va_x_xmm7 (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5
va_x_xmm5 (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1
va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_reg64 rR15 va_x_r15 (va_upd_reg64 rR14 va_x_r14
(va_upd_reg64 rR13 va_x_r13 (va_upd_reg64 rR12 va_x_r12 (va_upd_reg64 rR11 va_x_r11
(va_upd_reg64 rR10 va_x_r10 (va_upd_reg64 rR9 va_x_r9 (va_upd_reg64 rR8 va_x_r8 (va_upd_reg64
rRsp va_x_rsp (va_upd_reg64 rRbp va_x_rbp (va_upd_reg64 rRdi va_x_rdi (va_upd_reg64 rRsi
va_x_rsi (va_upd_reg64 rRdx va_x_rdx (va_upd_reg64 rRcx va_x_rcx (va_upd_reg64 rRbx va_x_rbx
(va_upd_reg64 rRax va_x_rax (va_upd_mem va_x_mem va_s0))))))))))))))))))))))))))))))))))) in
va_get_ok va_sM /\ va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\ va_get_reg64 rRbx
va_sM == va_get_reg64 rRbx va_s0 /\ va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0 /\
va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\ va_get_reg64 rR13 va_sM == va_get_reg64
rR13 va_s0 /\ va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0 /\ va_get_reg64 rR15 va_sM ==
va_get_reg64 rR15 va_s0 /\ (win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0) /\ (win
==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\ (win ==> va_get_xmm 6 va_sM ==
va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==>
va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0)
/\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM ==
va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==>
va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14
va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ Vale.X64.Decls.modifies_mem
loc_none (va_get_mem va_s0) (va_get_mem va_sM) ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.Test.X64.Args.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 72,
"end_line": 204,
"start_col": 0,
"start_line": 140
} | module Vale.Test.X64.Args
open Vale.Arch.HeapImpl
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.Stack_i
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
#set-options "--z3rlimit 20"
//-- Test
val va_code_Test : win:bool -> Tot va_code
val va_codegen_success_Test : win:bool -> Tot va_pbool
let va_req_Test (va_b0:va_code) (va_s0:va_state) (win:bool) (arg0:buffer64) (arg1:buffer64)
(arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) :
prop =
(va_require_total va_b0 (va_code_Test win) va_s0 /\ va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 ==
Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap
(va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\ (win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0))
/\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16)
(va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 +
32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64
(va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRcx va_s0 else
va_get_reg64 rRdi va_s0) arg0 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else
va_get_reg64 rRsi va_s0) arg1 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR8 va_s0 else
va_get_reg64 rRdx va_s0) arg2 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR9 va_s0 else
va_get_reg64 rRcx va_s0) arg3 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) arg4 0
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win
then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)
else va_get_reg64 rR9 va_s0) arg5 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) arg6 0 (va_get_mem_layout va_s0) Secret
/\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) arg7 0 (va_get_mem_layout va_s0) Secret)
let va_ens_Test (va_b0:va_code) (va_s0:va_state) (win:bool) (arg0:buffer64) (arg1:buffer64)
(arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64)
(va_sM:va_state) (va_fM:va_fuel) : prop =
(va_req_Test va_b0 va_s0 win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 /\ va_ensure_total va_b0
va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\
va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0 /\ va_get_reg64 rRbp va_sM == va_get_reg64
rRbp va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\ va_get_reg64 rR13 va_sM ==
va_get_reg64 rR13 va_s0 /\ va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0 /\ va_get_reg64
rR15 va_sM == va_get_reg64 rR15 va_s0 /\ (win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi
va_s0) /\ (win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\ (win ==> va_get_xmm 6
va_sM == va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==>
va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0)
/\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM ==
va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==>
va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14
va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ Vale.X64.Decls.modifies_mem
loc_none (va_get_mem va_s0) (va_get_mem va_sM) /\ va_state_eq va_sM (va_update_mem_layout va_sM
(va_update_mem_heaplet 0 va_sM (va_update_flags va_sM (va_update_xmm 15 va_sM (va_update_xmm 14
va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10
va_sM (va_update_xmm 9 va_sM (va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6
va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2
va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR15 va_sM
(va_update_reg64 rR14 va_sM (va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM
(va_update_reg64 rR11 va_sM (va_update_reg64 rR10 va_sM (va_update_reg64 rR9 va_sM
(va_update_reg64 rR8 va_sM (va_update_reg64 rRsp va_sM (va_update_reg64 rRbp va_sM
(va_update_reg64 rRdi va_sM (va_update_reg64 rRsi va_sM (va_update_reg64 rRdx va_sM
(va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM
(va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))))))))))))))))))))))))))))
val va_lemma_Test : va_b0:va_code -> va_s0:va_state -> win:bool -> arg0:buffer64 -> arg1:buffer64
-> arg2:buffer64 -> arg3:buffer64 -> arg4:buffer64 -> arg5:buffer64 -> arg6:buffer64 ->
arg7:buffer64
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Test win) va_s0 /\ va_get_ok va_s0 /\ va_get_reg64
rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap
(va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\ (win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0))
/\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16)
(va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 +
32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64
(va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRcx va_s0 else
va_get_reg64 rRdi va_s0) arg0 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else
va_get_reg64 rRsi va_s0) arg1 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR8 va_s0 else
va_get_reg64 rRdx va_s0) arg2 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR9 va_s0 else
va_get_reg64 rRcx va_s0) arg3 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) arg4 0
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win
then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)
else va_get_reg64 rR9 va_s0) arg5 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) arg6 0 (va_get_mem_layout va_s0) Secret
/\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) arg7 0 (va_get_mem_layout va_s0)
Secret))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\ va_get_reg64 rRbx va_sM == va_get_reg64
rRbx va_s0 /\ va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0 /\ va_get_reg64 rR12 va_sM ==
va_get_reg64 rR12 va_s0 /\ va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0 /\ va_get_reg64
rR14 va_sM == va_get_reg64 rR14 va_s0 /\ va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0 /\
(win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0) /\ (win ==> va_get_reg64 rRsi
va_sM == va_get_reg64 rRsi va_s0) /\ (win ==> va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\ (win
==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==> va_get_xmm 8 va_sM == va_get_xmm 8
va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0) /\ (win ==> va_get_xmm 10 va_sM ==
va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM == va_get_xmm 11 va_s0) /\ (win ==>
va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==> va_get_xmm 13 va_sM == va_get_xmm 13
va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14 va_s0) /\ (win ==> va_get_xmm 15 va_sM
== va_get_xmm 15 va_s0) /\ Vale.X64.Decls.modifies_mem loc_none (va_get_mem va_s0) (va_get_mem
va_sM) /\ va_state_eq va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 0 va_sM
(va_update_flags va_sM (va_update_xmm 15 va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM
(va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM
(va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM
(va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_xmm 0 va_sM (va_update_reg64 rR15 va_sM (va_update_reg64 rR14 va_sM (va_update_reg64
rR13 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR11 va_sM (va_update_reg64 rR10 va_sM
(va_update_reg64 rR9 va_sM (va_update_reg64 rR8 va_sM (va_update_reg64 rRsp va_sM
(va_update_reg64 rRbp va_sM (va_update_reg64 rRdi va_sM (va_update_reg64 rRsi va_sM
(va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM
(va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM
va_s0))))))))))))))))))))))))))))))))))))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Test.X64.Args.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Test.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Test.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
win: Prims.bool ->
arg0: Vale.X64.Memory.buffer64 ->
arg1: Vale.X64.Memory.buffer64 ->
arg2: Vale.X64.Memory.buffer64 ->
arg3: Vale.X64.Memory.buffer64 ->
arg4: Vale.X64.Memory.buffer64 ->
arg5: Vale.X64.Memory.buffer64 ->
arg6: Vale.X64.Memory.buffer64 ->
arg7: Vale.X64.Memory.buffer64 ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.X64.Memory.buffer64",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Prims.eq2",
"Vale.Def.Words_s.nat64",
"Vale.X64.Decls.va_get_reg64",
"Vale.X64.Machine_s.rRsp",
"Vale.X64.Stack_i.init_rsp",
"Vale.X64.Decls.va_get_stack",
"Vale.X64.Memory.is_initial_heap",
"Vale.X64.Decls.va_get_mem_layout",
"Vale.X64.Decls.va_get_mem",
"Prims.l_imp",
"Vale.X64.Stack_i.valid_src_stack64",
"Prims.op_Addition",
"Prims.l_not",
"Vale.X64.Decls.validSrcAddrs64",
"Vale.X64.Decls.va_if",
"Vale.Def.Types_s.nat64",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Machine_s.rRdi",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.X64.Machine_s.rRdx",
"Vale.X64.Machine_s.rRsi",
"Vale.X64.Machine_s.rR8",
"Vale.X64.Machine_s.rR9",
"Vale.X64.Memory.nat64",
"Vale.X64.Stack_i.load_stack64",
"Prims.l_Forall",
"Vale.X64.InsBasic.vale_heap",
"Vale.X64.Decls.quad32",
"Vale.X64.Flags.t",
"Vale.Arch.HeapImpl.vale_heap_layout",
"Vale.X64.Machine_s.rRbx",
"Vale.X64.Machine_s.rRbp",
"Vale.X64.Machine_s.rR12",
"Vale.X64.Machine_s.rR13",
"Vale.X64.Machine_s.rR14",
"Vale.X64.Machine_s.rR15",
"Vale.X64.Decls.va_get_xmm",
"Vale.X64.Decls.modifies_mem",
"Vale.X64.Memory.loc_none",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_mem_layout",
"Vale.X64.Decls.va_upd_mem_heaplet",
"Vale.X64.Decls.va_upd_flags",
"Vale.X64.Decls.va_upd_xmm",
"Vale.X64.Decls.va_upd_reg64",
"Vale.X64.Machine_s.rR11",
"Vale.X64.Machine_s.rR10",
"Vale.X64.Machine_s.rRax",
"Vale.X64.Decls.va_upd_mem"
] | [] | false | false | false | true | true | let va_wp_Test
(win: bool)
(arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\
Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\
(win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0)) /\
(win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) /\
(~win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\
(~win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0))
arg0
0
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0))
arg1
0
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(va_if win (fun _ -> va_get_reg64 rR8 va_s0) (fun _ -> va_get_reg64 rRdx va_s0))
arg2
0
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(va_if win (fun _ -> va_get_reg64 rR9 va_s0) (fun _ -> va_get_reg64 rRcx va_s0))
arg3
0
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0)
(va_get_stack va_s0))
(fun _ -> va_get_reg64 rR8 va_s0))
arg4
0
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8)
(va_get_stack va_s0))
(fun _ -> va_get_reg64 rR9 va_s0))
arg5
0
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16)
(va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)))
arg6
0
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0)
(va_if win
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 24)
(va_get_stack va_s0))
(fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)))
arg7
0
(va_get_mem_layout va_s0)
Secret /\
(forall (va_x_mem: vale_heap) (va_x_rax: nat64) (va_x_rbx: nat64) (va_x_rcx: nat64)
(va_x_rdx: nat64) (va_x_rsi: nat64) (va_x_rdi: nat64) (va_x_rbp: nat64) (va_x_rsp: nat64)
(va_x_r8: nat64) (va_x_r9: nat64) (va_x_r10: nat64) (va_x_r11: nat64) (va_x_r12: nat64)
(va_x_r13: nat64) (va_x_r14: nat64) (va_x_r15: nat64) (va_x_xmm0: quad32) (va_x_xmm1: quad32)
(va_x_xmm2: quad32) (va_x_xmm3: quad32) (va_x_xmm4: quad32) (va_x_xmm5: quad32)
(va_x_xmm6: quad32) (va_x_xmm7: quad32) (va_x_xmm8: quad32) (va_x_xmm9: quad32)
(va_x_xmm10: quad32) (va_x_xmm11: quad32) (va_x_xmm12: quad32) (va_x_xmm13: quad32)
(va_x_xmm14: quad32) (va_x_xmm15: quad32) (va_x_efl: Vale.X64.Flags.t) (va_x_heap0: vale_heap)
(va_x_memLayout: vale_heap_layout).
let va_sM =
va_upd_mem_layout va_x_memLayout
(va_upd_mem_heaplet 0
va_x_heap0
(va_upd_flags va_x_efl
(va_upd_xmm 15
va_x_xmm15
(va_upd_xmm 14
va_x_xmm14
(va_upd_xmm 13
va_x_xmm13
(va_upd_xmm 12
va_x_xmm12
(va_upd_xmm 11
va_x_xmm11
(va_upd_xmm 10
va_x_xmm10
(va_upd_xmm 9
va_x_xmm9
(va_upd_xmm 8
va_x_xmm8
(va_upd_xmm 7
va_x_xmm7
(va_upd_xmm 6
va_x_xmm6
(va_upd_xmm 5
va_x_xmm5
(va_upd_xmm 4
va_x_xmm4
(va_upd_xmm 3
va_x_xmm3
(va_upd_xmm 2
va_x_xmm2
(va_upd_xmm 1
va_x_xmm1
(va_upd_xmm 0
va_x_xmm0
(va_upd_reg64 rR15
va_x_r15
(va_upd_reg64 rR14
va_x_r14
(va_upd_reg64
rR13
va_x_r13
(va_upd_reg64
rR12
va_x_r12
(va_upd_reg64
rR11
va_x_r11
(
va_upd_reg64
rR10
va_x_r10
(
va_upd_reg64
rR9
va_x_r9
(
va_upd_reg64
rR8
va_x_r8
(
va_upd_reg64
rRsp
va_x_rsp
(
va_upd_reg64
rRbp
va_x_rbp
(
va_upd_reg64
rRdi
va_x_rdi
(
va_upd_reg64
rRsi
va_x_rsi
(
va_upd_reg64
rRdx
va_x_rdx
(
va_upd_reg64
rRcx
va_x_rcx
(
va_upd_reg64
rRbx
va_x_rbx
(
va_upd_reg64
rRax
va_x_rax
(
va_upd_mem
va_x_mem
va_s0
)
)
)
)
)
)
)
)
)
)
)
)
))
))))))))))
)))))))))))
in
va_get_ok va_sM /\ va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\
va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0 /\
va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0 /\
va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\
va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0 /\
va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0 /\
va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0 /\
(win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0) /\
(win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\
(win ==> va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\
(win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\
(win ==> va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\
(win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0) /\
(win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\
(win ==> va_get_xmm 11 va_sM == va_get_xmm 11 va_s0) /\
(win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\
(win ==> va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\
(win ==> va_get_xmm 14 va_sM == va_get_xmm 14 va_s0) /\
(win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\
Vale.X64.Decls.modifies_mem loc_none (va_get_mem va_s0) (va_get_mem va_sM) ==>
va_k va_sM (()))) | false |
LowParse.Low.Base.fst | LowParse.Low.Base.witness_valid_gen | val witness_valid_gen
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
: HST.Stack (irepr p s compl)
(requires
(fun h ->
valid p h s pos /\
B.stable_on (wvalid p
s
compl
pos
(Ghost.hide (get_valid_pos p h s pos))
(Ghost.hide (contents p h s pos)))
(buffer_srel_of_srel rel) /\
compl pos (contents p h s pos) (get_valid_pos p h s pos) (B.as_seq h s.base)))
(ensures
(fun h res h' ->
h' == h /\ irepr_pos res == pos /\
valid_content_pos p h s pos (irepr_v res) (irepr_pos' res))) | val witness_valid_gen
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
: HST.Stack (irepr p s compl)
(requires
(fun h ->
valid p h s pos /\
B.stable_on (wvalid p
s
compl
pos
(Ghost.hide (get_valid_pos p h s pos))
(Ghost.hide (contents p h s pos)))
(buffer_srel_of_srel rel) /\
compl pos (contents p h s pos) (get_valid_pos p h s pos) (B.as_seq h s.base)))
(ensures
(fun h res h' ->
h' == h /\ irepr_pos res == pos /\
valid_content_pos p h s pos (irepr_v res) (irepr_pos' res))) | let witness_valid_gen
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
: HST.Stack (irepr p s compl)
(requires (fun h ->
valid p h s pos /\
B.stable_on (wvalid p s compl pos (Ghost.hide (get_valid_pos p h s pos)) (Ghost.hide (contents p h s pos))) (buffer_srel_of_srel rel) /\
compl pos (contents p h s pos) (get_valid_pos p h s pos) (B.as_seq h s.base)
))
(ensures (fun h res h' ->
h' == h /\
irepr_pos res == pos /\
valid_content_pos p h s pos (irepr_v res) (irepr_pos' res)
))
= let h = HST.get () in
[@inline_let]
let gpos' = Ghost.hide (get_valid_pos p h s pos) in
[@inline_let]
let gv = Ghost.hide (contents p h s pos) in
[@inline_let]
let _ = valid_facts p h s pos in
B.witness_p s.base (wvalid p s compl pos gpos' gv);
IRepr pos gpos' gv () | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 23,
"end_line": 2114,
"start_col": 0,
"start_line": 2087
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
()
inline_for_extraction
let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len
#push-options "--z3rlimit 32 --fuel 2 --ifuel 1"
inline_for_extraction
let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
(x: Ghost.erased t) ->
HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
(#rrel_out #rel_out: _)
(sl_out : slice rrel_out rel_out)
(pos_out : U32.t)
: HST.Stack U32.t
(requires (fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\
valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out
))
(ensures (fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
//B.fresh_frame_modifies h0 h1;
let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\ (
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow
)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))
inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then begin
assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2
end else
L.append_l_nil (L.filter f (G.reveal l1))
)
;
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out'
#pop-options
#push-options "--z3rlimit 64 --fuel 2 --ifuel 1"
inline_for_extraction
let list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(i: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos' /\
U32.v i < L.length (contents_list p h sl pos pos')
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid_list p h sl pos res /\
valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos1 = BF.alloca pos 1ul in
let bk = BF.alloca 0ul 1ul in
let h2 = HST.get () in
valid_list_nil p h0 sl pos;
let _ : bool = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
let k = Seq.index (B.as_seq h bk) 0 in
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bpos1 /\
B.live h bk /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v k /\
U32.v k <= U32.v i
)
(fun h _ _ _ h' ->
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1);
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk);
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
let pos1 = Seq.index (B.as_seq h bpos1) 0 in
B.live h bpos1 /\
valid p h0 sl pos1 /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v i /\
contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)
)
(fun _ _ ->
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 ->
let k = B.index bk 0ul in
if k = i
then begin
B.upd bpos1 0ul pos1;
valid_list_cons_recip p h0 sl pos1 pos';
list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i);
valid_list_append p h0 sl pos pos1 pos' ;
assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i));
false
end else begin
B.upd bk 0ul (k `U32.add` 1ul);
let h = HST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h;
valid_list_snoc p h0 sl pos pos1;
assert (valid p h0 sl pos1);
assert (pos2 == get_valid_pos p h0 sl pos1);
assert (valid_list p h0 sl pos pos2);
list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1];
true
end
)
in
let res = B.index bpos1 0ul in
HST.pop_frame ();
res
inline_for_extraction
let list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\
valid p h sl res /\ (
let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\
f x == true /\
L.find f l == Some x
)
)))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bres = BF.alloca 0ul 1ul in
let h2 = HST.get () in
let not_found = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\
valid_list p h0 sl pos1 pos' /\
l2 == contents_list p h0 sl pos1 pos' /\
L.find f (contents_list p h0 sl pos pos') == L.find f l2
)
(fun h _ _ _ h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\ (
let res = Seq.index (B.as_seq h bres) 0 in
U32.v pos <= U32.v res /\
valid p h0 sl res /\ (
let x = contents p h0 sl res in
U32.v res + content_length p h0 sl res <= U32.v pos' /\
f x == true /\
L.find f (contents_list p h0 sl pos pos') == Some x
)))
(fun h h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun pos1 pos2 ->
if f' sl pos1
then begin
B.upd bres 0ul pos1;
false
end
else true
)
in
let res =
if not_found
then pos'
else B.index bres 0ul
in
HST.pop_frame ();
res
#pop-options
let rec list_existsb_find
(#a: Type)
(f: (a -> Tot bool))
(l: list a)
: Lemma
(L.existsb f l == Some? (L.find f l))
= match l with
| [] -> ()
| x :: q ->
if f x
then ()
else list_existsb_find f q
inline_for_extraction
noextract
let list_existsb
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack bool
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == L.existsb f (contents_list p h sl pos pos')
))
= let h = HST.get () in
list_existsb_find f (contents_list p h sl pos pos');
let posn = list_find j f f' sl pos pos' in
posn <> pos'
#push-options "--fuel 2 --ifuel 1 --z3rlimit 256 --query_stats"
inline_for_extraction
noextract
let list_flatten_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot (list t2))) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2_ res /\
contents_list p2 h' sl2 pos2_ res == y
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= let hz = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos2_ = BF.alloca pos2 1ul in
let h2 = HST.get () in
valid_list_nil p2 hz sl2 pos2;
let fits = list_fold_left_gen
p1
j1
sl1
pos1 pos1'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2))
(fun h ll lr _ ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
B.live h bpos2_ /\ (
let pos2_ = Seq.index (B.as_seq h bpos2_) 0 in
contents_list p1 h0 sl1 pos1 pos1' == ll `List.Tot.append` lr /\
valid_list p2 h sl2 pos2 pos2_ /\
contents_list p2 h sl2 pos2 pos2_ == List.Tot.flatten (List.Tot.map f ll) /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(fun h _ _ _ h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
U32.v pos2 + serialized_list_length s2 (List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1'))) > U32.v sl2.len
)
(fun h h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1l pos1r ->
let pos2_ = B.index bpos2_ 0ul in
let h = HST.get () in
writable_weaken sl2.base (U32.v pos2) (U32.v sl2.len) h (U32.v pos2_) (U32.v sl2.len);
valid_pos_frame_strong p1 h0 sl1 pos1l pos1r (loc_slice_from sl2 pos2) hz;
let res = f' pos1l pos2_ in
let fits = not (res = max_uint32) in
if fits then begin
B.upd bpos2_ 0ul res;
let h' = HST.get () in
writable_modifies sl2.base (U32.v pos2) (U32.v sl2.len) h (B.loc_region_only true (HS.get_tip h1)) h' ;
List.Tot.append_assoc (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l] (contents_list p1 h0 sl1 pos1r pos1');
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l];
valid_list_snoc p1 h0 sl1 pos1 pos1l;
valid_list_append p2 h' sl2 pos2 pos2_ res;
valid_list_nil p2 h' sl2 res;
valid_list_append p2 h' sl2 pos2_ res res
end else begin
let h' = HST.get () in
valid_list_cons p1 h0 sl1 pos1l pos1' ;
valid_list_append p1 h0 sl1 pos1 pos1l pos1' ;
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) (contents_list p1 h0 sl1 pos1l pos1');
serialized_list_length_append s2 (L.flatten (L.map f (contents_list p1 h0 sl1 pos1 pos1l))) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1l pos1')));
serialized_list_length_append s2 (f (contents p1 h0 sl1 pos1l)) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1r pos1')));
valid_list_serialized_list_length s2 h' sl2 pos2 pos2_
end;
fits
)
in
let res =
if fits
then B.index bpos2_ 0ul
else max_uint32
in
HST.pop_frame ();
res
#pop-options
#push-options "--z3rlimit 16 --query_stats"
inline_for_extraction
noextract
let list_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot t2)) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_length s2 y > U32.v sl2.len
else
valid_content_pos p2 h' sl2 pos2_ y res
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1') in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= list_map_list_flatten_map f (contents_list p1 h0 sl1 pos1 pos1');
list_flatten_map
j1
s2
(fun x -> [f x])
h0
sl1 pos1 pos1'
sl2 pos2
(fun pos1 pos2 ->
let res = f' pos1 pos2 in
let h = HST.get () in
if res = max_uint32
then begin
serialized_list_length_nil s2;
serialized_list_length_cons s2 (f (contents p1 h0 sl1 pos1)) []
end
else begin
valid_list_nil p2 h sl2 res;
valid_list_cons p2 h sl2 pos2 res
end;
res
)
(* Example: trivial printers *)
inline_for_extraction
let print_list
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(print: ((#rrel: _) -> (#rel: _) -> (sl: slice rrel rel) -> (pos: U32.t) -> HST.Stack unit (requires (fun h -> valid p h sl pos)) (ensures (fun h _ h' -> B.modifies B.loc_none h h'))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack unit
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h _ h' ->
B.modifies B.loc_none h h'
))
= let h0 = HST.get () in
list_fold_left
p
j
sl
pos pos'
h0
(Ghost.hide B.loc_none)
(fun _ _ _ _ -> True)
(fun _ _ _ _ _ -> ())
(fun pos1 _ _ _ _ ->
print sl pos1
)
(* Monotonicity *)
inline_for_extraction
let compl_t (t: Type) = U32.t -> t -> U32.t -> Tot (B.spred byte)
let wvalid
(#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos' : Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
: GTot prop
=
U32.v pos <= U32.v (Ghost.reveal gpos') /\
U32.v (Ghost.reveal gpos') <= U32.v s.len /\
U32.v s.len <= Seq.length x /\
parse p (Seq.slice x (U32.v pos) (U32.v s.len)) == Some (Ghost.reveal gv, U32.v (Ghost.reveal gpos') - U32.v pos) /\
compl pos (Ghost.reveal gv) (Ghost.reveal gpos') x
let wvalid_valid_content_pos
(#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
(gpos' : Ghost.erased U32.t)
(gv: Ghost.erased t)
(x: Seq.seq byte)
(h: HS.mem)
: Lemma
(requires (
wvalid p s compl pos gpos' gv x /\
live_slice h s /\
x == B.as_seq h s.base
))
(ensures (
valid_content_pos p h s pos gv gpos'
))
=
valid_facts p h s pos
inline_for_extraction
noeq
type irepr (#t: Type) (#k: parser_kind) (p: parser k t) (#rrel #rel: _) (s: slice rrel rel) (compl: compl_t t) =
| IRepr:
(pos: U32.t) ->
(gpos' : Ghost.erased U32.t) ->
(gv: Ghost.erased t) ->
(irepr_correct: squash (
U32.v pos <= U32.v (Ghost.reveal gpos') /\
U32.v (Ghost.reveal gpos') <= U32.v s.len /\
B.witnessed s.base (wvalid p s compl pos gpos' gv)
)) ->
irepr p s compl
inline_for_extraction
let irepr_pos
(#t: Type) (#k: parser_kind) (#p: parser k t) (#rrel #rel: _) (#s: slice rrel rel) (#compl: compl_t t) (x: irepr p s compl) : Tot U32.t =
IRepr?.pos x
let irepr_pos'
(#t: Type) (#k: parser_kind) (#p: parser k t) (#rrel #rel: _) (#s: slice rrel rel) (#compl: compl_t t) (x: irepr p s compl) : Ghost U32.t
(requires True)
(ensures (fun y -> True))
= Ghost.reveal (IRepr?.gpos' x)
#push-options "--ifuel 1 --fuel 2"
let irepr_pos'_post
(#t: Type) (#k: parser_kind) (#p: parser k t) (#rrel #rel: _) (#s: slice rrel rel) (#compl: compl_t t) (x: irepr p s compl) : Lemma
(requires True)
(ensures (
let y = irepr_pos' x in
U32.v (irepr_pos x) <= U32.v y /\ U32.v y <= U32.v s.len
))
[SMTPat (irepr_pos' x)]
= ()
let irepr_v
(#t: Type) (#k: parser_kind) (#p: parser k t) (#rrel #rel: _) (#s: slice rrel rel) (#compl: compl_t t) (x: irepr p s compl) : GTot t
= Ghost.reveal (IRepr?.gv x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: LowParse.Slice.slice rrel rel -> compl: LowParse.Low.Base.compl_t t -> pos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack (LowParse.Low.Base.irepr p s compl) | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Low.Base.compl_t",
"FStar.UInt32.t",
"LowParse.Low.Base.IRepr",
"LowParse.Low.Base.irepr",
"Prims.unit",
"LowStar.Monotonic.Buffer.witness_p",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"LowParse.Low.Base.wvalid",
"LowParse.Low.Base.Spec.valid_facts",
"FStar.Ghost.erased",
"FStar.Ghost.hide",
"LowParse.Low.Base.Spec.contents",
"LowParse.Low.Base.Spec.get_valid_pos",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.l_and",
"LowParse.Low.Base.Spec.valid",
"LowStar.Monotonic.Buffer.stable_on",
"LowStar.Monotonic.Buffer.as_seq",
"Prims.eq2",
"LowParse.Low.Base.irepr_pos",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Low.Base.irepr_v",
"LowParse.Low.Base.irepr_pos'"
] | [] | false | true | false | false | false | let witness_valid_gen
(#t: Type)
(#k: parser_kind)
(#p: parser k t)
(#rrel #rel: _)
(s: slice rrel rel)
(compl: compl_t t)
(pos: U32.t)
: HST.Stack (irepr p s compl)
(requires
(fun h ->
valid p h s pos /\
B.stable_on (wvalid p
s
compl
pos
(Ghost.hide (get_valid_pos p h s pos))
(Ghost.hide (contents p h s pos)))
(buffer_srel_of_srel rel) /\
compl pos (contents p h s pos) (get_valid_pos p h s pos) (B.as_seq h s.base)))
(ensures
(fun h res h' ->
h' == h /\ irepr_pos res == pos /\
valid_content_pos p h s pos (irepr_v res) (irepr_pos' res))) =
| let h = HST.get () in
[@@ inline_let ]let gpos' = Ghost.hide (get_valid_pos p h s pos) in
[@@ inline_let ]let gv = Ghost.hide (contents p h s pos) in
[@@ inline_let ]let _ = valid_facts p h s pos in
B.witness_p s.base (wvalid p s compl pos gpos' gv);
IRepr pos gpos' gv () | false |
LowParse.Low.Base.fst | LowParse.Low.Base.list_length | val list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos': U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ U32.v res == L.length (contents_list p h sl pos pos'))) | val list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos': U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ U32.v res == L.length (contents_list p h sl pos pos'))) | let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 1408,
"start_col": 0,
"start_line": 1360
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
() | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: LowParse.Spec.Base.parser k t ->
j: LowParse.Low.Base.jumper p ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"LowStar.Monotonic.Buffer.index",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.__uint_to_t",
"LowParse.Low.Base.list_fold_left",
"FStar.Ghost.hide",
"LowStar.Monotonic.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_buffer",
"FStar.Monotonic.HyperStack.mem",
"Prims.list",
"Prims.l_and",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.live",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.op_GreaterThanOrEqual",
"FStar.List.Tot.Base.length",
"FStar.UInt.uint_t",
"FStar.Seq.Base.index",
"LowStar.Monotonic.Buffer.as_seq",
"LowStar.Monotonic.Buffer.loc_unused_in_not_unused_in_disjoint",
"LowStar.Monotonic.Buffer.modifies_only_not_unused_in",
"FStar.Ghost.erased",
"FStar.Classical.forall_intro_2",
"FStar.List.Tot.Base.append",
"Prims.op_Addition",
"LowParse.Low.Base.Spec.list_length_append",
"LowStar.Monotonic.Buffer.upd",
"FStar.UInt32.add",
"FStar.HyperStack.ST.get",
"LowStar.Buffer.pointer",
"LowStar.Buffer.alloca",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.Monotonic.Buffer.fresh_frame_modifies",
"FStar.HyperStack.ST.push_frame",
"LowParse.Low.Base.Spec.valid_list",
"LowStar.Monotonic.Buffer.loc_none",
"LowParse.Low.Base.Spec.contents_list"
] | [] | false | true | false | false | false | let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos': U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ U32.v res == L.length (contents_list p h sl pos pos'))) =
| let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen:BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left p j sl pos pos' h2 (Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\ B.live h blen /\
(let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ len == L.length l1))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul ((B.index blen 0ul) `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t));
let len = B.index blen 0ul in
HST.pop_frame ();
len | false |
LowParse.Low.Base.fst | LowParse.Low.Base.list_map | val list_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 {k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0})
(f: (t1 -> Tot t2))
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1': U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2:
U32.t
{ valid_list p1 h0 sl1 pos1 pos1' /\ U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\ U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32 })
(f':
(pos1_: U32.t -> pos2_: U32.t
-> HST.Stack U32.t
(requires
(fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\ valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\ U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h))
(ensures
(fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\
(let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_length s2 y > U32.v sl2.len
else valid_content_pos p2 h' sl2 pos2_ y res)))))
: HST.Stack U32.t
(requires
(fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\ live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h))
(ensures
(fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\
(let y = List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1') in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else valid_list p2 h' sl2 pos2 res /\ contents_list p2 h' sl2 pos2 res == y))) | val list_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 {k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0})
(f: (t1 -> Tot t2))
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1': U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2:
U32.t
{ valid_list p1 h0 sl1 pos1 pos1' /\ U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\ U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32 })
(f':
(pos1_: U32.t -> pos2_: U32.t
-> HST.Stack U32.t
(requires
(fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\ valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\ U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h))
(ensures
(fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\
(let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_length s2 y > U32.v sl2.len
else valid_content_pos p2 h' sl2 pos2_ y res)))))
: HST.Stack U32.t
(requires
(fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\ live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h))
(ensures
(fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\
(let y = List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1') in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else valid_list p2 h' sl2 pos2 res /\ contents_list p2 h' sl2 pos2 res == y))) | let list_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot t2)) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_length s2 y > U32.v sl2.len
else
valid_content_pos p2 h' sl2 pos2_ y res
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1') in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= list_map_list_flatten_map f (contents_list p1 h0 sl1 pos1 pos1');
list_flatten_map
j1
s2
(fun x -> [f x])
h0
sl1 pos1 pos1'
sl2 pos2
(fun pos1 pos2 ->
let res = f' pos1 pos2 in
let h = HST.get () in
if res = max_uint32
then begin
serialized_list_length_nil s2;
serialized_list_length_cons s2 (f (contents p1 h0 sl1 pos1)) []
end
else begin
valid_list_nil p2 h sl2 res;
valid_list_cons p2 h sl2 pos2 res
end;
res
) | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 1969,
"start_col": 0,
"start_line": 1886
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
()
inline_for_extraction
let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len
#push-options "--z3rlimit 32 --fuel 2 --ifuel 1"
inline_for_extraction
let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
(x: Ghost.erased t) ->
HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
(#rrel_out #rel_out: _)
(sl_out : slice rrel_out rel_out)
(pos_out : U32.t)
: HST.Stack U32.t
(requires (fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\
valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out
))
(ensures (fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
//B.fresh_frame_modifies h0 h1;
let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\ (
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow
)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))
inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then begin
assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2
end else
L.append_l_nil (L.filter f (G.reveal l1))
)
;
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out'
#pop-options
#push-options "--z3rlimit 64 --fuel 2 --ifuel 1"
inline_for_extraction
let list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(i: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos' /\
U32.v i < L.length (contents_list p h sl pos pos')
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid_list p h sl pos res /\
valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos1 = BF.alloca pos 1ul in
let bk = BF.alloca 0ul 1ul in
let h2 = HST.get () in
valid_list_nil p h0 sl pos;
let _ : bool = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
let k = Seq.index (B.as_seq h bk) 0 in
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bpos1 /\
B.live h bk /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v k /\
U32.v k <= U32.v i
)
(fun h _ _ _ h' ->
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1);
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk);
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
let pos1 = Seq.index (B.as_seq h bpos1) 0 in
B.live h bpos1 /\
valid p h0 sl pos1 /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v i /\
contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)
)
(fun _ _ ->
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 ->
let k = B.index bk 0ul in
if k = i
then begin
B.upd bpos1 0ul pos1;
valid_list_cons_recip p h0 sl pos1 pos';
list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i);
valid_list_append p h0 sl pos pos1 pos' ;
assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i));
false
end else begin
B.upd bk 0ul (k `U32.add` 1ul);
let h = HST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h;
valid_list_snoc p h0 sl pos pos1;
assert (valid p h0 sl pos1);
assert (pos2 == get_valid_pos p h0 sl pos1);
assert (valid_list p h0 sl pos pos2);
list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1];
true
end
)
in
let res = B.index bpos1 0ul in
HST.pop_frame ();
res
inline_for_extraction
let list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\
valid p h sl res /\ (
let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\
f x == true /\
L.find f l == Some x
)
)))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bres = BF.alloca 0ul 1ul in
let h2 = HST.get () in
let not_found = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\
valid_list p h0 sl pos1 pos' /\
l2 == contents_list p h0 sl pos1 pos' /\
L.find f (contents_list p h0 sl pos pos') == L.find f l2
)
(fun h _ _ _ h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\ (
let res = Seq.index (B.as_seq h bres) 0 in
U32.v pos <= U32.v res /\
valid p h0 sl res /\ (
let x = contents p h0 sl res in
U32.v res + content_length p h0 sl res <= U32.v pos' /\
f x == true /\
L.find f (contents_list p h0 sl pos pos') == Some x
)))
(fun h h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun pos1 pos2 ->
if f' sl pos1
then begin
B.upd bres 0ul pos1;
false
end
else true
)
in
let res =
if not_found
then pos'
else B.index bres 0ul
in
HST.pop_frame ();
res
#pop-options
let rec list_existsb_find
(#a: Type)
(f: (a -> Tot bool))
(l: list a)
: Lemma
(L.existsb f l == Some? (L.find f l))
= match l with
| [] -> ()
| x :: q ->
if f x
then ()
else list_existsb_find f q
inline_for_extraction
noextract
let list_existsb
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack bool
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == L.existsb f (contents_list p h sl pos pos')
))
= let h = HST.get () in
list_existsb_find f (contents_list p h sl pos pos');
let posn = list_find j f f' sl pos pos' in
posn <> pos'
#push-options "--fuel 2 --ifuel 1 --z3rlimit 256 --query_stats"
inline_for_extraction
noextract
let list_flatten_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 { k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0 } )
(f: (t1 -> Tot (list t2))) // should be GTot, but List.Tot.map requires Tot
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1' : U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2: U32.t {
valid_list p1 h0 sl1 pos1 pos1' /\
U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\
U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32
})
(f' : (
(pos1_: U32.t) ->
(pos2_: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\
U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\ (
let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2_ res /\
contents_list p2 h' sl2 pos2_ res == y
)))
))
: HST.Stack U32.t
(requires (fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\
live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(ensures (fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\ (
let y = List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1')) in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else
valid_list p2 h' sl2 pos2 res /\
contents_list p2 h' sl2 pos2 res == y
)))
= let hz = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos2_ = BF.alloca pos2 1ul in
let h2 = HST.get () in
valid_list_nil p2 hz sl2 pos2;
let fits = list_fold_left_gen
p1
j1
sl1
pos1 pos1'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2))
(fun h ll lr _ ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
B.live h bpos2_ /\ (
let pos2_ = Seq.index (B.as_seq h bpos2_) 0 in
contents_list p1 h0 sl1 pos1 pos1' == ll `List.Tot.append` lr /\
valid_list p2 h sl2 pos2 pos2_ /\
contents_list p2 h sl2 pos2 pos2_ == List.Tot.flatten (List.Tot.map f ll) /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h
))
(fun h _ _ _ h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h /\
U32.v pos2 + serialized_list_length s2 (List.Tot.flatten (List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1'))) > U32.v sl2.len
)
(fun h h' ->
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1) `B.loc_union` loc_slice_from sl2 pos2) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1l pos1r ->
let pos2_ = B.index bpos2_ 0ul in
let h = HST.get () in
writable_weaken sl2.base (U32.v pos2) (U32.v sl2.len) h (U32.v pos2_) (U32.v sl2.len);
valid_pos_frame_strong p1 h0 sl1 pos1l pos1r (loc_slice_from sl2 pos2) hz;
let res = f' pos1l pos2_ in
let fits = not (res = max_uint32) in
if fits then begin
B.upd bpos2_ 0ul res;
let h' = HST.get () in
writable_modifies sl2.base (U32.v pos2) (U32.v sl2.len) h (B.loc_region_only true (HS.get_tip h1)) h' ;
List.Tot.append_assoc (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l] (contents_list p1 h0 sl1 pos1r pos1');
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) [contents p1 h0 sl1 pos1l];
valid_list_snoc p1 h0 sl1 pos1 pos1l;
valid_list_append p2 h' sl2 pos2 pos2_ res;
valid_list_nil p2 h' sl2 res;
valid_list_append p2 h' sl2 pos2_ res res
end else begin
let h' = HST.get () in
valid_list_cons p1 h0 sl1 pos1l pos1' ;
valid_list_append p1 h0 sl1 pos1 pos1l pos1' ;
list_flatten_map_append f (contents_list p1 h0 sl1 pos1 pos1l) (contents_list p1 h0 sl1 pos1l pos1');
serialized_list_length_append s2 (L.flatten (L.map f (contents_list p1 h0 sl1 pos1 pos1l))) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1l pos1')));
serialized_list_length_append s2 (f (contents p1 h0 sl1 pos1l)) (L.flatten (L.map f (contents_list p1 h0 sl1 pos1r pos1')));
valid_list_serialized_list_length s2 h' sl2 pos2 pos2_
end;
fits
)
in
let res =
if fits
then B.index bpos2_ 0ul
else max_uint32
in
HST.pop_frame ();
res
#pop-options
#push-options "--z3rlimit 16 --query_stats"
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
j1: LowParse.Low.Base.jumper p1 ->
s2:
LowParse.Spec.Base.serializer p2
{ Mkparser_kind'?.parser_kind_subkind k2 ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
Mkparser_kind'?.parser_kind_low k2 > 0 } ->
f: (_: t1 -> t2) ->
h0: FStar.Monotonic.HyperStack.mem ->
sl1: LowParse.Slice.slice rrel1 rel1 ->
pos1: FStar.UInt32.t ->
pos1': FStar.UInt32.t ->
sl2: LowParse.Slice.slice rrel2 rel2 ->
pos2:
FStar.UInt32.t
{ LowParse.Low.Base.Spec.valid_list p1 h0 sl1 pos1 pos1' /\
FStar.UInt32.v pos1 <= FStar.UInt32.v pos1' /\
FStar.UInt32.v pos1' <= FStar.UInt32.v (Mkslice?.len sl1) /\
FStar.UInt32.v pos2 <= FStar.UInt32.v (Mkslice?.len sl2) /\
LowStar.Monotonic.Buffer.loc_disjoint (LowParse.Slice.loc_slice_from_to sl1 pos1 pos1')
(LowParse.Slice.loc_slice_from sl2 pos2) /\
FStar.UInt32.v (Mkslice?.len sl2) < FStar.UInt32.v LowParse.Low.ErrorCode.max_uint32 } ->
f': (pos1_: FStar.UInt32.t -> pos2_: FStar.UInt32.t -> FStar.HyperStack.ST.Stack FStar.UInt32.t)
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"LowParse.Spec.Base.serializer",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"Prims.b2t",
"Prims.op_GreaterThan",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.valid_list",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowParse.Slice.loc_slice_from_to",
"LowParse.Slice.loc_slice_from",
"Prims.op_LessThan",
"LowParse.Low.ErrorCode.max_uint32",
"LowStar.Monotonic.Buffer.modifies",
"LowParse.Low.Base.Spec.valid",
"Prims.op_Addition",
"LowParse.Low.Base.Spec.content_length",
"LowParse.Slice.live_slice",
"LowParse.Low.Base.writable",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"Prims.op_Equality",
"LowParse.Low.Base.Spec.serialized_length",
"Prims.bool",
"LowParse.Low.Base.Spec.valid_content_pos",
"Prims.logical",
"LowParse.Low.Base.Spec.contents",
"LowParse.Low.Base.list_flatten_map",
"Prims.Cons",
"Prims.Nil",
"Prims.list",
"Prims.unit",
"LowParse.Low.Base.Spec.serialized_list_length_cons",
"LowParse.Low.Base.Spec.serialized_list_length_nil",
"LowParse.Low.Base.Spec.valid_list_cons",
"LowParse.Low.Base.Spec.valid_list_nil",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.Spec.list_map_list_flatten_map",
"LowParse.Low.Base.Spec.contents_list",
"LowParse.Low.Base.Spec.serialized_list_length",
"FStar.List.Tot.Base.map"
] | [] | false | true | false | false | false | let list_map
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(s2: serializer p2 {k2.parser_kind_subkind == Some ParserStrong /\ k2.parser_kind_low > 0})
(f: (t1 -> Tot t2))
(h0: HS.mem)
(#rrel1 #rel1: _)
(sl1: slice rrel1 rel1)
(pos1 pos1': U32.t)
(#rrel2 #rel2: _)
(sl2: slice rrel2 rel2)
(pos2:
U32.t
{ valid_list p1 h0 sl1 pos1 pos1' /\ U32.v pos1 <= U32.v pos1' /\
U32.v pos1' <= U32.v sl1.len /\ U32.v pos2 <= U32.v sl2.len /\
B.loc_disjoint (loc_slice_from_to sl1 pos1 pos1') (loc_slice_from sl2 pos2) /\
U32.v sl2.len < U32.v max_uint32 })
(f':
(pos1_: U32.t -> pos2_: U32.t
-> HST.Stack U32.t
(requires
(fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\ valid p1 h0 sl1 pos1_ /\
U32.v pos1 <= U32.v pos1_ /\
U32.v pos1_ + content_length p1 h0 sl1 pos1_ <= U32.v pos1' /\
live_slice h sl2 /\ U32.v pos2 <= U32.v pos2_ /\
U32.v pos2_ <= U32.v sl2.len /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h))
(ensures
(fun h res h' ->
B.modifies (loc_slice_from sl2 pos2_) h h' /\
(let y = f (contents p1 h0 sl1 pos1_) in
if res = max_uint32
then U32.v pos2_ + serialized_length s2 y > U32.v sl2.len
else valid_content_pos p2 h' sl2 pos2_ y res)))))
: HST.Stack U32.t
(requires
(fun h ->
B.modifies (loc_slice_from sl2 pos2) h0 h /\ live_slice h sl2 /\
writable sl2.base (U32.v pos2) (U32.v sl2.len) h))
(ensures
(fun h res h' ->
B.modifies (loc_slice_from sl2 pos2) h h' /\
(let y = List.Tot.map f (contents_list p1 h0 sl1 pos1 pos1') in
if res = max_uint32
then U32.v pos2 + serialized_list_length s2 y > U32.v sl2.len
else valid_list p2 h' sl2 pos2 res /\ contents_list p2 h' sl2 pos2 res == y))) =
| list_map_list_flatten_map f (contents_list p1 h0 sl1 pos1 pos1');
list_flatten_map j1 s2 (fun x -> [f x]) h0 sl1 pos1 pos1' sl2 pos2
(fun pos1 pos2 ->
let res = f' pos1 pos2 in
let h = HST.get () in
if res = max_uint32
then
(serialized_list_length_nil s2;
serialized_list_length_cons s2 (f (contents p1 h0 sl1 pos1)) [])
else
(valid_list_nil p2 h sl2 res;
valid_list_cons p2 h sl2 pos2 res);
res) | false |
Vale.Stdcalls.X64.GCMencryptOpt.fst | Vale.Stdcalls.X64.GCMencryptOpt.gcm128_encrypt_opt | val gcm128_encrypt_opt : Vale.Interop.Base.normal (
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Vale.Stdcalls.X64.GCMencryptOpt.lowstar_gcm128_t s iv) | let gcm128_encrypt_opt //: normal ((s:Ghost.erased (Seq.seq nat32)) -> lowstar_gcm128_t s)
= as_normal_t #((s:Ghost.erased (Seq.seq nat32)) -> (iv:Ghost.erased supported_iv_LE) -> lowstar_gcm128_t s iv) (fun (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) -> lowstar_gcm128 s iv) | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCMencryptOpt.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 209,
"end_line": 400,
"start_col": 0,
"start_line": 399
} | module Vale.Stdcalls.X64.GCMencryptOpt
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
open FStar.Mul
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
module GC = Vale.AES.X64.GCMencryptOpt
open Vale.AES.AES_s
open Vale.AES.GCM_s
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b128 = buf_t TUInt8 TUInt128
[@__reduce__] noextract
let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq
[@__reduce__] noextract
let t128_mod_pub = TD_Buffer TUInt8 TUInt128 ({modified=true; strict_disjointness=false; taint=MS.Public})
[@__reduce__] noextract
let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let (dom: list td{List.length dom <= 20}) =
let y = [t128_no_mod; tuint64; tuint64; t128_no_mod; t128_mod_pub; t128_no_mod;
t128_no_mod; t128_no_mod; t128_mod; tuint64; t128_no_mod; t128_mod; tuint64; t128_mod; tuint64; t128_mod; t128_mod] in
assert_norm (List.length y = 17);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm128_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
[@__reduce__] noextract
let gcm128_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f
#set-options "--z3rlimit 50"
[@__reduce__] noextract
let gcm128_lemma'
(s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(code:V.va_code)
(_win:bool)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm128_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\
gcm128_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\
ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\
ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b)
)) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f
(* Prove that gcm128_lemma' has the required type *)
noextract
let gcm128_lemma (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = as_t #(VSig.vale_sig_stdcall (gcm128_pre s iv) (gcm128_post s iv)) (gcm128_lemma' s iv)
noextract
let code_gcm128 = GC.va_code_Gcm_blocks_stdcall IA.win AES_128
(* Here's the type expected for the gcm wrapper *)
[@__reduce__] noextract
let lowstar_gcm128_t (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.as_lowstar_sig_t_weak_stdcall
code_gcm128
dom
[]
_
_
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win))
(* And here's the gcm wrapper itself *)
noextract
let lowstar_gcm128 (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) : lowstar_gcm128_t s iv =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.wrap_weak_stdcall
code_gcm128
dom
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win))
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm256_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
[@__reduce__] noextract
let gcm256_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f
#set-options "--z3rlimit 50"
[@__reduce__] noextract
let gcm256_lemma'
(s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(code:V.va_code)
(_win:bool)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm256_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\
gcm256_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\
ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\
ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b)
)) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f
(* Prove that gcm256_lemma' has the required type *)
noextract
let gcm256_lemma (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = as_t #(VSig.vale_sig_stdcall (gcm256_pre s iv) (gcm256_post s iv)) (gcm256_lemma' s iv)
noextract
let code_gcm256 = GC.va_code_Gcm_blocks_stdcall IA.win AES_256
(* Here's the type expected for the gcm wrapper *)
[@__reduce__] noextract
let lowstar_gcm256_t (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.as_lowstar_sig_t_weak_stdcall
code_gcm256
dom
[]
_
_
(W.mk_prediction code_gcm256 dom [] ((gcm256_lemma s iv) code_gcm256 IA.win))
(* And here's the gcm wrapper itself *)
noextract
let lowstar_gcm256 (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) : lowstar_gcm256_t s iv =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.wrap_weak_stdcall
code_gcm256
dom
(W.mk_prediction code_gcm256 dom [] ((gcm256_lemma s iv) code_gcm256 IA.win)) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.MemoryAdapters.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Interop.X64.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Interop.Assumptions.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"Vale.AES.X64.GCMencryptOpt.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.GCMencryptOpt.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AES.X64.GCMencryptOpt",
"short_module": "GC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Vale.Interop.Base.normal (
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Vale.Stdcalls.X64.GCMencryptOpt.lowstar_gcm128_t s iv) | Prims.Tot | [
"total"
] | [] | [
"Vale.Stdcalls.X64.GCMencryptOpt.as_normal_t",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCM_s.supported_iv_LE",
"Vale.Stdcalls.X64.GCMencryptOpt.lowstar_gcm128_t",
"Vale.Stdcalls.X64.GCMencryptOpt.lowstar_gcm128"
] | [] | false | false | false | false | false | let gcm128_encrypt_opt =
| as_normal_t #(s: Ghost.erased (Seq.seq nat32) -> iv: Ghost.erased supported_iv_LE
-> lowstar_gcm128_t s iv)
(fun (s: Ghost.erased (Seq.seq nat32)) (iv: Ghost.erased supported_iv_LE) -> lowstar_gcm128 s iv) | false |
|
LowParse.Low.Base.fst | LowParse.Low.Base.list_find | val list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f':
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos))))
)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos': U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\
(let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\ valid p h sl res /\
(let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\ f x == true /\
L.find f l == Some x)))) | val list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f':
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos))))
)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos': U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\
(let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\ valid p h sl res /\
(let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\ f x == true /\
L.find f l == Some x)))) | let list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool)) // should be GTot, but List.find requires Tot
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack bool
(requires (fun h ->
valid p h sl pos
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (contents p h sl pos)
))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\
valid p h sl res /\ (
let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\
f x == true /\
L.find f l == Some x
)
)))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bres = BF.alloca 0ul 1ul in
let h2 = HST.get () in
let not_found = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\
valid_list p h0 sl pos1 pos' /\
l2 == contents_list p h0 sl pos1 pos' /\
L.find f (contents_list p h0 sl pos pos') == L.find f l2
)
(fun h _ _ _ h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bres /\ (
let res = Seq.index (B.as_seq h bres) 0 in
U32.v pos <= U32.v res /\
valid p h0 sl res /\ (
let x = contents p h0 sl res in
U32.v res + content_length p h0 sl res <= U32.v pos' /\
f x == true /\
L.find f (contents_list p h0 sl pos pos') == Some x
)))
(fun h h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun pos1 pos2 ->
if f' sl pos1
then begin
B.upd bres 0ul pos1;
false
end
else true
)
in
let res =
if not_found
then pos'
else B.index bres 0ul
in
HST.pop_frame ();
res | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 1692,
"start_col": 0,
"start_line": 1600
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
()
inline_for_extraction
let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len
#push-options "--z3rlimit 32 --fuel 2 --ifuel 1"
inline_for_extraction
let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
(x: Ghost.erased t) ->
HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
(#rrel_out #rel_out: _)
(sl_out : slice rrel_out rel_out)
(pos_out : U32.t)
: HST.Stack U32.t
(requires (fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\
valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out
))
(ensures (fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
//B.fresh_frame_modifies h0 h1;
let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\ (
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow
)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))
inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then begin
assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2
end else
L.append_l_nil (L.filter f (G.reveal l1))
)
;
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out'
#pop-options
#push-options "--z3rlimit 64 --fuel 2 --ifuel 1"
inline_for_extraction
let list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(i: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos' /\
U32.v i < L.length (contents_list p h sl pos pos')
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid_list p h sl pos res /\
valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos1 = BF.alloca pos 1ul in
let bk = BF.alloca 0ul 1ul in
let h2 = HST.get () in
valid_list_nil p h0 sl pos;
let _ : bool = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
let k = Seq.index (B.as_seq h bk) 0 in
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bpos1 /\
B.live h bk /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v k /\
U32.v k <= U32.v i
)
(fun h _ _ _ h' ->
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1);
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk);
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
let pos1 = Seq.index (B.as_seq h bpos1) 0 in
B.live h bpos1 /\
valid p h0 sl pos1 /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v i /\
contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)
)
(fun _ _ ->
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 ->
let k = B.index bk 0ul in
if k = i
then begin
B.upd bpos1 0ul pos1;
valid_list_cons_recip p h0 sl pos1 pos';
list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i);
valid_list_append p h0 sl pos pos1 pos' ;
assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i));
false
end else begin
B.upd bk 0ul (k `U32.add` 1ul);
let h = HST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h;
valid_list_snoc p h0 sl pos pos1;
assert (valid p h0 sl pos1);
assert (pos2 == get_valid_pos p h0 sl pos1);
assert (valid_list p h0 sl pos pos2);
list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1];
true
end
)
in
let res = B.index bpos1 0ul in
HST.pop_frame ();
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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": false,
"smtencoding_l_arith_repr": "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": 64,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
j: LowParse.Low.Base.jumper p ->
f: (_: t -> Prims.bool) ->
f':
(sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack Prims.bool) ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"Prims.bool",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Base.Spec.valid",
"Prims.l_and",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.eq2",
"LowParse.Low.Base.Spec.contents",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"LowStar.Monotonic.Buffer.index",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.__uint_to_t",
"LowParse.Low.Base.list_fold_left_gen",
"FStar.Ghost.hide",
"LowStar.Monotonic.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_region_only",
"FStar.Monotonic.HyperStack.get_tip",
"Prims.list",
"LowStar.Monotonic.Buffer.live",
"LowParse.Low.Base.Spec.valid_list",
"LowParse.Low.Base.Spec.contents_list",
"FStar.Pervasives.Native.option",
"Prims.b2t",
"FStar.List.Tot.Base.find",
"LowStar.Monotonic.Buffer.modifies_only_not_unused_in",
"LowStar.Monotonic.Buffer.loc_unused_in_not_unused_in_disjoint",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"Prims.op_Addition",
"LowParse.Low.Base.Spec.content_length",
"FStar.Pervasives.Native.Some",
"FStar.Seq.Base.index",
"LowStar.Monotonic.Buffer.as_seq",
"LowStar.Monotonic.Buffer.upd",
"FStar.HyperStack.ST.get",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"FStar.UInt32.uint_to_t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.Buffer.alloca",
"FStar.HyperStack.ST.push_frame",
"Prims.op_Equality",
"FStar.Pervasives.Native.None",
"Prims.logical"
] | [] | false | true | false | false | false | let list_find
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f':
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t
-> HST.Stack bool
(requires (fun h -> valid p h sl pos))
(ensures
(fun h res h' -> B.modifies B.loc_none h h' /\ res == f (contents p h sl pos))))
)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos': U32.t)
: HST.Stack U32.t
(requires (fun h -> valid_list p h sl pos pos'))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\
(let l = contents_list p h sl pos pos' in
if res = pos'
then L.find f l == None
else
U32.v pos <= U32.v res /\ valid p h sl res /\
(let x = contents p h sl res in
U32.v res + content_length p h sl res <= U32.v pos' /\ f x == true /\
L.find f l == Some x)))) =
| let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bres = BF.alloca 0ul 1ul in
let h2 = HST.get () in
let not_found =
list_fold_left_gen p j sl pos pos' h2 (Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bres /\
valid_list p h0 sl pos1 pos' /\ l2 == contents_list p h0 sl pos1 pos' /\
L.find f (contents_list p h0 sl pos pos') == L.find f l2)
(fun h _ _ _ h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h')
(fun h ->
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bres /\
(let res = Seq.index (B.as_seq h bres) 0 in
U32.v pos <= U32.v res /\ valid p h0 sl res /\
(let x = contents p h0 sl res in
U32.v res + content_length p h0 sl res <= U32.v pos' /\ f x == true /\
L.find f (contents_list p h0 sl pos pos') == Some x)))
(fun h h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h')
(fun pos1 pos2 ->
if f' sl pos1
then
(B.upd bres 0ul pos1;
false)
else true)
in
let res = if not_found then pos' else B.index bres 0ul in
HST.pop_frame ();
res | false |
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.no_extra_bytes_helper | val no_extra_bytes_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 0 <= num_bytes /\
num_bytes % 16 == 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures slice (le_seq_quad32_to_bytes s) 0 num_bytes == le_seq_quad32_to_bytes s /\
slice s 0 (num_bytes / 16) == s) | val no_extra_bytes_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 0 <= num_bytes /\
num_bytes % 16 == 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures slice (le_seq_quad32_to_bytes s) 0 num_bytes == le_seq_quad32_to_bytes s /\
slice s 0 (num_bytes / 16) == s) | let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s) | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 29,
"start_col": 0,
"start_line": 28
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = () | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 0,
"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": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> num_bytes: Prims.int
-> FStar.Pervasives.Lemma
(requires
0 <= num_bytes /\ num_bytes % 16 == 0 /\
FStar.Seq.Base.length s == Vale.AES.GCM_helpers.bytes_to_quad_size num_bytes)
(ensures
FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes s) 0 num_bytes ==
Vale.Def.Types_s.le_seq_quad32_to_bytes s /\ FStar.Seq.Base.slice s 0 (num_bytes / 16) == s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Prims.int",
"FStar.Seq.Properties.slice_length",
"Vale.Def.Types_s.nat8",
"Vale.Def.Types_s.le_seq_quad32_to_bytes",
"Prims.unit"
] | [] | true | false | true | false | false | let no_extra_bytes_helper s num_bytes =
| slice_length (le_seq_quad32_to_bytes s) | false |
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.pad_to_128_bits_multiples | val pad_to_128_bits_multiples (b: seq nat8)
: Lemma
(let full_blocks = ((length b) / 16) * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) | val pad_to_128_bits_multiples (b: seq nat8)
: Lemma
(let full_blocks = ((length b) / 16) * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) | let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
) | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 88,
"start_col": 0,
"start_line": 61
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 0,
"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": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Seq.Base.seq Vale.Def.Types_s.nat8
-> FStar.Pervasives.Lemma
(ensures
(let full_blocks = (FStar.Seq.Base.length b / 16) * 16 in
let _ = FStar.Seq.Properties.split b full_blocks in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ full_bytes partial_bytes = _ in
Vale.AES.GCTR_s.pad_to_128_bits b ==
full_bytes @| Vale.AES.GCTR_s.pad_to_128_bits partial_bytes)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat8",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.unit",
"FStar.Seq.Base.append_empty_l",
"Vale.AES.GCTR_s.pad_to_128_bits",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.empty",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.op_At_Bar",
"FStar.Seq.Properties.lemma_split",
"FStar.Seq.Base.equal",
"Vale.Def.Words_s.nat8",
"FStar.Seq.Base.create",
"Prims.op_Subtraction",
"Prims.op_Modulus",
"Prims.op_Addition",
"FStar.Pervasives.Native.tuple2",
"FStar.Seq.Properties.split",
"FStar.Mul.op_Star",
"Prims.op_Division",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let pad_to_128_bits_multiples (b: seq nat8)
: Lemma
(let full_blocks = ((length b) / 16) * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes) =
| let full_blocks = ((length b) / 16) * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16
then
(assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l (pad_to_128_bits partial_bytes);
())
else
(assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0
then
(lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
())
else
(let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
());
()) | false |
Vale.Test.X64.Args.fsti | Vale.Test.X64.Args.va_quick_Test | val va_quick_Test (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64)
: (va_quickCode unit (va_code_Test win)) | val va_quick_Test (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64)
: (va_quickCode unit (va_code_Test win)) | let va_quick_Test (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64)
(arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) : (va_quickCode unit
(va_code_Test win)) =
(va_QProc (va_code_Test win) ([va_Mod_mem_layout; va_Mod_mem_heaplet 0; va_Mod_flags; va_Mod_xmm
15; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9;
va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm
2; va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR15; va_Mod_reg64 rR14; va_Mod_reg64 rR13;
va_Mod_reg64 rR12; va_Mod_reg64 rR11; va_Mod_reg64 rR10; va_Mod_reg64 rR9; va_Mod_reg64 rR8;
va_Mod_reg64 rRsp; va_Mod_reg64 rRbp; va_Mod_reg64 rRdi; va_Mod_reg64 rRsi; va_Mod_reg64 rRdx;
va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_mem]) (va_wp_Test win arg0 arg1
arg2 arg3 arg4 arg5 arg6 arg7) (va_wpProof_Test win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7)) | {
"file_name": "obj/Vale.Test.X64.Args.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 97,
"end_line": 231,
"start_col": 0,
"start_line": 221
} | module Vale.Test.X64.Args
open Vale.Arch.HeapImpl
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.Stack_i
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
#set-options "--z3rlimit 20"
//-- Test
val va_code_Test : win:bool -> Tot va_code
val va_codegen_success_Test : win:bool -> Tot va_pbool
let va_req_Test (va_b0:va_code) (va_s0:va_state) (win:bool) (arg0:buffer64) (arg1:buffer64)
(arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) :
prop =
(va_require_total va_b0 (va_code_Test win) va_s0 /\ va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 ==
Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap
(va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\ (win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0))
/\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16)
(va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 +
32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64
(va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRcx va_s0 else
va_get_reg64 rRdi va_s0) arg0 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else
va_get_reg64 rRsi va_s0) arg1 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR8 va_s0 else
va_get_reg64 rRdx va_s0) arg2 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR9 va_s0 else
va_get_reg64 rRcx va_s0) arg3 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) arg4 0
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win
then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)
else va_get_reg64 rR9 va_s0) arg5 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) arg6 0 (va_get_mem_layout va_s0) Secret
/\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) arg7 0 (va_get_mem_layout va_s0) Secret)
let va_ens_Test (va_b0:va_code) (va_s0:va_state) (win:bool) (arg0:buffer64) (arg1:buffer64)
(arg2:buffer64) (arg3:buffer64) (arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64)
(va_sM:va_state) (va_fM:va_fuel) : prop =
(va_req_Test va_b0 va_s0 win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 /\ va_ensure_total va_b0
va_s0 va_sM va_fM /\ va_get_ok va_sM /\ va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\
va_get_reg64 rRbx va_sM == va_get_reg64 rRbx va_s0 /\ va_get_reg64 rRbp va_sM == va_get_reg64
rRbp va_s0 /\ va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\ va_get_reg64 rR13 va_sM ==
va_get_reg64 rR13 va_s0 /\ va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0 /\ va_get_reg64
rR15 va_sM == va_get_reg64 rR15 va_s0 /\ (win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi
va_s0) /\ (win ==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\ (win ==> va_get_xmm 6
va_sM == va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==>
va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0)
/\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM ==
va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==>
va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14
va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ Vale.X64.Decls.modifies_mem
loc_none (va_get_mem va_s0) (va_get_mem va_sM) /\ va_state_eq va_sM (va_update_mem_layout va_sM
(va_update_mem_heaplet 0 va_sM (va_update_flags va_sM (va_update_xmm 15 va_sM (va_update_xmm 14
va_sM (va_update_xmm 13 va_sM (va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10
va_sM (va_update_xmm 9 va_sM (va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6
va_sM (va_update_xmm 5 va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2
va_sM (va_update_xmm 1 va_sM (va_update_xmm 0 va_sM (va_update_reg64 rR15 va_sM
(va_update_reg64 rR14 va_sM (va_update_reg64 rR13 va_sM (va_update_reg64 rR12 va_sM
(va_update_reg64 rR11 va_sM (va_update_reg64 rR10 va_sM (va_update_reg64 rR9 va_sM
(va_update_reg64 rR8 va_sM (va_update_reg64 rRsp va_sM (va_update_reg64 rRbp va_sM
(va_update_reg64 rRdi va_sM (va_update_reg64 rRsi va_sM (va_update_reg64 rRdx va_sM
(va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM (va_update_reg64 rRax va_sM
(va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))))))))))))))))))))))))))))
val va_lemma_Test : va_b0:va_code -> va_s0:va_state -> win:bool -> arg0:buffer64 -> arg1:buffer64
-> arg2:buffer64 -> arg3:buffer64 -> arg4:buffer64 -> arg5:buffer64 -> arg6:buffer64 ->
arg7:buffer64
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_Test win) va_s0 /\ va_get_ok va_s0 /\ va_get_reg64
rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\ Vale.X64.Memory.is_initial_heap
(va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) /\ (win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0))
/\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16)
(va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 +
32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64
(va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRcx va_s0 else
va_get_reg64 rRdi va_s0) arg0 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rRdx va_s0 else
va_get_reg64 rRsi va_s0) arg1 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR8 va_s0 else
va_get_reg64 rRdx va_s0) arg2 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then va_get_reg64 rR9 va_s0 else
va_get_reg64 rRcx va_s0) arg3 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0) else va_get_reg64 rR8 va_s0) arg4 0
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win
then Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)
else va_get_reg64 rR9 va_s0) arg5 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) arg6 0 (va_get_mem_layout va_s0) Secret
/\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (if win then Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0) else Vale.X64.Stack_i.load_stack64
(va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) arg7 0 (va_get_mem_layout va_s0)
Secret))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\ va_get_reg64 rRbx va_sM == va_get_reg64
rRbx va_s0 /\ va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0 /\ va_get_reg64 rR12 va_sM ==
va_get_reg64 rR12 va_s0 /\ va_get_reg64 rR13 va_sM == va_get_reg64 rR13 va_s0 /\ va_get_reg64
rR14 va_sM == va_get_reg64 rR14 va_s0 /\ va_get_reg64 rR15 va_sM == va_get_reg64 rR15 va_s0 /\
(win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0) /\ (win ==> va_get_reg64 rRsi
va_sM == va_get_reg64 rRsi va_s0) /\ (win ==> va_get_xmm 6 va_sM == va_get_xmm 6 va_s0) /\ (win
==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==> va_get_xmm 8 va_sM == va_get_xmm 8
va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0) /\ (win ==> va_get_xmm 10 va_sM ==
va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM == va_get_xmm 11 va_s0) /\ (win ==>
va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==> va_get_xmm 13 va_sM == va_get_xmm 13
va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14 va_s0) /\ (win ==> va_get_xmm 15 va_sM
== va_get_xmm 15 va_s0) /\ Vale.X64.Decls.modifies_mem loc_none (va_get_mem va_s0) (va_get_mem
va_sM) /\ va_state_eq va_sM (va_update_mem_layout va_sM (va_update_mem_heaplet 0 va_sM
(va_update_flags va_sM (va_update_xmm 15 va_sM (va_update_xmm 14 va_sM (va_update_xmm 13 va_sM
(va_update_xmm 12 va_sM (va_update_xmm 11 va_sM (va_update_xmm 10 va_sM (va_update_xmm 9 va_sM
(va_update_xmm 8 va_sM (va_update_xmm 7 va_sM (va_update_xmm 6 va_sM (va_update_xmm 5 va_sM
(va_update_xmm 4 va_sM (va_update_xmm 3 va_sM (va_update_xmm 2 va_sM (va_update_xmm 1 va_sM
(va_update_xmm 0 va_sM (va_update_reg64 rR15 va_sM (va_update_reg64 rR14 va_sM (va_update_reg64
rR13 va_sM (va_update_reg64 rR12 va_sM (va_update_reg64 rR11 va_sM (va_update_reg64 rR10 va_sM
(va_update_reg64 rR9 va_sM (va_update_reg64 rR8 va_sM (va_update_reg64 rRsp va_sM
(va_update_reg64 rRbp va_sM (va_update_reg64 rRdi va_sM (va_update_reg64 rRsi va_sM
(va_update_reg64 rRdx va_sM (va_update_reg64 rRcx va_sM (va_update_reg64 rRbx va_sM
(va_update_reg64 rRax va_sM (va_update_ok va_sM (va_update_mem va_sM
va_s0)))))))))))))))))))))))))))))))))))))))
[@ va_qattr]
let va_wp_Test (win:bool) (arg0:buffer64) (arg1:buffer64) (arg2:buffer64) (arg3:buffer64)
(arg4:buffer64) (arg5:buffer64) (arg6:buffer64) (arg7:buffer64) (va_s0:va_state) (va_k:(va_state
-> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ va_get_reg64 rRsp va_s0 == Vale.X64.Stack_i.init_rsp (va_get_stack va_s0) /\
Vale.X64.Memory.is_initial_heap (va_get_mem_layout va_s0) (va_get_mem va_s0) /\ (win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0))
/\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8)
(va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 +
32 + 8 + 16) (va_get_stack va_s0)) /\ (win ==> Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64
rRsp va_s0 + 32 + 8 + 24) (va_get_stack va_s0)) /\ (~win ==> Vale.X64.Stack_i.valid_src_stack64
(va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack va_s0)) /\ (~win ==>
Vale.X64.Stack_i.valid_src_stack64 (va_get_reg64 rRsp va_s0 + 8 + 8) (va_get_stack va_s0)) /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rRcx va_s0)
(fun _ -> va_get_reg64 rRdi va_s0)) arg0 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rRdx va_s0)
(fun _ -> va_get_reg64 rRsi va_s0)) arg1 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rR8 va_s0)
(fun _ -> va_get_reg64 rRdx va_s0)) arg2 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ -> va_get_reg64 rR9 va_s0)
(fun _ -> va_get_reg64 rRcx va_s0)) arg3 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 0) (va_get_stack va_s0)) (fun
_ -> va_get_reg64 rR8 va_s0)) arg4 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 8) (va_get_stack va_s0)) (fun
_ -> va_get_reg64 rR9 va_s0)) arg5 0 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs64 (va_get_mem va_s0) (va_if win (fun _ ->
Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 + 16) (va_get_stack va_s0))
(fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8 + 0) (va_get_stack
va_s0))) arg6 0 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validSrcAddrs64 (va_get_mem
va_s0) (va_if win (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 32 + 8 +
24) (va_get_stack va_s0)) (fun _ -> Vale.X64.Stack_i.load_stack64 (va_get_reg64 rRsp va_s0 + 8
+ 8) (va_get_stack va_s0))) arg7 0 (va_get_mem_layout va_s0) Secret /\ (forall
(va_x_mem:vale_heap) (va_x_rax:nat64) (va_x_rbx:nat64) (va_x_rcx:nat64) (va_x_rdx:nat64)
(va_x_rsi:nat64) (va_x_rdi:nat64) (va_x_rbp:nat64) (va_x_rsp:nat64) (va_x_r8:nat64)
(va_x_r9:nat64) (va_x_r10:nat64) (va_x_r11:nat64) (va_x_r12:nat64) (va_x_r13:nat64)
(va_x_r14:nat64) (va_x_r15:nat64) (va_x_xmm0:quad32) (va_x_xmm1:quad32) (va_x_xmm2:quad32)
(va_x_xmm3:quad32) (va_x_xmm4:quad32) (va_x_xmm5:quad32) (va_x_xmm6:quad32) (va_x_xmm7:quad32)
(va_x_xmm8:quad32) (va_x_xmm9:quad32) (va_x_xmm10:quad32) (va_x_xmm11:quad32)
(va_x_xmm12:quad32) (va_x_xmm13:quad32) (va_x_xmm14:quad32) (va_x_xmm15:quad32)
(va_x_efl:Vale.X64.Flags.t) (va_x_heap0:vale_heap) (va_x_memLayout:vale_heap_layout) . let
va_sM = va_upd_mem_layout va_x_memLayout (va_upd_mem_heaplet 0 va_x_heap0 (va_upd_flags
va_x_efl (va_upd_xmm 15 va_x_xmm15 (va_upd_xmm 14 va_x_xmm14 (va_upd_xmm 13 va_x_xmm13
(va_upd_xmm 12 va_x_xmm12 (va_upd_xmm 11 va_x_xmm11 (va_upd_xmm 10 va_x_xmm10 (va_upd_xmm 9
va_x_xmm9 (va_upd_xmm 8 va_x_xmm8 (va_upd_xmm 7 va_x_xmm7 (va_upd_xmm 6 va_x_xmm6 (va_upd_xmm 5
va_x_xmm5 (va_upd_xmm 4 va_x_xmm4 (va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1
va_x_xmm1 (va_upd_xmm 0 va_x_xmm0 (va_upd_reg64 rR15 va_x_r15 (va_upd_reg64 rR14 va_x_r14
(va_upd_reg64 rR13 va_x_r13 (va_upd_reg64 rR12 va_x_r12 (va_upd_reg64 rR11 va_x_r11
(va_upd_reg64 rR10 va_x_r10 (va_upd_reg64 rR9 va_x_r9 (va_upd_reg64 rR8 va_x_r8 (va_upd_reg64
rRsp va_x_rsp (va_upd_reg64 rRbp va_x_rbp (va_upd_reg64 rRdi va_x_rdi (va_upd_reg64 rRsi
va_x_rsi (va_upd_reg64 rRdx va_x_rdx (va_upd_reg64 rRcx va_x_rcx (va_upd_reg64 rRbx va_x_rbx
(va_upd_reg64 rRax va_x_rax (va_upd_mem va_x_mem va_s0))))))))))))))))))))))))))))))))))) in
va_get_ok va_sM /\ va_get_reg64 rRsp va_sM == va_get_reg64 rRsp va_s0 /\ va_get_reg64 rRbx
va_sM == va_get_reg64 rRbx va_s0 /\ va_get_reg64 rRbp va_sM == va_get_reg64 rRbp va_s0 /\
va_get_reg64 rR12 va_sM == va_get_reg64 rR12 va_s0 /\ va_get_reg64 rR13 va_sM == va_get_reg64
rR13 va_s0 /\ va_get_reg64 rR14 va_sM == va_get_reg64 rR14 va_s0 /\ va_get_reg64 rR15 va_sM ==
va_get_reg64 rR15 va_s0 /\ (win ==> va_get_reg64 rRdi va_sM == va_get_reg64 rRdi va_s0) /\ (win
==> va_get_reg64 rRsi va_sM == va_get_reg64 rRsi va_s0) /\ (win ==> va_get_xmm 6 va_sM ==
va_get_xmm 6 va_s0) /\ (win ==> va_get_xmm 7 va_sM == va_get_xmm 7 va_s0) /\ (win ==>
va_get_xmm 8 va_sM == va_get_xmm 8 va_s0) /\ (win ==> va_get_xmm 9 va_sM == va_get_xmm 9 va_s0)
/\ (win ==> va_get_xmm 10 va_sM == va_get_xmm 10 va_s0) /\ (win ==> va_get_xmm 11 va_sM ==
va_get_xmm 11 va_s0) /\ (win ==> va_get_xmm 12 va_sM == va_get_xmm 12 va_s0) /\ (win ==>
va_get_xmm 13 va_sM == va_get_xmm 13 va_s0) /\ (win ==> va_get_xmm 14 va_sM == va_get_xmm 14
va_s0) /\ (win ==> va_get_xmm 15 va_sM == va_get_xmm 15 va_s0) /\ Vale.X64.Decls.modifies_mem
loc_none (va_get_mem va_s0) (va_get_mem va_sM) ==> va_k va_sM (())))
val va_wpProof_Test : win:bool -> arg0:buffer64 -> arg1:buffer64 -> arg2:buffer64 -> arg3:buffer64
-> arg4:buffer64 -> arg5:buffer64 -> arg6:buffer64 -> arg7:buffer64 -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_Test win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7 va_s0
va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_Test win) ([va_Mod_mem_layout;
va_Mod_mem_heaplet 0; va_Mod_flags; va_Mod_xmm 15; va_Mod_xmm 14; va_Mod_xmm 13; va_Mod_xmm 12;
va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 8; va_Mod_xmm 7; va_Mod_xmm 6;
va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_xmm 0;
va_Mod_reg64 rR15; va_Mod_reg64 rR14; va_Mod_reg64 rR13; va_Mod_reg64 rR12; va_Mod_reg64 rR11;
va_Mod_reg64 rR10; va_Mod_reg64 rR9; va_Mod_reg64 rR8; va_Mod_reg64 rRsp; va_Mod_reg64 rRbp;
va_Mod_reg64 rRdi; va_Mod_reg64 rRsi; va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx;
va_Mod_reg64 rRax; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g)))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Stack_i.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Arch.HeapImpl.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Test.X64.Args.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Stack_i",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.HeapImpl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Test.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Test.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
win: Prims.bool ->
arg0: Vale.X64.Memory.buffer64 ->
arg1: Vale.X64.Memory.buffer64 ->
arg2: Vale.X64.Memory.buffer64 ->
arg3: Vale.X64.Memory.buffer64 ->
arg4: Vale.X64.Memory.buffer64 ->
arg5: Vale.X64.Memory.buffer64 ->
arg6: Vale.X64.Memory.buffer64 ->
arg7: Vale.X64.Memory.buffer64
-> Vale.X64.QuickCode.va_quickCode Prims.unit (Vale.Test.X64.Args.va_code_Test win) | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.X64.Memory.buffer64",
"Vale.X64.QuickCode.va_QProc",
"Prims.unit",
"Vale.Test.X64.Args.va_code_Test",
"Prims.Cons",
"Vale.X64.QuickCode.mod_t",
"Vale.X64.QuickCode.va_Mod_mem_layout",
"Vale.X64.QuickCode.va_Mod_mem_heaplet",
"Vale.X64.QuickCode.va_Mod_flags",
"Vale.X64.QuickCode.va_Mod_xmm",
"Vale.X64.QuickCode.va_Mod_reg64",
"Vale.X64.Machine_s.rR15",
"Vale.X64.Machine_s.rR14",
"Vale.X64.Machine_s.rR13",
"Vale.X64.Machine_s.rR12",
"Vale.X64.Machine_s.rR11",
"Vale.X64.Machine_s.rR10",
"Vale.X64.Machine_s.rR9",
"Vale.X64.Machine_s.rR8",
"Vale.X64.Machine_s.rRsp",
"Vale.X64.Machine_s.rRbp",
"Vale.X64.Machine_s.rRdi",
"Vale.X64.Machine_s.rRsi",
"Vale.X64.Machine_s.rRdx",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Machine_s.rRbx",
"Vale.X64.Machine_s.rRax",
"Vale.X64.QuickCode.va_Mod_mem",
"Prims.Nil",
"Vale.Test.X64.Args.va_wp_Test",
"Vale.Test.X64.Args.va_wpProof_Test",
"Vale.X64.QuickCode.va_quickCode"
] | [] | false | false | false | false | false | let va_quick_Test (win: bool) (arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7: buffer64)
: (va_quickCode unit (va_code_Test win)) =
| (va_QProc (va_code_Test win)
([
va_Mod_mem_layout; va_Mod_mem_heaplet 0; va_Mod_flags; va_Mod_xmm 15; va_Mod_xmm 14;
va_Mod_xmm 13; va_Mod_xmm 12; va_Mod_xmm 11; va_Mod_xmm 10; va_Mod_xmm 9; va_Mod_xmm 8;
va_Mod_xmm 7; va_Mod_xmm 6; va_Mod_xmm 5; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2;
va_Mod_xmm 1; va_Mod_xmm 0; va_Mod_reg64 rR15; va_Mod_reg64 rR14; va_Mod_reg64 rR13;
va_Mod_reg64 rR12; va_Mod_reg64 rR11; va_Mod_reg64 rR10; va_Mod_reg64 rR9; va_Mod_reg64 rR8;
va_Mod_reg64 rRsp; va_Mod_reg64 rRbp; va_Mod_reg64 rRdi; va_Mod_reg64 rRsi;
va_Mod_reg64 rRdx; va_Mod_reg64 rRcx; va_Mod_reg64 rRbx; va_Mod_reg64 rRax; va_Mod_mem
])
(va_wp_Test win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7)
(va_wpProof_Test win arg0 arg1 arg2 arg3 arg4 arg5 arg6 arg7)) | false |
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.pad_to_128_bits_le_quad32_to_bytes | val pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
length final_quads == 1 /\
(let final_quad = index final_quads 0 in
pad_to_128_bits (slice (le_seq_quad32_to_bytes s) 0 num_bytes)
==
le_seq_quad32_to_bytes full_quads @| pad_to_128_bits (slice (le_quad32_to_bytes final_quad) 0 (num_bytes % 16))))) | val pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
length final_quads == 1 /\
(let final_quad = index final_quads 0 in
pad_to_128_bits (slice (le_seq_quad32_to_bytes s) 0 num_bytes)
==
le_seq_quad32_to_bytes full_quads @| pad_to_128_bits (slice (le_quad32_to_bytes final_quad) 0 (num_bytes % 16))))) | let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 132,
"start_col": 0,
"start_line": 90
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 0,
"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": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> num_bytes: Prims.int
-> FStar.Pervasives.Lemma
(requires
1 <= num_bytes /\ num_bytes < 16 * FStar.Seq.Base.length s /\
16 * (FStar.Seq.Base.length s - 1) < num_bytes /\ num_bytes % 16 <> 0 /\
FStar.Seq.Base.length s == Vale.AES.GCM_helpers.bytes_to_quad_size num_bytes)
(ensures
(let num_blocks = num_bytes / 16 in
let _ = FStar.Seq.Properties.split s num_blocks in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ full_quads final_quads = _ in
FStar.Seq.Base.length final_quads == 1 /\
(let final_quad = FStar.Seq.Base.index final_quads 0 in
Vale.AES.GCTR_s.pad_to_128_bits (FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes
s)
0
num_bytes) ==
Vale.Def.Types_s.le_seq_quad32_to_bytes full_quads @|
Vale.AES.GCTR_s.pad_to_128_bits (FStar.Seq.Base.slice (Vale.Def.Types_s.le_quad32_to_bytes
final_quad)
0
(num_bytes % 16))))
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Prims.int",
"Vale.Def.Types_s.nat8",
"Prims.unit",
"Vale.AES.GCM_helpers.le_seq_quad32_to_bytes_tail_prefix",
"FStar.Seq.Properties.slice_slice",
"Vale.Def.Types_s.le_seq_quad32_to_bytes",
"Prims._assert",
"Prims.eq2",
"Vale.Arch.Types.slice_commutes_le_seq_quad32_to_bytes0",
"FStar.Pervasives.Native.tuple2",
"Vale.Def.Words_s.nat8",
"FStar.Seq.Properties.split",
"FStar.Mul.op_Star",
"Prims.op_Division",
"FStar.Seq.Base.length",
"Vale.AES.GCM_helpers.pad_to_128_bits_multiples",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.index",
"Prims.op_Modulus"
] | [] | false | false | true | false | false | let pad_to_128_bits_le_quad32_to_bytes (s: seq quad32) (num_bytes: int) =
| let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads, final_quads = split s num_blocks in
assert (length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b;
let full_blocks = ((length b) / 16) * 16 in
let full_bytes, partial_bytes = split b full_blocks in
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
() | false |
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.le_seq_quad32_to_bytes_tail_prefix | val le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) : Lemma
(requires (1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0))
(ensures (let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra in
x == x')) | val le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) : Lemma
(requires (1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0))
(ensures (let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra in
x == x')) | let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 48,
"start_col": 0,
"start_line": 31
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 0,
"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": 25,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> num_bytes: Prims.nat
-> FStar.Pervasives.Lemma
(requires
1 <= num_bytes /\ num_bytes < 16 * FStar.Seq.Base.length s /\
16 * (FStar.Seq.Base.length s - 1) < num_bytes /\ num_bytes % 16 <> 0)
(ensures
(let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let x =
FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes s)
(num_blocks * 16)
num_bytes
in
let x' =
FStar.Seq.Base.slice (Vale.Def.Types_s.le_quad32_to_bytes (FStar.Seq.Base.index s
num_blocks))
0
num_extra
in
x == x')) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Prims.nat",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Def.Types_s.nat8",
"Prims.eq2",
"FStar.Seq.Base.slice",
"Vale.Def.Types_s.le_seq_quad32_to_bytes",
"FStar.Mul.op_Star",
"FStar.Seq.Base.length",
"Vale.Arch.Types.slice_commutes_le_seq_quad32_to_bytes",
"FStar.Seq.Base.create",
"Vale.Def.Types_s.le_quad32_to_bytes",
"Vale.Arch.Types.le_seq_quad32_to_bytes_of_singleton",
"Vale.Def.Words_s.nat8",
"FStar.Seq.Base.index",
"Prims.int",
"Prims.op_Division",
"Prims.op_Modulus"
] | [] | true | false | true | false | false | let le_seq_quad32_to_bytes_tail_prefix (s: seq quad32) (num_bytes: nat) =
| let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra
);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
() | false |
Pulse.Soundness.STT.fsti | Pulse.Soundness.STT.inames_tm | val inames_tm : FStar.Stubs.Reflection.Types.term | let inames_tm = R.(pack_ln (Tv_FVar (pack_fv inames_lid))) | {
"file_name": "lib/steel/pulse/Pulse.Soundness.STT.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 58,
"end_line": 25,
"start_col": 0,
"start_line": 25
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Soundness.STT
module R = FStar.Reflection.V2
module RT = FStar.Reflection.Typing
open Pulse.Reflection.Util | {
"checked_file": "/",
"dependencies": [
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Soundness.STT.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Soundness",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Soundness",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.V2.Builtins.pack_ln",
"FStar.Stubs.Reflection.V2.Data.Tv_FVar",
"FStar.Stubs.Reflection.V2.Builtins.pack_fv",
"Pulse.Reflection.Util.inames_lid"
] | [] | false | false | false | true | false | let inames_tm =
| let open R in pack_ln (Tv_FVar (pack_fv inames_lid)) | false |
|
Vale.Stdcalls.X64.GCMencryptOpt.fst | Vale.Stdcalls.X64.GCMencryptOpt.gcm256_lemma | val gcm256_lemma : s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Vale.AsLowStar.ValeSig.vale_sig_stdcall (Vale.Stdcalls.X64.GCMencryptOpt.gcm256_pre s iv)
(Vale.Stdcalls.X64.GCMencryptOpt.gcm256_post s iv) | let gcm256_lemma (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = as_t #(VSig.vale_sig_stdcall (gcm256_pre s iv) (gcm256_post s iv)) (gcm256_lemma' s iv) | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCMencryptOpt.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 173,
"end_line": 372,
"start_col": 0,
"start_line": 372
} | module Vale.Stdcalls.X64.GCMencryptOpt
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
open FStar.Mul
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
module GC = Vale.AES.X64.GCMencryptOpt
open Vale.AES.AES_s
open Vale.AES.GCM_s
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b128 = buf_t TUInt8 TUInt128
[@__reduce__] noextract
let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq
[@__reduce__] noextract
let t128_mod_pub = TD_Buffer TUInt8 TUInt128 ({modified=true; strict_disjointness=false; taint=MS.Public})
[@__reduce__] noextract
let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let (dom: list td{List.length dom <= 20}) =
let y = [t128_no_mod; tuint64; tuint64; t128_no_mod; t128_mod_pub; t128_no_mod;
t128_no_mod; t128_no_mod; t128_mod; tuint64; t128_no_mod; t128_mod; tuint64; t128_mod; tuint64; t128_mod; t128_mod] in
assert_norm (List.length y = 17);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm128_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
[@__reduce__] noextract
let gcm128_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f
#set-options "--z3rlimit 50"
[@__reduce__] noextract
let gcm128_lemma'
(s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(code:V.va_code)
(_win:bool)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm128_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\
gcm128_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\
ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\
ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b)
)) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f
(* Prove that gcm128_lemma' has the required type *)
noextract
let gcm128_lemma (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = as_t #(VSig.vale_sig_stdcall (gcm128_pre s iv) (gcm128_post s iv)) (gcm128_lemma' s iv)
noextract
let code_gcm128 = GC.va_code_Gcm_blocks_stdcall IA.win AES_128
(* Here's the type expected for the gcm wrapper *)
[@__reduce__] noextract
let lowstar_gcm128_t (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.as_lowstar_sig_t_weak_stdcall
code_gcm128
dom
[]
_
_
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win))
(* And here's the gcm wrapper itself *)
noextract
let lowstar_gcm128 (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) : lowstar_gcm128_t s iv =
assert_norm (List.length dom + List.length ([]<:list arg) <= 20);
IX64.wrap_weak_stdcall
code_gcm128
dom
(W.mk_prediction code_gcm128 dom [] ((gcm128_lemma s iv) code_gcm128 IA.win))
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm256_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
[@__reduce__] noextract
let gcm256_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f
#set-options "--z3rlimit 50"
[@__reduce__] noextract
let gcm256_lemma'
(s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(code:V.va_code)
(_win:bool)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm256_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\
gcm256_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\
ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\
ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b)
)) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_256
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f
(* Prove that gcm256_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.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"Vale.AES.X64.GCMencryptOpt.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.GCMencryptOpt.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AES.X64.GCMencryptOpt",
"short_module": "GC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Vale.AsLowStar.ValeSig.vale_sig_stdcall (Vale.Stdcalls.X64.GCMencryptOpt.gcm256_pre s iv)
(Vale.Stdcalls.X64.GCMencryptOpt.gcm256_post s iv) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCM_s.supported_iv_LE",
"Vale.Stdcalls.X64.GCMencryptOpt.as_t",
"Vale.AsLowStar.ValeSig.vale_sig_stdcall",
"Vale.Stdcalls.X64.GCMencryptOpt.dom",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm256_pre",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm256_post",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm256_lemma'"
] | [] | false | false | false | false | false | let gcm256_lemma (s: Ghost.erased (Seq.seq nat32)) (iv: Ghost.erased supported_iv_LE) =
| as_t #(VSig.vale_sig_stdcall (gcm256_pre s iv) (gcm256_post s iv)) (gcm256_lemma' s iv) | false |
|
Vale.Stdcalls.X64.GCMencryptOpt.fst | Vale.Stdcalls.X64.GCMencryptOpt.gcm128_lemma | val gcm128_lemma : s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Vale.AsLowStar.ValeSig.vale_sig_stdcall (Vale.Stdcalls.X64.GCMencryptOpt.gcm128_pre s iv)
(Vale.Stdcalls.X64.GCMencryptOpt.gcm128_post s iv) | let gcm128_lemma (s:Ghost.erased (Seq.seq nat32)) (iv:Ghost.erased supported_iv_LE) = as_t #(VSig.vale_sig_stdcall (gcm128_pre s iv) (gcm128_post s iv)) (gcm128_lemma' s iv) | {
"file_name": "vale/code/arch/x64/interop/Vale.Stdcalls.X64.GCMencryptOpt.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 173,
"end_line": 200,
"start_col": 0,
"start_line": 200
} | module Vale.Stdcalls.X64.GCMencryptOpt
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
open FStar.Mul
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.Def.Types_s
open Vale.Interop.Base
module IX64 = Vale.Interop.X64
module VSig = Vale.AsLowStar.ValeSig
module LSig = Vale.AsLowStar.LowStarSig
module ME = Vale.X64.Memory
module V = Vale.X64.Decls
module IA = Vale.Interop.Assumptions
module W = Vale.AsLowStar.Wrapper
open Vale.X64.MemoryAdapters
module VS = Vale.X64.State
module MS = Vale.X64.Machine_s
module GC = Vale.AES.X64.GCMencryptOpt
open Vale.AES.AES_s
open Vale.AES.GCM_s
let uint64 = UInt64.t
(* A little utility to trigger normalization in types *)
noextract
let as_t (#a:Type) (x:normal a) : a = x
noextract
let as_normal_t (#a:Type) (x:a) : normal a = x
[@__reduce__] noextract
let b128 = buf_t TUInt8 TUInt128
[@__reduce__] noextract
let t128_mod = TD_Buffer TUInt8 TUInt128 default_bq
[@__reduce__] noextract
let t128_mod_pub = TD_Buffer TUInt8 TUInt128 ({modified=true; strict_disjointness=false; taint=MS.Public})
[@__reduce__] noextract
let t128_no_mod = TD_Buffer TUInt8 TUInt128 ({modified=false; strict_disjointness=false; taint=MS.Secret})
[@__reduce__] noextract
let tuint64 = TD_Base TUInt64
[@__reduce__] noextract
let (dom: list td{List.length dom <= 20}) =
let y = [t128_no_mod; tuint64; tuint64; t128_no_mod; t128_mod_pub; t128_no_mod;
t128_no_mod; t128_no_mod; t128_mod; tuint64; t128_no_mod; t128_mod; tuint64; t128_mod; tuint64; t128_mod; t128_mod] in
assert_norm (List.length y = 17);
y
(* Need to rearrange the order of arguments *)
[@__reduce__] noextract
let gcm128_pre : (Ghost.erased (Seq.seq nat32)) -> (Ghost.erased supported_iv_LE) -> VSig.vale_pre dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state) ->
GC.va_req_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b) (Ghost.reveal s)
[@__reduce__] noextract
let gcm128_post : Ghost.erased (Seq.seq nat32) -> (Ghost.erased supported_iv_LE) -> VSig.vale_post dom =
fun (s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(c:V.va_code)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
(va_s1:V.va_state)
(f:V.va_fuel) ->
GC.va_ens_Gcm_blocks_stdcall c va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b) (UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) va_s1 f
#set-options "--z3rlimit 50"
[@__reduce__] noextract
let gcm128_lemma'
(s:Ghost.erased (Seq.seq nat32))
(iv:Ghost.erased supported_iv_LE)
(code:V.va_code)
(_win:bool)
(auth_b:b128)
(auth_bytes:uint64)
(auth_num:uint64)
(keys_b:b128)
(iv_b:b128)
(hkeys_b:b128)
(abytes_b:b128)
(in128x6_b:b128)
(out128x6_b:b128)
(len128x6_num:uint64)
(in128_b:b128)
(out128_b:b128)
(len128_num:uint64)
(inout_b:b128)
(plain_num:uint64)
(scratch_b:b128)
(tag_b:b128)
(va_s0:V.va_state)
: Ghost (V.va_state & V.va_fuel)
(requires
gcm128_pre s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b 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 /\
gcm128_post s iv code auth_b auth_bytes auth_num keys_b iv_b hkeys_b abytes_b
in128x6_b out128x6_b len128x6_num in128_b out128_b len128_num inout_b plain_num scratch_b tag_b va_s0 va_s1 f /\
ME.buffer_writeable (as_vale_buffer auth_b) /\
ME.buffer_writeable (as_vale_buffer keys_b) /\
ME.buffer_writeable (as_vale_buffer iv_b) /\
ME.buffer_writeable (as_vale_buffer hkeys_b) /\
ME.buffer_writeable (as_vale_buffer abytes_b) /\
ME.buffer_writeable (as_vale_buffer in128x6_b) /\
ME.buffer_writeable (as_vale_buffer out128x6_b) /\
ME.buffer_writeable (as_vale_buffer in128_b) /\
ME.buffer_writeable (as_vale_buffer out128_b) /\
ME.buffer_writeable (as_vale_buffer inout_b) /\
ME.buffer_writeable (as_vale_buffer scratch_b) /\
ME.buffer_writeable (as_vale_buffer tag_b)
)) =
let va_s1, f = GC.va_lemma_Gcm_blocks_stdcall code va_s0 IA.win AES_128
(as_vale_buffer auth_b) (UInt64.v auth_bytes)
(UInt64.v auth_num) (as_vale_buffer keys_b)
(as_vale_buffer iv_b) (Ghost.reveal iv) (as_vale_buffer hkeys_b)
(as_vale_buffer abytes_b) (as_vale_buffer in128x6_b)
(as_vale_buffer out128x6_b) (UInt64.v len128x6_num)
(as_vale_buffer in128_b) (as_vale_buffer out128_b)
(UInt64.v len128_num) (as_vale_buffer inout_b)
(UInt64.v plain_num)
(as_vale_buffer scratch_b) (as_vale_buffer tag_b)
(Ghost.reveal s) in
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 auth_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 keys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 iv_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 hkeys_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 abytes_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128x6_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 in128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 out128_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 inout_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 scratch_b;
Vale.AsLowStar.MemoryHelpers.buffer_writeable_reveal ME.TUInt8 ME.TUInt128 tag_b;
va_s1, f
(* Prove that gcm128_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.AsLowStar.Wrapper.fsti.checked",
"Vale.AsLowStar.ValeSig.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.AsLowStar.LowStarSig.fst.checked",
"Vale.AES.X64.GCMencryptOpt.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Stdcalls.X64.GCMencryptOpt.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AES.X64.GCMencryptOpt",
"short_module": "GC"
},
{
"abbrev": true,
"full_module": "Vale.X64.Machine_s",
"short_module": "MS"
},
{
"abbrev": true,
"full_module": "Vale.X64.State",
"short_module": "VS"
},
{
"abbrev": false,
"full_module": "Vale.X64.MemoryAdapters",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.Wrapper",
"short_module": "W"
},
{
"abbrev": true,
"full_module": "Vale.Interop.Assumptions",
"short_module": "IA"
},
{
"abbrev": true,
"full_module": "Vale.X64.Decls",
"short_module": "V"
},
{
"abbrev": true,
"full_module": "Vale.X64.Memory",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.LowStarSig",
"short_module": "LSig"
},
{
"abbrev": true,
"full_module": "Vale.AsLowStar.ValeSig",
"short_module": "VSig"
},
{
"abbrev": true,
"full_module": "Vale.Interop.X64",
"short_module": "IX64"
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Stdcalls.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Ghost.erased (FStar.Seq.Base.seq Vale.Def.Types_s.nat32) ->
iv: FStar.Ghost.erased Vale.AES.GCM_s.supported_iv_LE
-> Vale.AsLowStar.ValeSig.vale_sig_stdcall (Vale.Stdcalls.X64.GCMencryptOpt.gcm128_pre s iv)
(Vale.Stdcalls.X64.GCMencryptOpt.gcm128_post s iv) | Prims.Tot | [
"total"
] | [] | [
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCM_s.supported_iv_LE",
"Vale.Stdcalls.X64.GCMencryptOpt.as_t",
"Vale.AsLowStar.ValeSig.vale_sig_stdcall",
"Vale.Stdcalls.X64.GCMencryptOpt.dom",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm128_pre",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm128_post",
"Vale.Stdcalls.X64.GCMencryptOpt.gcm128_lemma'"
] | [] | false | false | false | false | false | let gcm128_lemma (s: Ghost.erased (Seq.seq nat32)) (iv: Ghost.erased supported_iv_LE) =
| as_t #(VSig.vale_sig_stdcall (gcm128_pre s iv) (gcm128_post s iv)) (gcm128_lemma' s iv) | false |
|
Pulse.Soundness.STT.fsti | Pulse.Soundness.STT.post_type | val post_type : t: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term | let post_type t = mk_arrow (t, R.Q_Explicit) vprop_tm | {
"file_name": "lib/steel/pulse/Pulse.Soundness.STT.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 53,
"end_line": 24,
"start_col": 0,
"start_line": 24
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Soundness.STT
module R = FStar.Reflection.V2
module RT = FStar.Reflection.Typing
open Pulse.Reflection.Util | {
"checked_file": "/",
"dependencies": [
"Pulse.Reflection.Util.fst.checked",
"prims.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Pulse.Soundness.STT.fsti"
} | [
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": false,
"full_module": "Pulse.Soundness",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Soundness",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: FStar.Stubs.Reflection.Types.term -> FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"Pulse.Reflection.Util.mk_arrow",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Reflection.V2.Data.aqualv",
"FStar.Stubs.Reflection.V2.Data.Q_Explicit",
"Pulse.Reflection.Util.vprop_tm"
] | [] | false | false | false | true | false | let post_type t =
| mk_arrow (t, R.Q_Explicit) vprop_tm | false |
|
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.lemma_pad_to_32_bits | val lemma_pad_to_32_bits (s s'': seq4 nat8) (n: nat)
: Lemma
(requires
n <= 4 /\
(forall (i: nat). {:pattern (index s i)\/(index s'' i)}
i < 4 ==> index s'' i == (if i < n then index s i else 0)))
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)
) | val lemma_pad_to_32_bits (s s'': seq4 nat8) (n: nat)
: Lemma
(requires
n <= 4 /\
(forall (i: nat). {:pattern (index s i)\/(index s'' i)}
i < 4 ==> index s'' i == (if i < n then index s i else 0)))
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)
) | let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 4 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else
assert (n == 3 \/ n == 4);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000);
assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000);
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 279,
"start_col": 0,
"start_line": 259
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
)
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
()
(*
let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 16)
(ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes)))
=
()
let insert_0_is_padding (q:quad32) :
Lemma (let q' = insert_nat64_def q 0 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8)))
=
()
*)
#reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10"
let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) =
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert(i < 4 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4))) i))
(fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2");
assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4))
#reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1"
let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 2 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
assert (n == 0 \/ n == 1 \/ n == 2);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1);
assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100);
assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: Vale.Def.Words.Seq_s.seq4 Vale.Def.Types_s.nat8 ->
s'': Vale.Def.Words.Seq_s.seq4 Vale.Def.Types_s.nat8 ->
n: Prims.nat
-> FStar.Pervasives.Lemma
(requires
n <= 4 /\
(forall (i: Prims.nat). {:pattern FStar.Seq.Base.index s i\/FStar.Seq.Base.index s'' i}
i < 4 ==>
FStar.Seq.Base.index s'' i ==
(match i < n with
| true -> FStar.Seq.Base.index s i
| _ -> 0)))
(ensures
Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE s'') ==
Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE s) %
Prims.pow2 (8 * n)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words.Seq_s.seq4",
"Vale.Def.Types_s.nat8",
"Prims.nat",
"Prims.unit",
"Prims._assert",
"Prims.l_imp",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Prims.pow2",
"FStar.Mul.op_Star",
"Vale.Def.Words_s.natN",
"Prims.op_Multiply",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words.Seq_s.seq_to_four_LE",
"FStar.Pervasives.assert_norm",
"Vale.Def.Words.Four_s.four_to_nat_unfold",
"Prims.op_LessThanOrEqual",
"Vale.AES.GCM_helpers.lemma_pad_to_32_bits_helper",
"Prims.bool",
"Prims.l_or",
"Prims.l_and",
"Prims.b2t",
"Prims.l_Forall",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_pad_to_32_bits (s s'': seq4 nat8) (n: nat)
: Lemma
(requires
n <= 4 /\
(forall (i: nat). {:pattern (index s i)\/(index s'' i)}
i < 4 ==> index s'' i == (if i < n then index s i else 0)))
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)
) =
| if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else assert (n == 3 \/ n == 4);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000);
assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000);
() | false |
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.lemma_64_32_lo2 | val lemma_64_32_lo2 (q': quad32) (lo lo': nat64) (n: nat)
: Lemma
(requires
n <= 4 /\ lo' == lo % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0))
(ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0) | val lemma_64_32_lo2 (q': quad32) (lo lo': nat64) (n: nat)
: Lemma
(requires
n <= 4 /\ lo' == lo % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0))
(ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0) | let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
lo' == lo % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)
)
(ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0)
=
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (pow2 (5 * 8) == 0x10000000000);
assert_norm (pow2 (6 * 8) == 0x1000000000000);
assert_norm (pow2 (7 * 8) == 0x100000000000000);
assert_norm (pow2 (8 * 8) == 0x10000000000000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 369,
"start_col": 0,
"start_line": 354
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
)
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
()
(*
let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 16)
(ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes)))
=
()
let insert_0_is_padding (q:quad32) :
Lemma (let q' = insert_nat64_def q 0 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8)))
=
()
*)
#reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10"
let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) =
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert(i < 4 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4))) i))
(fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2");
assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4))
#reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1"
let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 2 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
assert (n == 0 \/ n == 1 \/ n == 2);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1);
assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100);
assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000);
()
let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 4 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else
assert (n == 3 \/ n == 4);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000);
assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000);
()
let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in
assert_norm (f 0);
assert_norm (f 1);
assert_norm (f 2);
assert_norm (f 3);
assert_norm (f 4);
()
let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma
(requires n <= 2)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 2);
assert_norm (f 1);
assert_norm (f 0);
()
let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
if n <= 2 then lemma_mod_n_8_lower2_helper q n else
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 4);
assert_norm (f 3);
()
let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n
let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n)))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n
let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
lo' == lo % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)
)
(ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0)
=
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
q': Vale.Def.Types_s.quad32 ->
lo: Vale.Def.Types_s.nat64 ->
lo': Vale.Def.Types_s.nat64 ->
n: Prims.nat
-> FStar.Pervasives.Lemma
(requires
n <= 4 /\ lo' == lo % Prims.pow2 (8 * (n + 4)) /\
Vale.Def.Words.Four_s.four_to_two_two q' ==
Vale.Def.Words_s.Mktwo (Vale.Def.Words.Two_s.nat_to_two 32 lo')
(Vale.Def.Words.Two_s.nat_to_two 32 0))
(ensures
lo' == Mkfour?.lo0 q' + 0x100000000 * Mkfour?.lo1 q' /\
q' == Vale.Def.Words_s.Mkfour (Mkfour?.lo0 q') (Mkfour?.lo1 q') 0 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.nat64",
"Prims.nat",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Vale.Def.Words_s.two",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Two_s.nat_to_two",
"Vale.Def.Words.Two_s.nat_to_two_unfold",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Modulus",
"Prims.op_Addition",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words.Four_s.four_to_two_two",
"Vale.Def.Words_s.Mktwo",
"Prims.squash",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.Mkfour",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_64_32_lo2 (q': quad32) (lo lo': nat64) (n: nat)
: Lemma
(requires
n <= 4 /\ lo' == lo % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0))
(ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0) =
| assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (pow2 (5 * 8) == 0x10000000000);
assert_norm (pow2 (6 * 8) == 0x1000000000000);
assert_norm (pow2 (7 * 8) == 0x100000000000000);
assert_norm (pow2 (8 * 8) == 0x10000000000000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
() | false |
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.lemma_pad_to_32_bits_helper | val lemma_pad_to_32_bits_helper (s s'': seq4 nat8) (n: nat)
: Lemma
(requires
n <= 2 /\
(forall (i: nat). {:pattern (index s i)\/(index s'' i)}
i < 4 ==> index s'' i == (if i < n then index s i else 0)))
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)
) | val lemma_pad_to_32_bits_helper (s s'': seq4 nat8) (n: nat)
: Lemma
(requires
n <= 2 /\
(forall (i: nat). {:pattern (index s i)\/(index s'' i)}
i < 4 ==> index s'' i == (if i < n then index s i else 0)))
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)
) | let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 2 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
assert (n == 0 \/ n == 1 \/ n == 2);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1);
assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100);
assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000);
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 257,
"start_col": 0,
"start_line": 237
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
)
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
()
(*
let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 16)
(ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes)))
=
()
let insert_0_is_padding (q:quad32) :
Lemma (let q' = insert_nat64_def q 0 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8)))
=
()
*)
#reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10"
let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) =
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert(i < 4 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4))) i))
(fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2");
assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4)) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: Vale.Def.Words.Seq_s.seq4 Vale.Def.Types_s.nat8 ->
s'': Vale.Def.Words.Seq_s.seq4 Vale.Def.Types_s.nat8 ->
n: Prims.nat
-> FStar.Pervasives.Lemma
(requires
n <= 2 /\
(forall (i: Prims.nat). {:pattern FStar.Seq.Base.index s i\/FStar.Seq.Base.index s'' i}
i < 4 ==>
FStar.Seq.Base.index s'' i ==
(match i < n with
| true -> FStar.Seq.Base.index s i
| _ -> 0)))
(ensures
Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE s'') ==
Vale.Def.Words.Four_s.four_to_nat 8 (Vale.Def.Words.Seq_s.seq_to_four_LE s) %
Prims.pow2 (8 * n)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words.Seq_s.seq4",
"Vale.Def.Types_s.nat8",
"Prims.nat",
"Prims.unit",
"Prims._assert",
"Prims.l_imp",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Prims.pow2",
"FStar.Mul.op_Star",
"Vale.Def.Words_s.natN",
"Prims.op_Multiply",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words.Seq_s.seq_to_four_LE",
"FStar.Pervasives.assert_norm",
"Vale.Def.Words.Four_s.four_to_nat_unfold",
"Prims.l_or",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.l_Forall",
"Prims.op_LessThan",
"FStar.Seq.Base.index",
"Prims.bool",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_pad_to_32_bits_helper (s s'': seq4 nat8) (n: nat)
: Lemma
(requires
n <= 2 /\
(forall (i: nat). {:pattern (index s i)\/(index s'' i)}
i < 4 ==> index s'' i == (if i < n then index s i else 0)))
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n)
) =
| assert (n == 0 \/ n == 1 \/ n == 2);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1);
assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100);
assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000);
() | false |
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.lemma_mod_n_8_lower2 | val lemma_mod_n_8_lower2 (q: quad32) (n: nat)
: Lemma (requires n <= 4)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) | val lemma_mod_n_8_lower2 (q: quad32) (n: nat)
: Lemma (requires n <= 4)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) | let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
if n <= 2 then lemma_mod_n_8_lower2_helper q n else
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 4);
assert_norm (f 3);
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 317,
"start_col": 0,
"start_line": 307
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
)
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
()
(*
let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 16)
(ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes)))
=
()
let insert_0_is_padding (q:quad32) :
Lemma (let q' = insert_nat64_def q 0 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8)))
=
()
*)
#reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10"
let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) =
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert(i < 4 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4))) i))
(fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2");
assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4))
#reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1"
let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 2 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
assert (n == 0 \/ n == 1 \/ n == 2);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1);
assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100);
assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000);
()
let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 4 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else
assert (n == 3 \/ n == 4);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000);
assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000);
()
let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in
assert_norm (f 0);
assert_norm (f 1);
assert_norm (f 2);
assert_norm (f 3);
assert_norm (f 4);
()
let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma
(requires n <= 2)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 2);
assert_norm (f 1);
assert_norm (f 0);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32 -> n: Prims.nat
-> FStar.Pervasives.Lemma (requires n <= 4)
(ensures
Vale.Arch.Types.lo64 q % Prims.pow2 (8 * (4 + n)) ==
Mkfour?.lo0 q + 0x100000000 * (Mkfour?.lo1 q % Prims.pow2 (8 * n))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.nat",
"Prims.op_LessThanOrEqual",
"Vale.AES.GCM_helpers.lemma_mod_n_8_lower2_helper",
"Prims.bool",
"Vale.Def.Types_s.nat32",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.logical",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Vale.Arch.Types.lo64_def",
"Prims.pow2",
"FStar.Mul.op_Star",
"Prims.op_Addition",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Arch.Types.lo64_reveal",
"Prims.squash",
"Vale.Arch.Types.lo64",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_mod_n_8_lower2 (q: quad32) (n: nat)
: Lemma (requires n <= 4)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) =
| lo64_reveal ();
if n <= 2
then lemma_mod_n_8_lower2_helper q n
else
let Mkfour _ _ _ _ = q in
let f (n: nat{n <= 4}) =
lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))
in
assert_norm (f 4);
assert_norm (f 3);
() | false |
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.lemma_64_32_hi1 | val lemma_64_32_hi1 (q': quad32) (hi hi': nat64) (n: nat)
: Lemma
(requires
n <= 4 /\ hi' == hi % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi'))
(ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0) | val lemma_64_32_hi1 (q': quad32) (hi hi': nat64) (n: nat)
: Lemma
(requires
n <= 4 /\ hi' == hi % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi'))
(ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0) | let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
hi' == hi % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')
)
(ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0)
=
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi');
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 385,
"start_col": 0,
"start_line": 371
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
)
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
()
(*
let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 16)
(ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes)))
=
()
let insert_0_is_padding (q:quad32) :
Lemma (let q' = insert_nat64_def q 0 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8)))
=
()
*)
#reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10"
let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) =
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert(i < 4 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4))) i))
(fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2");
assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4))
#reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1"
let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 2 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
assert (n == 0 \/ n == 1 \/ n == 2);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1);
assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100);
assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000);
()
let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 4 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else
assert (n == 3 \/ n == 4);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000);
assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000);
()
let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in
assert_norm (f 0);
assert_norm (f 1);
assert_norm (f 2);
assert_norm (f 3);
assert_norm (f 4);
()
let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma
(requires n <= 2)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 2);
assert_norm (f 1);
assert_norm (f 0);
()
let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
if n <= 2 then lemma_mod_n_8_lower2_helper q n else
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 4);
assert_norm (f 3);
()
let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n
let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n)))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n
let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
lo' == lo % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)
)
(ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0)
=
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
()
let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
lo' == lo % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)
)
(ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0)
=
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (pow2 (5 * 8) == 0x10000000000);
assert_norm (pow2 (6 * 8) == 0x1000000000000);
assert_norm (pow2 (7 * 8) == 0x100000000000000);
assert_norm (pow2 (8 * 8) == 0x10000000000000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
q': Vale.Def.Types_s.quad32 ->
hi: Vale.Def.Types_s.nat64 ->
hi': Vale.Def.Types_s.nat64 ->
n: Prims.nat
-> FStar.Pervasives.Lemma
(requires
n <= 4 /\ hi' == hi % Prims.pow2 (8 * n) /\
Vale.Def.Words.Four_s.four_to_two_two q' ==
Vale.Def.Words_s.Mktwo (Vale.Def.Words_s.Mktwo (Mkfour?.lo0 q') (Mkfour?.lo1 q'))
(Vale.Def.Words.Two_s.nat_to_two 32 hi'))
(ensures hi' < 0x100000000 /\ hi' == Mkfour?.hi2 q' /\ Mkfour?.hi3 q' == 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.nat64",
"Prims.nat",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Vale.Def.Words_s.two",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Two_s.nat_to_two",
"Vale.Def.Words.Two_s.nat_to_two_unfold",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Modulus",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words.Four_s.four_to_two_two",
"Vale.Def.Words_s.Mktwo",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Prims.squash",
"Prims.op_LessThan",
"Prims.l_or",
"Vale.Def.Words_s.pow2_64",
"Vale.Def.Words_s.pow2_32",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_64_32_hi1 (q': quad32) (hi hi': nat64) (n: nat)
: Lemma
(requires
n <= 4 /\ hi' == hi % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi'))
(ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0) =
| assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi');
() | false |
LowParse.Low.Base.fst | LowParse.Low.Base.list_nth | val list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' i: U32.t)
: HST.Stack U32.t
(requires
(fun h -> valid_list p h sl pos pos' /\ U32.v i < L.length (contents_list p h sl pos pos')))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ valid_list p h sl pos res /\ valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i))) | val list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' i: U32.t)
: HST.Stack U32.t
(requires
(fun h -> valid_list p h sl pos pos' /\ U32.v i < L.length (contents_list p h sl pos pos')))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ valid_list p h sl pos res /\ valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i))) | let list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(i: U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos' /\
U32.v i < L.length (contents_list p h sl pos pos')
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
valid_list p h sl pos res /\
valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i)
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos1 = BF.alloca pos 1ul in
let bk = BF.alloca 0ul 1ul in
let h2 = HST.get () in
valid_list_nil p h0 sl pos;
let _ : bool = list_fold_left_gen
p
j
sl
pos pos'
h2
(Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
let k = Seq.index (B.as_seq h bk) 0 in
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\
B.live h bpos1 /\
B.live h bk /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v k /\
U32.v k <= U32.v i
)
(fun h _ _ _ h' ->
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bpos1);
// assert (B.loc_not_unused_in h2 `B.loc_includes` B.loc_buffer bk);
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h'
)
(fun h ->
let pos1 = Seq.index (B.as_seq h bpos1) 0 in
B.live h bpos1 /\
valid p h0 sl pos1 /\
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v i /\
contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i)
)
(fun _ _ ->
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 ->
let k = B.index bk 0ul in
if k = i
then begin
B.upd bpos1 0ul pos1;
valid_list_cons_recip p h0 sl pos1 pos';
list_index_append (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') (U32.v i);
valid_list_append p h0 sl pos pos1 pos' ;
assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i));
false
end else begin
B.upd bk 0ul (k `U32.add` 1ul);
let h = HST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h;
valid_list_snoc p h0 sl pos pos1;
assert (valid p h0 sl pos1);
assert (pos2 == get_valid_pos p h0 sl pos1);
assert (valid_list p h0 sl pos pos2);
list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1];
true
end
)
in
let res = B.index bpos1 0ul in
HST.pop_frame ();
res | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 1597,
"start_col": 0,
"start_line": 1508
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
()
inline_for_extraction
let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len
#push-options "--z3rlimit 32 --fuel 2 --ifuel 1"
inline_for_extraction
let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
(x: Ghost.erased t) ->
HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
(#rrel_out #rel_out: _)
(sl_out : slice rrel_out rel_out)
(pos_out : U32.t)
: HST.Stack U32.t
(requires (fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\
valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out
))
(ensures (fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
//B.fresh_frame_modifies h0 h1;
let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\ (
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow
)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))
inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then begin
assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2
end else
L.append_l_nil (L.filter f (G.reveal l1))
)
;
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out'
#pop-options
#push-options "--z3rlimit 64 --fuel 2 --ifuel 1" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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": false,
"smtencoding_l_arith_repr": "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": 64,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: LowParse.Spec.Base.parser k t ->
j: LowParse.Low.Base.jumper p ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t ->
i: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"LowStar.Monotonic.Buffer.index",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"LowParse.Low.Base.list_fold_left_gen",
"FStar.Ghost.hide",
"LowStar.Monotonic.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_region_only",
"FStar.Monotonic.HyperStack.get_tip",
"FStar.Monotonic.HyperStack.mem",
"Prims.list",
"Prims.l_and",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.live",
"LowParse.Low.Base.Spec.valid_list",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.List.Tot.Base.length",
"LowParse.Low.Base.Spec.contents_list",
"FStar.UInt32.v",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.index",
"LowStar.Monotonic.Buffer.as_seq",
"LowStar.Monotonic.Buffer.modifies_only_not_unused_in",
"LowStar.Monotonic.Buffer.loc_unused_in_not_unused_in_disjoint",
"LowParse.Low.Base.Spec.valid",
"LowParse.Low.Base.Spec.get_valid_pos",
"LowParse.Low.Base.Spec.contents",
"FStar.List.Tot.Base.index",
"Prims.op_Equality",
"Prims._assert",
"LowParse.Low.Base.Spec.valid_list_append",
"LowParse.Low.Base.Spec.list_index_append",
"LowParse.Low.Base.Spec.valid_list_cons_recip",
"LowStar.Monotonic.Buffer.upd",
"LowParse.Low.Base.Spec.list_length_append",
"Prims.Cons",
"Prims.Nil",
"LowParse.Low.Base.Spec.valid_list_snoc",
"LowStar.Monotonic.Buffer.loc_none",
"FStar.HyperStack.ST.get",
"FStar.UInt32.add",
"LowParse.Low.Base.Spec.valid_list_nil",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"FStar.UInt32.uint_to_t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.Buffer.alloca",
"FStar.HyperStack.ST.push_frame",
"Prims.op_LessThan"
] | [] | false | true | false | false | false | let list_nth
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' i: U32.t)
: HST.Stack U32.t
(requires
(fun h -> valid_list p h sl pos pos' /\ U32.v i < L.length (contents_list p h sl pos pos')))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\ valid_list p h sl pos res /\ valid p h sl res /\
valid_list p h sl (get_valid_pos p h sl res) pos' /\
L.length (contents_list p h sl pos res) == U32.v i /\
contents p h sl res == L.index (contents_list p h sl pos pos') (U32.v i))) =
| let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos1 = BF.alloca pos 1ul in
let bk = BF.alloca 0ul 1ul in
let h2 = HST.get () in
valid_list_nil p h0 sl pos;
let _:bool =
list_fold_left_gen p j sl pos pos' h2 (Ghost.hide (B.loc_region_only true (HS.get_tip h1)))
(fun h l1 l2 pos1 ->
let k = Seq.index (B.as_seq h bk) 0 in
B.modifies (B.loc_region_only true (HS.get_tip h1)) h2 h /\ B.live h bpos1 /\ B.live h bk /\
valid_list p h0 sl pos pos1 /\ valid_list p h0 sl pos1 pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v k /\ U32.v k <= U32.v i)
(fun h _ _ _ h' ->
B.loc_unused_in_not_unused_in_disjoint h2;
B.modifies_only_not_unused_in (B.loc_region_only true (HS.get_tip h1)) h2 h')
(fun h ->
let pos1 = Seq.index (B.as_seq h bpos1) 0 in
B.live h bpos1 /\ valid p h0 sl pos1 /\ valid_list p h0 sl pos pos1 /\
valid_list p h0 sl (get_valid_pos p h0 sl pos1) pos' /\
L.length (contents_list p h0 sl pos pos1) == U32.v i /\
contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i))
(fun _ _ -> B.loc_unused_in_not_unused_in_disjoint h2)
(fun pos1 pos2 ->
let k = B.index bk 0ul in
if k = i
then
(B.upd bpos1 0ul pos1;
valid_list_cons_recip p h0 sl pos1 pos';
list_index_append (contents_list p h0 sl pos pos1)
(contents_list p h0 sl pos1 pos')
(U32.v i);
valid_list_append p h0 sl pos pos1 pos';
assert (contents p h0 sl pos1 == L.index (contents_list p h0 sl pos pos') (U32.v i));
false)
else
(B.upd bk 0ul (k `U32.add` 1ul);
let h = HST.get () in
B.modifies_only_not_unused_in B.loc_none h0 h;
valid_list_snoc p h0 sl pos pos1;
assert (valid p h0 sl pos1);
assert (pos2 == get_valid_pos p h0 sl pos1);
assert (valid_list p h0 sl pos pos2);
list_length_append (contents_list p h0 sl pos pos1) [contents p h0 sl pos1];
true))
in
let res = B.index bpos1 0ul in
HST.pop_frame ();
res | false |
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.lemma_mod_n_8_lower2_helper | val lemma_mod_n_8_lower2_helper (q: quad32) (n: nat)
: Lemma (requires n <= 2)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) | val lemma_mod_n_8_lower2_helper (q: quad32) (n: nat)
: Lemma (requires n <= 2)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) | let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma
(requires n <= 2)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 2);
assert_norm (f 1);
assert_norm (f 0);
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 305,
"start_col": 0,
"start_line": 295
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
)
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
()
(*
let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 16)
(ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes)))
=
()
let insert_0_is_padding (q:quad32) :
Lemma (let q' = insert_nat64_def q 0 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8)))
=
()
*)
#reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10"
let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) =
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert(i < 4 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4))) i))
(fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2");
assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4))
#reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1"
let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 2 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
assert (n == 0 \/ n == 1 \/ n == 2);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1);
assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100);
assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000);
()
let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 4 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else
assert (n == 3 \/ n == 4);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000);
assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000);
()
let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in
assert_norm (f 0);
assert_norm (f 1);
assert_norm (f 2);
assert_norm (f 3);
assert_norm (f 4);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32 -> n: Prims.nat
-> FStar.Pervasives.Lemma (requires n <= 2)
(ensures
Vale.Arch.Types.lo64 q % Prims.pow2 (8 * (4 + n)) ==
Mkfour?.lo0 q + 0x100000000 * (Mkfour?.lo1 q % Prims.pow2 (8 * n))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.nat",
"Vale.Def.Types_s.nat32",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.logical",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Vale.Arch.Types.lo64_def",
"Prims.pow2",
"FStar.Mul.op_Star",
"Prims.op_Addition",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Arch.Types.lo64_reveal",
"Prims.squash",
"Vale.Arch.Types.lo64",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_mod_n_8_lower2_helper (q: quad32) (n: nat)
: Lemma (requires n <= 2)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))) =
| lo64_reveal ();
let Mkfour _ _ _ _ = q in
let f (n: nat{n <= 4}) =
lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n))
in
assert_norm (f 2);
assert_norm (f 1);
assert_norm (f 0);
() | false |
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.lemma_64_32_lo1 | val lemma_64_32_lo1 (q': quad32) (lo lo': nat64) (n: nat)
: Lemma
(requires
n <= 4 /\ lo' == lo % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0))
(ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0) | val lemma_64_32_lo1 (q': quad32) (lo lo': nat64) (n: nat)
: Lemma
(requires
n <= 4 /\ lo' == lo % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0))
(ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0) | let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
lo' == lo % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)
)
(ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0)
=
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 352,
"start_col": 0,
"start_line": 337
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
)
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
()
(*
let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 16)
(ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes)))
=
()
let insert_0_is_padding (q:quad32) :
Lemma (let q' = insert_nat64_def q 0 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8)))
=
()
*)
#reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10"
let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) =
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert(i < 4 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4))) i))
(fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2");
assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4))
#reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1"
let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 2 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
assert (n == 0 \/ n == 1 \/ n == 2);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1);
assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100);
assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000);
()
let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 4 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else
assert (n == 3 \/ n == 4);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000);
assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000);
()
let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in
assert_norm (f 0);
assert_norm (f 1);
assert_norm (f 2);
assert_norm (f 3);
assert_norm (f 4);
()
let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma
(requires n <= 2)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 2);
assert_norm (f 1);
assert_norm (f 0);
()
let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
if n <= 2 then lemma_mod_n_8_lower2_helper q n else
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 4);
assert_norm (f 3);
()
let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n
let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n)))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
q': Vale.Def.Types_s.quad32 ->
lo: Vale.Def.Types_s.nat64 ->
lo': Vale.Def.Types_s.nat64 ->
n: Prims.nat
-> FStar.Pervasives.Lemma
(requires
n <= 4 /\ lo' == lo % Prims.pow2 (8 * n) /\
Vale.Def.Words.Four_s.four_to_two_two q' ==
Vale.Def.Words_s.Mktwo (Vale.Def.Words.Two_s.nat_to_two 32 lo')
(Vale.Def.Words.Two_s.nat_to_two 32 0))
(ensures
lo' < 0x100000000 /\ lo' == Mkfour?.lo0 q' /\
q' == Vale.Def.Words_s.Mkfour (Mkfour?.lo0 q') 0 0 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.nat64",
"Prims.nat",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Vale.Def.Words_s.two",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Two_s.nat_to_two",
"Vale.Def.Words.Two_s.nat_to_two_unfold",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Modulus",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words.Four_s.four_to_two_two",
"Vale.Def.Words_s.Mktwo",
"Prims.squash",
"Prims.op_LessThan",
"Prims.l_or",
"Vale.Def.Words_s.pow2_64",
"Vale.Def.Words_s.pow2_32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.Mkfour",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_64_32_lo1 (q': quad32) (lo lo': nat64) (n: nat)
: Lemma
(requires
n <= 4 /\ lo' == lo % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0))
(ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0) =
| assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
() | false |
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.lemma_mod_n_8_upper1 | val lemma_mod_n_8_upper1 (q: quad32) (n: nat)
: Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n)) | val lemma_mod_n_8_upper1 (q: quad32) (n: nat)
: Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n)) | let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 326,
"start_col": 0,
"start_line": 319
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
)
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
()
(*
let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 16)
(ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes)))
=
()
let insert_0_is_padding (q:quad32) :
Lemma (let q' = insert_nat64_def q 0 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8)))
=
()
*)
#reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10"
let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) =
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert(i < 4 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4))) i))
(fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2");
assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4))
#reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1"
let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 2 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
assert (n == 0 \/ n == 1 \/ n == 2);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1);
assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100);
assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000);
()
let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 4 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else
assert (n == 3 \/ n == 4);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000);
assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000);
()
let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in
assert_norm (f 0);
assert_norm (f 1);
assert_norm (f 2);
assert_norm (f 3);
assert_norm (f 4);
()
let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma
(requires n <= 2)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 2);
assert_norm (f 1);
assert_norm (f 0);
()
let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
if n <= 2 then lemma_mod_n_8_lower2_helper q n else
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 4);
assert_norm (f 3);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32 -> n: Prims.nat
-> FStar.Pervasives.Lemma (requires n <= 4)
(ensures Vale.Arch.Types.hi64 q % Prims.pow2 (8 * n) == Mkfour?.hi2 q % Prims.pow2 (8 * n)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.nat",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCM_helpers.lemma_mod_n_8_lower1",
"Vale.Def.Words_s.Mkfour",
"Prims.unit",
"Vale.Arch.Types.lo64_reveal",
"Vale.Arch.Types.hi64_reveal",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Vale.Arch.Types.hi64",
"Prims.pow2",
"FStar.Mul.op_Star",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_mod_n_8_upper1 (q: quad32) (n: nat)
: Lemma (requires n <= 4) (ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n)) =
| hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n | false |
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.lemma_mod_n_8_upper2 | val lemma_mod_n_8_upper2 (q: quad32) (n: nat)
: Lemma (requires n <= 4)
(ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n))) | val lemma_mod_n_8_upper2 (q: quad32) (n: nat)
: Lemma (requires n <= 4)
(ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n))) | let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n)))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 335,
"start_col": 0,
"start_line": 328
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
)
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
()
(*
let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 16)
(ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes)))
=
()
let insert_0_is_padding (q:quad32) :
Lemma (let q' = insert_nat64_def q 0 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8)))
=
()
*)
#reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10"
let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) =
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert(i < 4 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4))) i))
(fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2");
assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4))
#reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1"
let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 2 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
assert (n == 0 \/ n == 1 \/ n == 2);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1);
assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100);
assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000);
()
let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 4 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else
assert (n == 3 \/ n == 4);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000);
assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000);
()
let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in
assert_norm (f 0);
assert_norm (f 1);
assert_norm (f 2);
assert_norm (f 3);
assert_norm (f 4);
()
let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma
(requires n <= 2)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 2);
assert_norm (f 1);
assert_norm (f 0);
()
let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
if n <= 2 then lemma_mod_n_8_lower2_helper q n else
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 4);
assert_norm (f 3);
()
let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32 -> n: Prims.nat
-> FStar.Pervasives.Lemma (requires n <= 4)
(ensures
Vale.Arch.Types.hi64 q % Prims.pow2 (8 * (4 + n)) ==
Mkfour?.hi2 q + 0x100000000 * (Mkfour?.hi3 q % Prims.pow2 (8 * n))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.nat",
"Vale.Def.Types_s.nat32",
"Vale.AES.GCM_helpers.lemma_mod_n_8_lower2",
"Vale.Def.Words_s.Mkfour",
"Prims.unit",
"Vale.Arch.Types.lo64_reveal",
"Vale.Arch.Types.hi64_reveal",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Vale.Arch.Types.hi64",
"Prims.pow2",
"FStar.Mul.op_Star",
"Prims.op_Addition",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_mod_n_8_upper2 (q: quad32) (n: nat)
: Lemma (requires n <= 4)
(ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n))) =
| hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n | false |
GenericStability.fst | GenericStability.filter_eq_contains | val filter_eq_contains: #a:eqtype -> (k:int) -> (xs: list a) -> key:(a -> Tot int) ->
Lemma (ensures (forall x. (mem x xs /\ key x = k) <==> mem x (filter_eq k xs key))) | val filter_eq_contains: #a:eqtype -> (k:int) -> (xs: list a) -> key:(a -> Tot int) ->
Lemma (ensures (forall x. (mem x xs /\ key x = k) <==> mem x (filter_eq k xs key))) | let rec filter_eq_contains #a k xs key =
match xs with
| [] -> ()
| hd::tl ->
filter_eq_contains k tl key | {
"file_name": "examples/algorithms/GenericStability.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 31,
"end_line": 49,
"start_col": 0,
"start_line": 45
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
@summary: This module defines sorting stability on generic lists.
@author: A Manning
**)
module GenericStability
open FStar.List.Tot
open FStar.List.Tot
open GenericSort
(*
This module is heavily inspired by Leino and Lucio's 2012 paper,
'An Assertional Proof of the Stability and Correctness of Natural Mergesort'.
http://research.microsoft.com/en-us/um/people/leino/papers/krml241.pdf
*)
(**
filterEq returns the elements of a list that have the same key as n.
**)
val filter_eq: #a:Type -> (x:int) -> (xs: list a) -> k:(a -> Tot int) -> Tot (list a)
let rec filter_eq #a x xs k =
match xs with
| [] -> []
| hd::tl
-> if k hd = x then
hd::(filter_eq x tl k)
else filter_eq x tl k
val filter_eq_contains: #a:eqtype -> (k:int) -> (xs: list a) -> key:(a -> Tot int) -> | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"GenericSort.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "GenericStability.fst"
} | [
{
"abbrev": false,
"full_module": "GenericSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "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 | k: Prims.int -> xs: Prims.list a -> key: (_: a -> Prims.int)
-> FStar.Pervasives.Lemma
(ensures
forall (x: a).
FStar.List.Tot.Base.mem x xs /\ key x = k <==>
FStar.List.Tot.Base.mem x (GenericStability.filter_eq k xs key)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"Prims.int",
"Prims.list",
"GenericStability.filter_eq_contains",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec filter_eq_contains #a k xs key =
| match xs with
| [] -> ()
| hd :: tl -> filter_eq_contains k tl key | false |
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.lemma_four_zero | val lemma_four_zero: unit -> Lemma (ensures four_to_nat 8 (seq_to_four_LE (create 4 0)) == 0) | val lemma_four_zero: unit -> Lemma (ensures four_to_nat 8 (seq_to_four_LE (create 4 0)) == 0) | let lemma_four_zero (_:unit) : Lemma
(ensures four_to_nat 8 (seq_to_four_LE (create 4 0)) == 0)
=
let s = create 4 0 in
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 421,
"start_col": 0,
"start_line": 416
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
)
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
()
(*
let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 16)
(ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes)))
=
()
let insert_0_is_padding (q:quad32) :
Lemma (let q' = insert_nat64_def q 0 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8)))
=
()
*)
#reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10"
let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) =
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert(i < 4 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4))) i))
(fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2");
assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4))
#reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1"
let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 2 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
assert (n == 0 \/ n == 1 \/ n == 2);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1);
assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100);
assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000);
()
let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 4 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else
assert (n == 3 \/ n == 4);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000);
assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000);
()
let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in
assert_norm (f 0);
assert_norm (f 1);
assert_norm (f 2);
assert_norm (f 3);
assert_norm (f 4);
()
let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma
(requires n <= 2)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 2);
assert_norm (f 1);
assert_norm (f 0);
()
let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
if n <= 2 then lemma_mod_n_8_lower2_helper q n else
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 4);
assert_norm (f 3);
()
let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n
let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n)))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n
let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
lo' == lo % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)
)
(ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0)
=
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
()
let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
lo' == lo % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)
)
(ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0)
=
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (pow2 (5 * 8) == 0x10000000000);
assert_norm (pow2 (6 * 8) == 0x1000000000000);
assert_norm (pow2 (7 * 8) == 0x100000000000000);
assert_norm (pow2 (8 * 8) == 0x10000000000000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
()
let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
hi' == hi % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')
)
(ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0)
=
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi');
()
let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
hi' == hi % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')
)
(ensures hi' == q'.hi2 + 0x100000000 * q'.hi3)
=
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (pow2 (5 * 8) == 0x10000000000);
assert_norm (pow2 (6 * 8) == 0x1000000000000);
assert_norm (pow2 (7 * 8) == 0x100000000000000);
assert_norm (pow2 (8 * 8) == 0x10000000000000000);
assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi');
()
let lemma_slices_le_bytes_to_quad32 (s:seq16 nat8) : Lemma
(ensures (
let q = le_bytes_to_quad32 s in
q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\
q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\
q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\
q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16))
))
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
le_bytes_to_quad32_reveal ();
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Words.Four_s.four_to_nat 8
(Vale.Def.Words.Seq_s.seq_to_four_LE (FStar.Seq.Base.create 4 0)) ==
0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"FStar.Mul.op_Star",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words.Seq_s.seq_to_four_LE",
"Vale.Def.Words.Four_s.four_to_nat_unfold",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.create",
"Prims.l_True",
"Prims.squash",
"Prims.int",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_four_zero (_: unit) : Lemma (ensures four_to_nat 8 (seq_to_four_LE (create 4 0)) == 0) =
| let s = create 4 0 in
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
() | false |
GenericStability.fst | GenericStability.filter_eq | val filter_eq: #a:Type -> (x:int) -> (xs: list a) -> k:(a -> Tot int) -> Tot (list a) | val filter_eq: #a:Type -> (x:int) -> (xs: list a) -> k:(a -> Tot int) -> Tot (list a) | let rec filter_eq #a x xs k =
match xs with
| [] -> []
| hd::tl
-> if k hd = x then
hd::(filter_eq x tl k)
else filter_eq x tl k | {
"file_name": "examples/algorithms/GenericStability.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 41,
"start_col": 0,
"start_line": 35
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
@summary: This module defines sorting stability on generic lists.
@author: A Manning
**)
module GenericStability
open FStar.List.Tot
open FStar.List.Tot
open GenericSort
(*
This module is heavily inspired by Leino and Lucio's 2012 paper,
'An Assertional Proof of the Stability and Correctness of Natural Mergesort'.
http://research.microsoft.com/en-us/um/people/leino/papers/krml241.pdf
*)
(**
filterEq returns the elements of a list that have the same key as n.
**) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"GenericSort.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "GenericStability.fst"
} | [
{
"abbrev": false,
"full_module": "GenericSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.int -> xs: Prims.list a -> k: (_: a -> Prims.int) -> Prims.list a | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Prims.list",
"Prims.Nil",
"Prims.op_Equality",
"Prims.Cons",
"GenericStability.filter_eq",
"Prims.bool"
] | [
"recursion"
] | false | false | false | true | false | let rec filter_eq #a x xs k =
| match xs with
| [] -> []
| hd :: tl -> if k hd = x then hd :: (filter_eq x tl k) else filter_eq x tl k | false |
GenericStability.fst | GenericStability.filter_eq_sorted_lt | val filter_eq_sorted_lt: #a:eqtype -> l:list a{Cons? l} -> k:(a -> Tot int) ->
Lemma (requires (sorted l k))
(ensures (forall x. (x < k (hd l)) ==> (filter_eq x l k = []))) | val filter_eq_sorted_lt: #a:eqtype -> l:list a{Cons? l} -> k:(a -> Tot int) ->
Lemma (requires (sorted l k))
(ensures (forall x. (x < k (hd l)) ==> (filter_eq x l k = []))) | let filter_eq_sorted_lt #a l k =
sorted_lt l k;
filter_eq_not_contains l k | {
"file_name": "examples/algorithms/GenericStability.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 78,
"start_col": 0,
"start_line": 76
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
@summary: This module defines sorting stability on generic lists.
@author: A Manning
**)
module GenericStability
open FStar.List.Tot
open FStar.List.Tot
open GenericSort
(*
This module is heavily inspired by Leino and Lucio's 2012 paper,
'An Assertional Proof of the Stability and Correctness of Natural Mergesort'.
http://research.microsoft.com/en-us/um/people/leino/papers/krml241.pdf
*)
(**
filterEq returns the elements of a list that have the same key as n.
**)
val filter_eq: #a:Type -> (x:int) -> (xs: list a) -> k:(a -> Tot int) -> Tot (list a)
let rec filter_eq #a x xs k =
match xs with
| [] -> []
| hd::tl
-> if k hd = x then
hd::(filter_eq x tl k)
else filter_eq x tl k
val filter_eq_contains: #a:eqtype -> (k:int) -> (xs: list a) -> key:(a -> Tot int) ->
Lemma (ensures (forall x. (mem x xs /\ key x = k) <==> mem x (filter_eq k xs key)))
let rec filter_eq_contains #a k xs key =
match xs with
| [] -> ()
| hd::tl ->
filter_eq_contains k tl key
val filter_eq_append: #a:eqtype -> (l1: list a) -> (l2: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l1 k)@(filter_eq x l2 k) = filter_eq x (l1@l2) k))
let rec filter_eq_append #a l1 l2 k =
match l1 with
| [] -> ()
| hd::tl ->
filter_eq_append tl l2 k
val filter_eq_not_contains: #a:eqtype -> (l: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l k) = [] <==> ~(exists e. (mem e l /\ k e = x))))
let rec filter_eq_not_contains #a l k =
match l with
| [] -> ()
| hd::tl ->
filter_eq_not_contains tl k
val filter_eq_single: #a:eqtype ->
(l: list a{Cons? l /\ length l = 1}) ->
k:(a -> Tot int) ->
Lemma (ensures (forall x. (k (hd l) = x ) ==> filter_eq x l k = [hd l]))
let filter_eq_single #a l k = ()
val filter_eq_sorted_lt: #a:eqtype -> l:list a{Cons? l} -> k:(a -> Tot int) ->
Lemma (requires (sorted l k)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"GenericSort.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "GenericStability.fst"
} | [
{
"abbrev": false,
"full_module": "GenericSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "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 | l: Prims.list a {Cons? l} -> k: (_: a -> Prims.int)
-> FStar.Pervasives.Lemma (requires GenericSort.sorted l k)
(ensures
forall (x: Prims.int).
x < k (FStar.List.Tot.Base.hd l) ==> GenericStability.filter_eq x l k = []) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.b2t",
"Prims.uu___is_Cons",
"Prims.int",
"GenericStability.filter_eq_not_contains",
"Prims.unit",
"GenericSort.sorted_lt"
] | [] | true | false | true | false | false | let filter_eq_sorted_lt #a l k =
| sorted_lt l k;
filter_eq_not_contains l k | false |
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.lemma_64_32_hi2 | val lemma_64_32_hi2 (q': quad32) (hi hi': nat64) (n: nat)
: Lemma
(requires
n <= 4 /\ hi' == hi % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi'))
(ensures hi' == q'.hi2 + 0x100000000 * q'.hi3) | val lemma_64_32_hi2 (q': quad32) (hi hi': nat64) (n: nat)
: Lemma
(requires
n <= 4 /\ hi' == hi % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi'))
(ensures hi' == q'.hi2 + 0x100000000 * q'.hi3) | let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
hi' == hi % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')
)
(ensures hi' == q'.hi2 + 0x100000000 * q'.hi3)
=
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (pow2 (5 * 8) == 0x10000000000);
assert_norm (pow2 (6 * 8) == 0x1000000000000);
assert_norm (pow2 (7 * 8) == 0x100000000000000);
assert_norm (pow2 (8 * 8) == 0x10000000000000000);
assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi');
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 401,
"start_col": 0,
"start_line": 387
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
)
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
()
(*
let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 16)
(ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes)))
=
()
let insert_0_is_padding (q:quad32) :
Lemma (let q' = insert_nat64_def q 0 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8)))
=
()
*)
#reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10"
let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) =
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert(i < 4 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4))) i))
(fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2");
assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4))
#reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1"
let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 2 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
assert (n == 0 \/ n == 1 \/ n == 2);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1);
assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100);
assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000);
()
let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 4 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else
assert (n == 3 \/ n == 4);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000);
assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000);
()
let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in
assert_norm (f 0);
assert_norm (f 1);
assert_norm (f 2);
assert_norm (f 3);
assert_norm (f 4);
()
let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma
(requires n <= 2)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 2);
assert_norm (f 1);
assert_norm (f 0);
()
let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
if n <= 2 then lemma_mod_n_8_lower2_helper q n else
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 4);
assert_norm (f 3);
()
let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n
let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n)))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n
let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
lo' == lo % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)
)
(ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0)
=
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
()
let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
lo' == lo % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)
)
(ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0)
=
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (pow2 (5 * 8) == 0x10000000000);
assert_norm (pow2 (6 * 8) == 0x1000000000000);
assert_norm (pow2 (7 * 8) == 0x100000000000000);
assert_norm (pow2 (8 * 8) == 0x10000000000000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
()
let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
hi' == hi % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')
)
(ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0)
=
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi');
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
q': Vale.Def.Types_s.quad32 ->
hi: Vale.Def.Types_s.nat64 ->
hi': Vale.Def.Types_s.nat64 ->
n: Prims.nat
-> FStar.Pervasives.Lemma
(requires
n <= 4 /\ hi' == hi % Prims.pow2 (8 * (n + 4)) /\
Vale.Def.Words.Four_s.four_to_two_two q' ==
Vale.Def.Words_s.Mktwo (Vale.Def.Words_s.Mktwo (Mkfour?.lo0 q') (Mkfour?.lo1 q'))
(Vale.Def.Words.Two_s.nat_to_two 32 hi'))
(ensures hi' == Mkfour?.hi2 q' + 0x100000000 * Mkfour?.hi3 q') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.nat64",
"Prims.nat",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Vale.Def.Words_s.two",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Two_s.nat_to_two",
"Vale.Def.Words.Two_s.nat_to_two_unfold",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Modulus",
"Prims.op_Addition",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words.Four_s.four_to_two_two",
"Vale.Def.Words_s.Mktwo",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Prims.squash",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_64_32_hi2 (q': quad32) (hi hi': nat64) (n: nat)
: Lemma
(requires
n <= 4 /\ hi' == hi % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi'))
(ensures hi' == q'.hi2 + 0x100000000 * q'.hi3) =
| assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (pow2 (5 * 8) == 0x10000000000);
assert_norm (pow2 (6 * 8) == 0x1000000000000);
assert_norm (pow2 (7 * 8) == 0x100000000000000);
assert_norm (pow2 (8 * 8) == 0x10000000000000000);
assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi');
() | false |
GenericStability.fst | GenericStability.stable_append_r | val stable_append_r: #a:eqtype ->
(l: list a) ->
(l': list a) ->
(r: list a) ->
k:(a -> Tot int) ->
Lemma (requires (stable l l' k))
(ensures(stable (l@r) (l'@r) k)) | val stable_append_r: #a:eqtype ->
(l: list a) ->
(l': list a) ->
(r: list a) ->
k:(a -> Tot int) ->
Lemma (requires (stable l l' k))
(ensures(stable (l@r) (l'@r) k)) | let rec stable_append_r #a l l' r k =
filter_eq_append l r k;
filter_eq_append l' r k | {
"file_name": "examples/algorithms/GenericStability.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 25,
"end_line": 125,
"start_col": 0,
"start_line": 123
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
@summary: This module defines sorting stability on generic lists.
@author: A Manning
**)
module GenericStability
open FStar.List.Tot
open FStar.List.Tot
open GenericSort
(*
This module is heavily inspired by Leino and Lucio's 2012 paper,
'An Assertional Proof of the Stability and Correctness of Natural Mergesort'.
http://research.microsoft.com/en-us/um/people/leino/papers/krml241.pdf
*)
(**
filterEq returns the elements of a list that have the same key as n.
**)
val filter_eq: #a:Type -> (x:int) -> (xs: list a) -> k:(a -> Tot int) -> Tot (list a)
let rec filter_eq #a x xs k =
match xs with
| [] -> []
| hd::tl
-> if k hd = x then
hd::(filter_eq x tl k)
else filter_eq x tl k
val filter_eq_contains: #a:eqtype -> (k:int) -> (xs: list a) -> key:(a -> Tot int) ->
Lemma (ensures (forall x. (mem x xs /\ key x = k) <==> mem x (filter_eq k xs key)))
let rec filter_eq_contains #a k xs key =
match xs with
| [] -> ()
| hd::tl ->
filter_eq_contains k tl key
val filter_eq_append: #a:eqtype -> (l1: list a) -> (l2: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l1 k)@(filter_eq x l2 k) = filter_eq x (l1@l2) k))
let rec filter_eq_append #a l1 l2 k =
match l1 with
| [] -> ()
| hd::tl ->
filter_eq_append tl l2 k
val filter_eq_not_contains: #a:eqtype -> (l: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l k) = [] <==> ~(exists e. (mem e l /\ k e = x))))
let rec filter_eq_not_contains #a l k =
match l with
| [] -> ()
| hd::tl ->
filter_eq_not_contains tl k
val filter_eq_single: #a:eqtype ->
(l: list a{Cons? l /\ length l = 1}) ->
k:(a -> Tot int) ->
Lemma (ensures (forall x. (k (hd l) = x ) ==> filter_eq x l k = [hd l]))
let filter_eq_single #a l k = ()
val filter_eq_sorted_lt: #a:eqtype -> l:list a{Cons? l} -> k:(a -> Tot int) ->
Lemma (requires (sorted l k))
(ensures (forall x. (x < k (hd l)) ==> (filter_eq x l k = [])))
let filter_eq_sorted_lt #a l k =
sorted_lt l k;
filter_eq_not_contains l k
val filter_eq_first: #a:eqtype ->
(l1: list a{Cons? l1}) ->
(l2: list a{Cons? l2}) ->
k:(a -> Tot int) ->
Lemma (requires (sorted l1 k) /\ (k (hd l1) > k (hd l2)))
(ensures (forall x. (k (hd l2) = x ) ==>
filter_eq x (l1@l2) k = ((filter_eq x ((hd l2)::l1) k )@(filter_eq x (tl l2) k))))
let filter_eq_first #a l1 l2 k =
filter_eq_append l1 l2 k;
filter_eq_sorted_lt l1 k
type stable (#a:eqtype) (l1:list a) (l2:list a) (k:(a -> Tot int)) = forall x. (filter_eq x l1 k = filter_eq x l2 k)
val stable_lift: #a:eqtype ->
(l1: list a{Cons? l1}) ->
(l2: list a{Cons? l2}) ->
k:(a -> Tot int) ->
Lemma (requires (sorted l1 k) /\ (k (hd l1) > k (hd l2)))
(ensures (stable (l1@l2) (((hd l2)::l1)@(tl l2)) k))
let stable_lift #a l1 l2 k =
filter_eq_append l1 l2 k;
filter_eq_append ((hd l2)::l1) (tl l2) k;
filter_eq_first l1 l2 k;
filter_eq_append ((hd l2)::l1) (tl l2) k
val stable_append_l: #a:eqtype ->
(l: list a) ->
(r: list a) ->
(r': list a) ->
k:(a -> Tot int) ->
Lemma (ensures (stable r r' k ==> stable (l@r) (l@r') k))
let rec stable_append_l #a l r r' k =
match l with
| [] -> ()
| hd::tl -> stable_append_l tl r r' k
val stable_append_r: #a:eqtype ->
(l: list a) ->
(l': list a) ->
(r: list a) ->
k:(a -> Tot int) ->
Lemma (requires (stable l l' k)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"GenericSort.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "GenericStability.fst"
} | [
{
"abbrev": false,
"full_module": "GenericSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "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 | l: Prims.list a -> l': Prims.list a -> r: Prims.list a -> k: (_: a -> Prims.int)
-> FStar.Pervasives.Lemma (requires GenericStability.stable l l' k)
(ensures GenericStability.stable (l @ r) (l' @ r) k) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.int",
"GenericStability.filter_eq_append",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec stable_append_r #a l l' r k =
| filter_eq_append l r k;
filter_eq_append l' r k | false |
GenericStability.fst | GenericStability.filter_eq_first | val filter_eq_first: #a:eqtype ->
(l1: list a{Cons? l1}) ->
(l2: list a{Cons? l2}) ->
k:(a -> Tot int) ->
Lemma (requires (sorted l1 k) /\ (k (hd l1) > k (hd l2)))
(ensures (forall x. (k (hd l2) = x ) ==>
filter_eq x (l1@l2) k = ((filter_eq x ((hd l2)::l1) k )@(filter_eq x (tl l2) k)))) | val filter_eq_first: #a:eqtype ->
(l1: list a{Cons? l1}) ->
(l2: list a{Cons? l2}) ->
k:(a -> Tot int) ->
Lemma (requires (sorted l1 k) /\ (k (hd l1) > k (hd l2)))
(ensures (forall x. (k (hd l2) = x ) ==>
filter_eq x (l1@l2) k = ((filter_eq x ((hd l2)::l1) k )@(filter_eq x (tl l2) k)))) | let filter_eq_first #a l1 l2 k =
filter_eq_append l1 l2 k;
filter_eq_sorted_lt l1 k | {
"file_name": "examples/algorithms/GenericStability.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 26,
"end_line": 89,
"start_col": 0,
"start_line": 87
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
@summary: This module defines sorting stability on generic lists.
@author: A Manning
**)
module GenericStability
open FStar.List.Tot
open FStar.List.Tot
open GenericSort
(*
This module is heavily inspired by Leino and Lucio's 2012 paper,
'An Assertional Proof of the Stability and Correctness of Natural Mergesort'.
http://research.microsoft.com/en-us/um/people/leino/papers/krml241.pdf
*)
(**
filterEq returns the elements of a list that have the same key as n.
**)
val filter_eq: #a:Type -> (x:int) -> (xs: list a) -> k:(a -> Tot int) -> Tot (list a)
let rec filter_eq #a x xs k =
match xs with
| [] -> []
| hd::tl
-> if k hd = x then
hd::(filter_eq x tl k)
else filter_eq x tl k
val filter_eq_contains: #a:eqtype -> (k:int) -> (xs: list a) -> key:(a -> Tot int) ->
Lemma (ensures (forall x. (mem x xs /\ key x = k) <==> mem x (filter_eq k xs key)))
let rec filter_eq_contains #a k xs key =
match xs with
| [] -> ()
| hd::tl ->
filter_eq_contains k tl key
val filter_eq_append: #a:eqtype -> (l1: list a) -> (l2: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l1 k)@(filter_eq x l2 k) = filter_eq x (l1@l2) k))
let rec filter_eq_append #a l1 l2 k =
match l1 with
| [] -> ()
| hd::tl ->
filter_eq_append tl l2 k
val filter_eq_not_contains: #a:eqtype -> (l: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l k) = [] <==> ~(exists e. (mem e l /\ k e = x))))
let rec filter_eq_not_contains #a l k =
match l with
| [] -> ()
| hd::tl ->
filter_eq_not_contains tl k
val filter_eq_single: #a:eqtype ->
(l: list a{Cons? l /\ length l = 1}) ->
k:(a -> Tot int) ->
Lemma (ensures (forall x. (k (hd l) = x ) ==> filter_eq x l k = [hd l]))
let filter_eq_single #a l k = ()
val filter_eq_sorted_lt: #a:eqtype -> l:list a{Cons? l} -> k:(a -> Tot int) ->
Lemma (requires (sorted l k))
(ensures (forall x. (x < k (hd l)) ==> (filter_eq x l k = [])))
let filter_eq_sorted_lt #a l k =
sorted_lt l k;
filter_eq_not_contains l k
val filter_eq_first: #a:eqtype ->
(l1: list a{Cons? l1}) ->
(l2: list a{Cons? l2}) ->
k:(a -> Tot int) ->
Lemma (requires (sorted l1 k) /\ (k (hd l1) > k (hd l2)))
(ensures (forall x. (k (hd l2) = x ) ==> | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"GenericSort.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "GenericStability.fst"
} | [
{
"abbrev": false,
"full_module": "GenericSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "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 | l1: Prims.list a {Cons? l1} -> l2: Prims.list a {Cons? l2} -> k: (_: a -> Prims.int)
-> FStar.Pervasives.Lemma
(requires
GenericSort.sorted l1 k /\ k (FStar.List.Tot.Base.hd l1) > k (FStar.List.Tot.Base.hd l2))
(ensures
forall (x: Prims.int).
k (FStar.List.Tot.Base.hd l2) = x ==>
GenericStability.filter_eq x (l1 @ l2) k =
GenericStability.filter_eq x (FStar.List.Tot.Base.hd l2 :: l1) k @
GenericStability.filter_eq x (FStar.List.Tot.Base.tl l2) k) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.b2t",
"Prims.uu___is_Cons",
"Prims.int",
"GenericStability.filter_eq_sorted_lt",
"Prims.unit",
"GenericStability.filter_eq_append"
] | [] | true | false | true | false | false | let filter_eq_first #a l1 l2 k =
| filter_eq_append l1 l2 k;
filter_eq_sorted_lt l1 k | false |
GenericStability.fst | GenericStability.stable_append_l | val stable_append_l: #a:eqtype ->
(l: list a) ->
(r: list a) ->
(r': list a) ->
k:(a -> Tot int) ->
Lemma (ensures (stable r r' k ==> stable (l@r) (l@r') k)) | val stable_append_l: #a:eqtype ->
(l: list a) ->
(r: list a) ->
(r': list a) ->
k:(a -> Tot int) ->
Lemma (ensures (stable r r' k ==> stable (l@r) (l@r') k)) | let rec stable_append_l #a l r r' k =
match l with
| [] -> ()
| hd::tl -> stable_append_l tl r r' k | {
"file_name": "examples/algorithms/GenericStability.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 114,
"start_col": 0,
"start_line": 111
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
@summary: This module defines sorting stability on generic lists.
@author: A Manning
**)
module GenericStability
open FStar.List.Tot
open FStar.List.Tot
open GenericSort
(*
This module is heavily inspired by Leino and Lucio's 2012 paper,
'An Assertional Proof of the Stability and Correctness of Natural Mergesort'.
http://research.microsoft.com/en-us/um/people/leino/papers/krml241.pdf
*)
(**
filterEq returns the elements of a list that have the same key as n.
**)
val filter_eq: #a:Type -> (x:int) -> (xs: list a) -> k:(a -> Tot int) -> Tot (list a)
let rec filter_eq #a x xs k =
match xs with
| [] -> []
| hd::tl
-> if k hd = x then
hd::(filter_eq x tl k)
else filter_eq x tl k
val filter_eq_contains: #a:eqtype -> (k:int) -> (xs: list a) -> key:(a -> Tot int) ->
Lemma (ensures (forall x. (mem x xs /\ key x = k) <==> mem x (filter_eq k xs key)))
let rec filter_eq_contains #a k xs key =
match xs with
| [] -> ()
| hd::tl ->
filter_eq_contains k tl key
val filter_eq_append: #a:eqtype -> (l1: list a) -> (l2: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l1 k)@(filter_eq x l2 k) = filter_eq x (l1@l2) k))
let rec filter_eq_append #a l1 l2 k =
match l1 with
| [] -> ()
| hd::tl ->
filter_eq_append tl l2 k
val filter_eq_not_contains: #a:eqtype -> (l: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l k) = [] <==> ~(exists e. (mem e l /\ k e = x))))
let rec filter_eq_not_contains #a l k =
match l with
| [] -> ()
| hd::tl ->
filter_eq_not_contains tl k
val filter_eq_single: #a:eqtype ->
(l: list a{Cons? l /\ length l = 1}) ->
k:(a -> Tot int) ->
Lemma (ensures (forall x. (k (hd l) = x ) ==> filter_eq x l k = [hd l]))
let filter_eq_single #a l k = ()
val filter_eq_sorted_lt: #a:eqtype -> l:list a{Cons? l} -> k:(a -> Tot int) ->
Lemma (requires (sorted l k))
(ensures (forall x. (x < k (hd l)) ==> (filter_eq x l k = [])))
let filter_eq_sorted_lt #a l k =
sorted_lt l k;
filter_eq_not_contains l k
val filter_eq_first: #a:eqtype ->
(l1: list a{Cons? l1}) ->
(l2: list a{Cons? l2}) ->
k:(a -> Tot int) ->
Lemma (requires (sorted l1 k) /\ (k (hd l1) > k (hd l2)))
(ensures (forall x. (k (hd l2) = x ) ==>
filter_eq x (l1@l2) k = ((filter_eq x ((hd l2)::l1) k )@(filter_eq x (tl l2) k))))
let filter_eq_first #a l1 l2 k =
filter_eq_append l1 l2 k;
filter_eq_sorted_lt l1 k
type stable (#a:eqtype) (l1:list a) (l2:list a) (k:(a -> Tot int)) = forall x. (filter_eq x l1 k = filter_eq x l2 k)
val stable_lift: #a:eqtype ->
(l1: list a{Cons? l1}) ->
(l2: list a{Cons? l2}) ->
k:(a -> Tot int) ->
Lemma (requires (sorted l1 k) /\ (k (hd l1) > k (hd l2)))
(ensures (stable (l1@l2) (((hd l2)::l1)@(tl l2)) k))
let stable_lift #a l1 l2 k =
filter_eq_append l1 l2 k;
filter_eq_append ((hd l2)::l1) (tl l2) k;
filter_eq_first l1 l2 k;
filter_eq_append ((hd l2)::l1) (tl l2) k
val stable_append_l: #a:eqtype ->
(l: list a) ->
(r: list a) ->
(r': list a) ->
k:(a -> Tot int) -> | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"GenericSort.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "GenericStability.fst"
} | [
{
"abbrev": false,
"full_module": "GenericSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "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 | l: Prims.list a -> r: Prims.list a -> r': Prims.list a -> k: (_: a -> Prims.int)
-> FStar.Pervasives.Lemma
(ensures GenericStability.stable r r' k ==> GenericStability.stable (l @ r) (l @ r') k) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.int",
"GenericStability.stable_append_l",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec stable_append_l #a l r r' k =
| match l with
| [] -> ()
| hd :: tl -> stable_append_l tl r r' k | false |
GenericStability.fst | GenericStability.filter_eq_not_contains | val filter_eq_not_contains: #a:eqtype -> (l: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l k) = [] <==> ~(exists e. (mem e l /\ k e = x)))) | val filter_eq_not_contains: #a:eqtype -> (l: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l k) = [] <==> ~(exists e. (mem e l /\ k e = x)))) | let rec filter_eq_not_contains #a l k =
match l with
| [] -> ()
| hd::tl ->
filter_eq_not_contains tl k | {
"file_name": "examples/algorithms/GenericStability.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 31,
"end_line": 65,
"start_col": 0,
"start_line": 61
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
@summary: This module defines sorting stability on generic lists.
@author: A Manning
**)
module GenericStability
open FStar.List.Tot
open FStar.List.Tot
open GenericSort
(*
This module is heavily inspired by Leino and Lucio's 2012 paper,
'An Assertional Proof of the Stability and Correctness of Natural Mergesort'.
http://research.microsoft.com/en-us/um/people/leino/papers/krml241.pdf
*)
(**
filterEq returns the elements of a list that have the same key as n.
**)
val filter_eq: #a:Type -> (x:int) -> (xs: list a) -> k:(a -> Tot int) -> Tot (list a)
let rec filter_eq #a x xs k =
match xs with
| [] -> []
| hd::tl
-> if k hd = x then
hd::(filter_eq x tl k)
else filter_eq x tl k
val filter_eq_contains: #a:eqtype -> (k:int) -> (xs: list a) -> key:(a -> Tot int) ->
Lemma (ensures (forall x. (mem x xs /\ key x = k) <==> mem x (filter_eq k xs key)))
let rec filter_eq_contains #a k xs key =
match xs with
| [] -> ()
| hd::tl ->
filter_eq_contains k tl key
val filter_eq_append: #a:eqtype -> (l1: list a) -> (l2: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l1 k)@(filter_eq x l2 k) = filter_eq x (l1@l2) k))
let rec filter_eq_append #a l1 l2 k =
match l1 with
| [] -> ()
| hd::tl ->
filter_eq_append tl l2 k
val filter_eq_not_contains: #a:eqtype -> (l: list a) -> k:(a -> Tot int) -> | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"GenericSort.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "GenericStability.fst"
} | [
{
"abbrev": false,
"full_module": "GenericSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "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 | l: Prims.list a -> k: (_: a -> Prims.int)
-> FStar.Pervasives.Lemma
(ensures
forall (x: Prims.int).
GenericStability.filter_eq x l k = [] <==>
~(exists (e: a). FStar.List.Tot.Base.mem e l /\ k e = x)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.int",
"GenericStability.filter_eq_not_contains",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec filter_eq_not_contains #a l k =
| match l with
| [] -> ()
| hd :: tl -> filter_eq_not_contains tl k | false |
LowParse.Low.Base.fst | LowParse.Low.Base.list_filter | val list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f':
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t -> x: Ghost.erased t
-> HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos': U32.t)
(#rrel_out #rel_out: _)
(sl_out: slice rrel_out rel_out)
(pos_out: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\ valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos')
(loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out))
(ensures
(fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
)) | val list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f':
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t -> x: Ghost.erased t
-> HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos': U32.t)
(#rrel_out #rel_out: _)
(sl_out: slice rrel_out rel_out)
(pos_out: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\ valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos')
(loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out))
(ensures
(fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
)) | let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f' : (
(#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
(x: Ghost.erased t) ->
HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))
))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos' : U32.t)
(#rrel_out #rel_out: _)
(sl_out : slice rrel_out rel_out)
(pos_out : U32.t)
: HST.Stack U32.t
(requires (fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\
valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos') (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out
))
(ensures (fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
//B.fresh_frame_modifies h0 h1;
let bpos_out' : BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\ (
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos // necessary to prove that length computations do not overflow
)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))
inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in (B.loc_buffer bpos_out' `B.loc_union` loc_slice_from_to sl_out pos_out pos_out') h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then begin
assert (B.loc_includes (loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) (loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (U32.v pos_out1) (U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h (B.loc_region_only true (HS.get_tip h1)) h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2
end else
L.append_l_nil (L.filter f (G.reveal l1))
)
;
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out' | {
"file_name": "src/lowparse/LowParse.Low.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 10,
"end_line": 1501,
"start_col": 0,
"start_line": 1413
} | module LowParse.Low.Base
include LowParse.Low.Base.Spec
include LowParse.Low.ErrorCode
module M = LowParse.Math
module B = LowStar.Monotonic.Buffer
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module Seq = FStar.Seq
module Cast = FStar.Int.Cast
module L = FStar.List.Tot
[@unifier_hint_injective]
inline_for_extraction
let accessor
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(g: gaccessor p1 p2 cl)
: Tot Type
= (#rrel: _) ->
(#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
valid p1 h sl pos /\
cl.clens_cond (contents p1 h sl pos)
))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
pos' == slice_access h g sl pos
))
#push-options "--z3rlimit 16"
inline_for_extraction
let make_accessor_from_pure
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
($g: gaccessor p1 p2 cl)
(f: (
(input: Ghost.erased bytes) ->
Pure U32.t
(requires (Seq.length (Ghost.reveal input) < 4294967296 /\ gaccessor_pre p1 p2 cl (Ghost.reveal input)))
(ensures (fun y -> U32.v y == (g (Ghost.reveal input))))
))
: Tot (accessor g)
= fun #rrel #rel sl (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ =
slice_access_eq h g sl pos
in
pos `U32.add` f (Ghost.hide (bytes_of_slice_from h sl pos))
inline_for_extraction
let accessor_id
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot (accessor (gaccessor_id p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_id p) input pos in
[@inline_let] let _ = gaccessor_id_eq p (bytes_of_slice_from h input pos) in
pos
#pop-options
inline_for_extraction
let accessor_ext
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t1 t2)
(#g: gaccessor p1 p2 cl)
(a: accessor g)
(cl': clens t1 t2)
(sq: squash (clens_eq cl cl'))
: Tot (accessor (gaccessor_ext g cl' sq))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
slice_access_eq h (gaccessor_ext g cl' sq) input pos;
slice_access_eq h g input pos;
gaccessor_ext_eq g cl' sq (bytes_of_slice_from h input pos)
in
a input pos
#push-options "--z3rlimit 128" // necessary for the .fst
#restart-solver // necessary for the .fst
inline_for_extraction
let accessor_compose
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23)
(sq: unit) // squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
let pos2 = a12' input pos in
let pos3 = a23' input pos2 in
slice_access_eq h a12 input pos;
slice_access_eq h a23 input pos2;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
gaccessor_compose_eq a12 a23 (bytes_of_slice_from h input pos);
pos3
#pop-options
(*
inline_for_extraction
let accessor_compose_strong
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl12: clens t1 t2)
(#a12: gaccessor p1 p2 cl12)
(a12' : accessor a12)
(#k3: parser_kind)
(#t3: Type)
(#p3: parser k3 t3)
(#cl23: clens t2 t3)
(#a23: gaccessor p2 p3 cl23)
(a23' : accessor a23 { clens_compose_strong_pre cl12 cl23 } )
(sq: squash (k2.parser_kind_subkind == Some ParserStrong))
: Tot (accessor (gaccessor_compose_strong a12 a23))
= fun #rrel #rel input pos ->
let h = HST.get () in
slice_access_eq h (gaccessor_compose_strong a12 a23) input pos;
slice_access_eq h (gaccessor_compose a12 a23) input pos;
accessor_compose a12' a23' () input pos
*)
(* Validators *)
[@unifier_hint_injective]
inline_for_extraction
let validator (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
[@unifier_hint_injective]
inline_for_extraction
let validator_no_read (#k: parser_kind) (#t: Type) (p: parser k t) : Tot Type =
(#rrel: _) -> (#rel: _) ->
(sl: Ghost.erased (slice rrel rel)) ->
(len: U32.t { len == (Ghost.reveal sl).len }) ->
(pos: U64.t) ->
HST.Stack U64.t
(requires (fun h -> live_slice h sl /\ U64.v pos <= U32.v sl.len))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
if is_success res
then
valid_pos p h sl (uint64_to_uint32 pos) (uint64_to_uint32 res)
else
(~ (valid p h sl (uint64_to_uint32 pos)))
)))
inline_for_extraction
let validate_no_read
(#k: parser_kind) (#t: Type) (#p: parser k t)
(v: validator_no_read p)
: Tot (validator p)
= fun #rrel #rel sl pos -> v (Ghost.hide sl) sl.len pos
noextract
inline_for_extraction
let comment (s: string) : HST.Stack unit
(requires (fun _ -> True))
(ensures (fun h _ h' -> h == h'))
= LowStar.Comment.comment s
noextract
inline_for_extraction
let validate_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
: Tot (validator p)
= fun #rrel #rel sl pos ->
comment s;
v sl pos
inline_for_extraction
let validate_with_error_code
(#k: parser_kind) (#t: Type) (#p: parser k t) (v: validator p) (c: error_code)
: Tot (validator p)
= fun #rrel #rel sl pos ->
let res = v sl pos in
maybe_set_error_code res pos c
inline_for_extraction
let validate
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v: validator p)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(len: U32.t)
: HST.Stack bool
(requires (fun h ->
B.live h b /\
U32.v len <= B.length b
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\ (
let sl = make_slice b len in
(res == true <==> (is_success (Cast.uint32_to_uint64 len) /\ valid p h sl 0ul))
)))
= if is_error (Cast.uint32_to_uint64 len)
then false
else
[@inline_let]
let sl = make_slice b len in
is_success (v sl 0uL)
let valid_total_constant_size
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: nat)
(#rrel #rel: _)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (
(valid p h input pos <==> (live_slice h input /\ U32.v input.len - U32.v pos >= k.parser_kind_low)) /\
(valid p h input pos ==> content_length p h input pos == k.parser_kind_low)
))
= parser_kind_prop_equiv k p;
valid_facts p h input pos
inline_for_extraction
let validate_total_constant_size_no_read
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator_no_read p)
= fun #rrel #rel (input: Ghost.erased (slice rrel rel)) len pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 len `U64.sub` pos) sz
then validator_error_not_enough_data
else
(pos `U64.add` sz)
inline_for_extraction
let validate_total_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= validate_no_read (validate_total_constant_size_no_read p sz u)
inline_for_extraction
let validate_total_constant_size_with_error_code
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U64.t)
(c: error_code {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U64.v sz /\
k.parser_kind_metadata == Some ParserKindMetadataTotal
})
: Tot (validator p)
= fun #rrel #rel (input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_total_constant_size h p (U64.v sz) input (uint64_to_uint32 pos) in
if U64.lt (Cast.uint32_to_uint64 input.len `U64.sub` pos) sz
then set_validator_error_pos_and_code validator_error_not_enough_data pos c
else
(pos `U64.add` sz)
let valid_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(p2: parser k2 t)
(h: HS.mem)
#rrel #rel
(sl: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (k1 `is_weaker_than` k2))
(ensures (
(valid (weaken k1 p2) h sl pos \/ valid p2 h sl pos) ==> (
valid p2 h sl pos /\
valid_content_pos (weaken k1 p2) h sl pos (contents p2 h sl pos) (get_valid_pos p2 h sl pos)
)))
= valid_facts (weaken k1 p2) h sl pos;
valid_facts p2 h sl pos
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2 { k1 `is_weaker_than` k2 } )
: Tot (validator (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl (uint64_to_uint32 pos)
in
v2 sl pos
[@unifier_hint_injective]
inline_for_extraction
let jumper
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h -> valid p h sl pos))
(ensures (fun h pos' h' ->
B.modifies B.loc_none h h' /\
U32.v pos + content_length p h sl pos == U32.v pos'
))
inline_for_extraction
let jump_constant_size'
(#k: parser_kind)
(#t: Type)
(p: (unit -> GTot (parser k t)))
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper (p ()))
= fun #rrel #rel (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (p ()) h input pos in
pos `U32.add` sz
inline_for_extraction
let jump_constant_size
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(sz: U32.t)
(u: unit {
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
})
: Tot (jumper p)
= jump_constant_size' (fun _ -> p) sz u
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2 { k1 `is_weaker_than` k2 } )
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_weaken k1 p2 h sl pos
in
v2 sl pos
let seq_starts_with (#t: Type) (slong sshort: Seq.seq t) : GTot Type0 =
Seq.length sshort <= Seq.length slong /\
Seq.slice slong 0 (Seq.length sshort) `Seq.equal` sshort
let seq_starts_with_trans (#t: Type) (s1 s2 s3: Seq.seq t) : Lemma
(requires (s1 `seq_starts_with` s2 /\ s2 `seq_starts_with` s3))
(ensures (s1 `seq_starts_with` s3))
= ()
let seq_starts_with_append_l_intro (#t: Type) (s1 s2: Seq.seq t) : Lemma
((s1 `Seq.append` s2) `seq_starts_with` s1)
= ()
let seq_starts_with_append_r_elim (#t: Type) (s s1 s2: Seq.seq t) : Lemma
(requires (s `seq_starts_with` (s1 `Seq.append` s2)))
(ensures (
s `seq_starts_with` s1 /\
Seq.slice s (Seq.length s1) (Seq.length s) `seq_starts_with` s2
))
[SMTPat (s `seq_starts_with` (s1 `Seq.append` s2))]
= let s3 = Seq.slice s (Seq.length s1 + Seq.length s2) (Seq.length s) in
assert (s `Seq.equal` (s1 `Seq.append` s2 `Seq.append` s3))
inline_for_extraction
noextract
let jump_serializer
(#k: _)
(#t: _)
(#p: parser k t)
(s: serializer p { k.parser_kind_subkind == Some ParserStrong })
(j: jumper p)
(#rrel #rel: _)
(sl: slice rrel rel)
(pos: U32.t)
(x: Ghost.erased t)
: HST.Stack U32.t
(requires (fun h ->
let sq = serialize s (Ghost.reveal x) in
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
bytes_of_slice_from h sl pos `seq_starts_with` sq
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v pos + Seq.length (serialize s (Ghost.reveal x)) == U32.v res
))
= let h = HST.get () in
let gsq = Ghost.hide (serialize s (Ghost.reveal x)) in
let glen = Ghost.hide (Seq.length (Ghost.reveal gsq)) in
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Ghost.reveal glen)) in
assert (bytes_of_slice_from_to h sl pos (Ghost.reveal gpos') == Seq.slice (bytes_of_slice_from h sl pos) 0 (Seq.length (serialize s (Ghost.reveal x))));
serialize_valid_exact s h sl (Ghost.reveal x) pos (Ghost.reveal gpos');
valid_exact_valid p h sl pos (Ghost.reveal gpos');
j sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader
(#k: parser_kind)
(#t: Type)
(p: parser k t)
: Tot Type
= (#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack t
(requires (fun h -> valid p h sl pos))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == contents p h sl pos
))
noextract
inline_for_extraction
let read_with_comment
(s: string)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(r: leaf_reader p)
: Tot (leaf_reader p)
= fun #rrel #rel sl pos ->
comment s;
r sl pos
[@unifier_hint_injective]
inline_for_extraction
let leaf_reader_ext
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(p32: leaf_reader p1)
(#k2: parser_kind)
(p2: parser k2 t)
(lem: (
(x: bytes) ->
Lemma
(parse p2 x == parse p1 x)
))
: Tot (leaf_reader p2)
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts p1 h sl pos;
valid_facts p2 h sl pos;
lem (bytes_of_slice_from h sl pos)
in
p32 sl pos
let writable
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
: GTot Type0
= let s = B.as_seq h b in
B.live h b /\
((pos <= pos' /\ pos' <= B.length b) ==> (
(forall (s1:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s1)}
forall (s2:Seq.lseq t (pos' - pos)) . {:pattern (Seq.replace_subseq s pos pos' s2)}
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2
)))
let writable_intro
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(_: squash (B.live h b /\ pos <= pos' /\ pos' <= B.length b))
(f: (
(s1: Seq.lseq t (pos' - pos)) ->
(s2: Seq.lseq t (pos' - pos)) ->
Lemma
(let s = B.as_seq h b in
Seq.replace_subseq s pos pos' s1 `rel` Seq.replace_subseq s pos pos' s2)
))
: Lemma
(writable b pos pos' h)
= Classical.forall_intro_2 f
#push-options "--z3rlimit 32"
let writable_weaken
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(lpos lpos' : nat)
: Lemma
(requires (writable b pos pos' h /\ pos <= lpos /\ lpos <= lpos' /\ lpos' <= pos' /\ pos' <= B.length b))
(ensures (writable b lpos lpos' h))
= writable_intro b lpos lpos' h () (fun s1 s2 ->
let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
let j1 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s1) in
let j2 = Seq.replace_subseq s pos pos' (Seq.replace_subseq sl (lpos - pos) (lpos' - pos) s2) in
assert (Seq.replace_subseq s lpos lpos' s1 `Seq.equal` j1);
assert (Seq.replace_subseq s lpos lpos' s2 `Seq.equal` j2);
assert (j1 `rel` j2)
)
#pop-options
let writable_replace_subseq_elim
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s'
))
= let s = B.as_seq h b in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl)
let writable_replace_subseq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(sl' : Seq.seq t)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
Seq.length sl' == pos' - pos /\
B.as_seq h' b `Seq.equal` Seq.replace_subseq (B.as_seq h b) pos pos' sl' /\
B.live h' b
))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' h'
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let sl = Seq.slice s pos pos' in
assert (s `Seq.equal` Seq.replace_subseq s pos pos' sl);
assert (s' `Seq.equal` Seq.replace_subseq s pos pos' sl');
writable_intro b pos pos' h' () (fun s1 s2 ->
assert (Seq.replace_subseq s' pos pos' s1 `Seq.equal` Seq.replace_subseq s pos pos' s1);
assert (Seq.replace_subseq s' pos pos' s2 `Seq.equal` Seq.replace_subseq s pos pos' s2)
)
let writable_ext
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\
pos' <= B.length b /\
B.as_seq h' b `Seq.equal` B.as_seq h b /\
B.live h' b
))
(ensures (
writable b pos pos' h'
))
= writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h b) pos pos') h'
let writable_upd_seq
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(sl' : Seq.seq t)
(h: HS.mem)
: Lemma
(requires (writable b pos pos' h /\ pos <= pos' /\ pos' <= B.length b /\ Seq.length sl' == pos' - pos))
(ensures (
let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
s `rel` s' /\
writable b pos pos' (B.g_upd_seq b s' h)
))
= let s = B.as_seq h b in
let s' = Seq.replace_subseq s pos pos' sl' in
let h' = B.g_upd_seq b s' h in
B.g_upd_seq_as_seq b s' h; // for live
writable_replace_subseq b pos pos' h sl' h'
let writable_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(i: nat)
(v: t)
: Lemma
(requires (writable b pos pos' h /\ pos <= i /\ i < pos' /\ pos' <= B.length b))
(ensures (
let s = B.as_seq h b in
s `rel` Seq.upd s i v /\
writable b pos pos' (B.g_upd b i v h)
))
= let s = B.as_seq h b in
let sl' = Seq.upd (Seq.slice s pos pos') (i - pos) v in
writable_upd_seq b pos pos' sl' h;
assert (Seq.upd s i v `Seq.equal` Seq.replace_subseq s pos pos' sl')
let writable_modifies
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : nat)
(h: HS.mem)
(l: B.loc)
(h' : HS.mem)
: Lemma
(requires (
writable b pos pos' h /\
pos <= pos' /\ pos' <= B.length b /\
B.modifies (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h' /\
B.loc_disjoint l (B.loc_buffer b)
))
(ensures (
writable b pos pos' h'
))
= B.modifies_buffer_from_to_elim b 0ul (U32.uint_to_t pos) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
B.modifies_buffer_from_to_elim b (U32.uint_to_t pos') (B.len b) (l `B.loc_union` B.loc_buffer_from_to b (U32.uint_to_t pos) (U32.uint_to_t pos')) h h';
writable_replace_subseq b pos pos' h (Seq.slice (B.as_seq h' b) pos pos') h'
inline_for_extraction
noextract
let mbuffer_upd
(#t: Type)
(#rrel #rel: _)
(b: B.mbuffer t rrel rel)
(pos pos' : Ghost.erased nat)
(i: U32.t)
(v: t)
: HST.Stack unit
(requires (fun h ->
writable b (Ghost.reveal pos) (Ghost.reveal pos') h /\
Ghost.reveal pos <= U32.v i /\
U32.v i + 1 <= Ghost.reveal pos' /\
Ghost.reveal pos' <= B.length b
))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to b i (i `U32.add` 1ul)) h h' /\
writable b (Ghost.reveal pos) (Ghost.reveal pos') h' /\
B.as_seq h' b == Seq.upd (B.as_seq h b) (U32.v i) v
))
= let h = HST.get () in
writable_upd b (Ghost.reveal pos) (Ghost.reveal pos') h (U32.v i) v;
B.g_upd_modifies_strong b (U32.v i) v h;
B.g_upd_seq_as_seq b (Seq.upd (B.as_seq h b) (U32.v i) v) h;
B.upd' b i v
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
live_slice h sl /\
U32.v pos <= U32.v sl.len /\
U32.v sl.len < U32.v max_uint32 /\
writable sl.base (U32.v pos) (U32.v sl.len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from sl pos) h h' /\ (
if pos' = max_uint32
then U32.v pos + serialized_length s x > U32.v sl.len
else valid_content_pos p h' sl pos x pos'
)))
[@unifier_hint_injective]
inline_for_extraction
let leaf_writer_strong
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(sl: slice rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let sq = B.as_seq h sl.base in
let len = serialized_length s x in
live_slice h sl /\
U32.v pos + len <= U32.v sl.len /\
writable sl.base (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h pos' h' ->
B.modifies (loc_slice_from_to sl pos pos') h h' /\
valid_content_pos p h' sl pos x pos'
))
[@unifier_hint_injective]
inline_for_extraction
let serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(s: serializer p)
: Tot Type
= (x: t) ->
(#rrel: _) -> (#rel: _) ->
(b: B.mbuffer byte rrel rel) ->
(pos: U32.t) ->
HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x
)))
inline_for_extraction
let serialize32_ext
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash (t1 == t2 /\ (forall (input: bytes) . parse p1 input == parse p2 input)))
: Tot (serializer32 (serialize_ext p1 s1 p2))
= fun x #rrel #rel b pos -> s1' x b pos
inline_for_extraction
let frame_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(x: t)
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(posl: Ghost.erased U32.t)
(posr: Ghost.erased U32.t)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len = Seq.length (serialize s x) in
let sq = B.as_seq h b in
B.live h b /\
U32.v (Ghost.reveal posl) <= U32.v pos /\
U32.v pos + len <= U32.v (Ghost.reveal posr) /\
U32.v (Ghost.reveal posr) <= B.length b /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h
))
(ensures (fun h len h' ->
Seq.length (serialize s x) == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` serialize s x /\
writable b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h' /\
Seq.slice (B.as_seq h' b) (U32.v (Ghost.reveal posl)) (U32.v pos) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v (Ghost.reveal posl)) (U32.v pos) /\
Seq.slice (B.as_seq h' b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr)) `Seq.equal` Seq.slice (B.as_seq h b) (U32.v pos + U32.v len) (U32.v (Ghost.reveal posr))
)))
=
let h0 = HST.get () in
writable_weaken b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 (U32.v pos) (U32.v pos + Seq.length (serialize s x));
let res = s32 x b pos in
let h1 = HST.get () in
let pos' = pos `U32.add` res in
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos pos';
writable_modifies b (U32.v (Ghost.reveal posl)) (U32.v (Ghost.reveal posr)) h0 B.loc_none h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) (Ghost.reveal posl) pos;
B.loc_disjoint_loc_buffer_from_to b (Ghost.reveal posl) pos pos pos';
B.modifies_buffer_from_to_elim b (Ghost.reveal posl) pos (B.loc_buffer_from_to b pos pos') h0 h1;
B.loc_includes_loc_buffer_from_to b (Ghost.reveal posl) (Ghost.reveal posr) pos' (Ghost.reveal posr);
B.loc_disjoint_loc_buffer_from_to b pos pos' pos' (Ghost.reveal posr);
B.modifies_buffer_from_to_elim b pos' (Ghost.reveal posr) (B.loc_buffer_from_to b pos pos') h0 h1;
res
inline_for_extraction
let leaf_writer_strong_of_serializer32
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(u: squash (k.parser_kind_subkind == Some ParserStrong))
: Tot (leaf_writer_strong s)
= fun x #rrel #rel input pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let len = s32 x input.base pos in
[@inline_let]
let pos' = pos `U32.add` len in
let h = HST.get () in
[@inline_let] let _ =
let large = bytes_of_slice_from h input pos in
let small = bytes_of_slice_from_to h input pos pos' in
parse_strong_prefix p small large;
valid_facts p h input pos
in
pos'
inline_for_extraction
let leaf_writer_weak_of_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz /\
k.parser_kind_low < U32.v max_uint32
))
: Tot (leaf_writer_weak s)
= fun x #rrel #rel input pos ->
if (input.len `U32.sub` pos) `U32.lt` sz
then max_uint32
else begin
let h = HST.get () in
writable_weaken input.base (U32.v pos) (U32.v input.len) h (U32.v pos) (U32.v pos + U32.v sz);
s32 x input pos
end
inline_for_extraction
let serializer32_of_leaf_writer_strong_constant_size
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(sz: U32.t)
(u: squash (
k.parser_kind_subkind == Some ParserStrong /\
k.parser_kind_high == Some k.parser_kind_low /\
k.parser_kind_low == U32.v sz
))
: Tot (serializer32 s)
= fun x #rrel #rel b pos ->
serialized_length_eq s x;
let h0 = HST.get () in
let pos' = s32 x (make_slice b (pos `U32.add` sz)) pos in
[@inline_let]
let len = pos' `U32.sub` pos in
let h = HST.get () in
[@inline_let] let _ =
valid_valid_exact p h (make_slice b (pos `U32.add` sz)) pos;
valid_exact_serialize s h (make_slice b (pos `U32.add` sz)) pos pos'
in
len
inline_for_extraction
let blit_strong
(#a:Type) (#rrel1 #rrel2 #rel1 #rel2: _)
(src: B.mbuffer a rrel1 rel1)
(idx_src:U32.t)
(dst: B.mbuffer a rrel2 rel2)
(idx_dst:U32.t)
(len:U32.t)
: HST.Stack unit
(requires (fun h ->
B.live h src /\ B.live h dst /\
U32.v idx_src + U32.v len <= B.length src /\
U32.v idx_dst + U32.v len <= B.length dst /\
B.loc_disjoint (B.loc_buffer_from_to src idx_src (idx_src `U32.add` len)) (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) /\
rel2 (B.as_seq h dst)
(Seq.replace_subseq (B.as_seq h dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len)
(Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)))))
(ensures (fun h _ h' ->
B.modifies (B.loc_buffer_from_to dst idx_dst (idx_dst `U32.add` len)) h h' /\
B.live h' dst /\
Seq.slice (B.as_seq h' dst) (U32.v idx_dst) (U32.v idx_dst + U32.v len) ==
Seq.slice (B.as_seq h src) (U32.v idx_src) (U32.v idx_src + U32.v len)
))
= let h = HST.get () in
B.blit src idx_src dst idx_dst len;
let h' = HST.get () in
B.modifies_loc_buffer_from_to_intro dst idx_dst (idx_dst `U32.add` len) B.loc_none h h'
#push-options "--z3rlimit 16"
inline_for_extraction
let copy_strong
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
U32.v dpos + U32.v spos' - U32.v spos <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from_to dst dpos (dpos `U32.add` (spos' `U32.sub` spos)))
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos' /\
dpos' `U32.sub` dpos == spos' `U32.sub` spos
))
= let h0 = HST.get () in
let len = spos' `U32.sub` spos in
valid_facts p h0 src spos;
writable_replace_subseq_elim dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h0 (Seq.slice (B.as_seq h0 src.base) (U32.v spos) (U32.v spos'));
blit_strong src.base spos dst.base dpos len;
let h = HST.get () in
[@inline_let] let dpos' = dpos `U32.add` len in
parse_strong_prefix p (bytes_of_slice_from h0 src spos) (bytes_of_slice_from h dst dpos);
valid_facts p h dst dpos;
dpos'
#pop-options
inline_for_extraction
let copy_strong'
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\ (
let clen = content_length p h src spos in
U32.v dpos + clen <= U32.v dst.len /\
live_slice h dst /\
writable dst.base (U32.v dpos) (U32.v dpos + clen) h /\
B.loc_disjoint (loc_slice_from src spos) (loc_slice_from_to dst dpos (dpos `U32.add` (U32.uint_to_t clen)))
)))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from_to dst dpos dpos') h h' /\
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
))
= let spos' = j src spos in
copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak_with_length
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(src: slice rrel1 rel1) // FIXME: length is useless here
(spos spos' : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid_pos p h src spos spos' /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (U32.v spos' - U32.v spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos spos') (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= if (dst.len `U32.sub` dpos) `U32.lt` (spos' `U32.sub` spos)
then max_uint32
else copy_strong p src spos spos' dst dpos
inline_for_extraction
let copy_weak
(#rrel1 #rrel2 #rel1 #rel2: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(jmp: jumper p)
(src: slice rrel1 rel1)
(spos : U32.t)
(dst: slice rrel2 rel2)
(dpos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
k.parser_kind_subkind == Some ParserStrong /\
valid p h src spos /\
live_slice h dst /\
U32.v dpos <= U32.v dst.len /\
U32.v dst.len < U32.v max_uint32 /\
writable dst.base (U32.v dpos) (U32.v dpos + (content_length p h src spos)) h /\
B.loc_disjoint (loc_slice_from_to src spos (get_valid_pos p h src spos)) (loc_slice_from dst dpos)
))
(ensures (fun h dpos' h' ->
B.modifies (loc_slice_from dst dpos) h h' /\ (
if dpos' = max_uint32
then
U32.v dpos + content_length p h src spos > U32.v dst.len
else
valid_content_pos p h' dst dpos (contents p h src spos) dpos'
)))
= let spos' = jmp src spos in
copy_weak_with_length p src spos spos' dst dpos
(* fold_left on lists *)
module BF = LowStar.Buffer
#push-options "--z3rlimit 256 --fuel 1 --ifuel 1"
#restart-solver
inline_for_extraction
let list_fold_left_gen
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(post_interrupt: ((h: HS.mem) -> GTot Type0))
(post_interrupt_frame: (h: HS.mem) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
post_interrupt h
)) (ensures (post_interrupt h')))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
HST.Stack bool
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos1 /\
valid_pos p h0 sl pos1 pos2 /\
valid_list p h0 sl pos2 pos' /\
inv h (contents_list p h0 sl pos pos1) (contents p h0 sl pos1 :: contents_list p h0 sl pos2 pos') pos1
))
(ensures (fun h ctinue h' ->
B.modifies (Ghost.reveal l) h h' /\
(if ctinue then inv h' (contents_list p h0 sl pos pos1 `L.append` [contents p h0 sl pos1]) (contents_list p h0 sl pos2 pos') pos2 else post_interrupt h')
))
))
: HST.Stack bool
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h res h' ->
B.modifies (Ghost.reveal l) h h' /\
(if res then inv h' (contents_list p h sl pos pos') [] pos' else post_interrupt h')
))
= HST.push_frame ();
let h1 = HST.get () in
// B.fresh_frame_modifies h0 h1;
let bpos : BF.pointer U32.t = BF.alloca pos 1ul in
let bctinue : BF.pointer bool = BF.alloca true 1ul in
let btest: BF.pointer bool = BF.alloca (pos `U32.lt` pos') 1ul in
let h2 = HST.get () in
assert (B.modifies B.loc_none h0 h2);
let test_pre (h: HS.mem) : GTot Type0 =
B.live h bpos /\ B.live h bctinue /\ B.live h btest /\ (
let pos1 = Seq.index (B.as_seq h bpos) 0 in
let ctinue = Seq.index (B.as_seq h bctinue) 0 in
valid_list p h0 sl pos pos1 /\
valid_list p h0 sl pos1 pos' /\
B.modifies (Ghost.reveal l `B.loc_union` B.loc_region_only true (HS.get_tip h1)) h2 h /\
Seq.index (B.as_seq h btest) 0 == ((U32.v (Seq.index (B.as_seq h bpos) 0) < U32.v pos') && Seq.index (B.as_seq h bctinue) 0) /\
(if ctinue then inv h (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 else post_interrupt h)
)
in
let test_post (cond: bool) (h: HS.mem) : GTot Type0 =
test_pre h /\
cond == Seq.index (B.as_seq h btest) 0
in
valid_list_nil p h0 sl pos;
inv_frame h0 [] (contents_list p h0 sl pos pos') pos h1;
inv_frame h1 [] (contents_list p h0 sl pos pos') pos h2;
[@inline_let]
let while_body () : HST.Stack unit
(requires (fun h -> test_post true h))
(ensures (fun _ _ h1 -> test_pre h1))
=
let h51 = HST.get () in
let pos1 = B.index bpos 0ul in
valid_list_cons_recip p h0 sl pos1 pos';
//assert (B.modifies (Ghost.reveal l `B.loc_union` B.loc_buffer bpos) h0 h51);
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos'));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos pos1));
valid_list_cons_recip p h51 sl pos1 pos';
let pos2 = j sl pos1 in
let h52 = HST.get () in
inv_frame h51 (contents_list p h0 sl pos pos1) (contents_list p h0 sl pos1 pos') pos1 h52;
B.modifies_only_not_unused_in (Ghost.reveal l) h0 h52;
let ctinue = body pos1 pos2 in
let h53 = HST.get () in
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2));
//assert (B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos2 pos'));
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h1));
valid_pos_frame_strong p h0 sl pos1 pos2 (Ghost.reveal l) h53;
valid_list_snoc p h0 sl pos pos1;
B.upd bpos 0ul pos2;
B.upd bctinue 0ul ctinue;
B.upd btest 0ul ((pos2 `U32.lt` pos') && ctinue);
let h54 = HST.get () in
[@inline_let]
let _ =
if ctinue
then inv_frame h53 (contents_list p h0 sl pos pos2) (contents_list p h0 sl pos2 pos') pos2 h54
else post_interrupt_frame h53 h54
in
()
in
C.Loops.while
#test_pre
#test_post
(fun (_: unit) -> (
B.index btest 0ul) <: HST.Stack bool (requires (fun h -> test_pre h)) (ensures (fun h x h1 -> test_post x h1)))
while_body
;
valid_list_nil p h0 sl pos';
let res = B.index bctinue 0ul in
let h3 = HST.get () in
HST.pop_frame ();
let h4 = HST.get () in
//B.popped_modifies h3 h4;
B.loc_regions_unused_in h0 (Set.singleton (HS.get_tip h3));
[@inline_let]
let _ =
if res
then inv_frame h3 (contents_list p h0 sl pos pos') [] pos' h4
else post_interrupt_frame h3 h4
in
res
#pop-options
//B.loc_includes_union_l (B.loc_all_regions_from false (HS.get_tip h1)) (Ghost.reveal l) (Ghost.reveal l)
//B.modifies_fresh_frame_popped h0 h1 (Ghost.reveal l) h3 h4
module G = FStar.Ghost
inline_for_extraction
let list_fold_left
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
(h0: HS.mem)
(l: Ghost.erased B.loc { B.loc_disjoint (Ghost.reveal l) (loc_slice_from_to sl pos pos') } )
(inv: (HS.mem -> list t -> list t -> U32.t -> GTot Type0))
(inv_frame: (h: HS.mem) -> (l1: list t) -> (l2: list t) -> (pos1: U32.t) -> (h' : HS.mem) -> Lemma (requires (
B.modifies (B.loc_unused_in h0) h h' /\
inv h l1 l2 pos1
)) (ensures (inv h' l1 l2 pos1)))
(body: (
(pos1: U32.t) ->
(pos2: U32.t) ->
(l1: Ghost.erased (list t)) ->
(x: Ghost.erased t) ->
(l2: Ghost.erased (list t)) ->
HST.Stack unit
(requires (fun h ->
B.modifies (Ghost.reveal l) h0 h /\
valid_list p h0 sl pos pos' /\
valid_content_pos p h0 sl pos1 (G.reveal x) pos2 /\
U32.v pos <= U32.v pos1 /\ U32.v pos2 <= U32.v pos' /\
B.loc_includes (loc_slice_from_to sl pos pos') (loc_slice_from_to sl pos1 pos2) /\
inv h (Ghost.reveal l1) (Ghost.reveal x :: Ghost.reveal l2) pos1 /\
contents_list p h0 sl pos pos' == Ghost.reveal l1 `L.append` (Ghost.reveal x :: Ghost.reveal l2)
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (Ghost.reveal l1 `L.append` [contents p h0 sl pos1]) (Ghost.reveal l2) pos2
))
))
: HST.Stack unit
(requires (fun h ->
h == h0 /\
valid_list p h sl pos pos' /\
inv h [] (contents_list p h sl pos pos') pos
))
(ensures (fun h _ h' ->
B.modifies (Ghost.reveal l) h h' /\
inv h' (contents_list p h sl pos pos') [] pos'
))
= let _ = list_fold_left_gen
p
j
sl
pos pos'
h0
l
inv
inv_frame
(fun _ -> False)
(fun _ _ -> ())
(fun pos1 pos2 ->
let h = HST.get () in
valid_list_cons p h sl pos1 pos';
valid_list_append p h sl pos pos1 pos';
body
pos1
pos2
(Ghost.hide (contents_list p h sl pos pos1))
(Ghost.hide (contents p h sl pos1))
(Ghost.hide (contents_list p h sl pos2 pos'))
;
true
)
in
()
inline_for_extraction
let list_length
(#rrel #rel: _)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(sl: slice rrel rel)
(pos pos' : U32.t)
: HST.Stack U32.t
(requires (fun h ->
valid_list p h sl pos pos'
))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
U32.v res == L.length (contents_list p h sl pos pos')
))
= let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
B.fresh_frame_modifies h0 h1;
let blen : BF.pointer U32.t = BF.alloca 0ul 1ul in
let h2 = HST.get () in
list_fold_left
p
j
sl
pos
pos'
h2
(Ghost.hide (B.loc_buffer blen))
(fun h l1 l2 pos1 ->
B.modifies (B.loc_buffer blen) h2 h /\
B.live h blen /\ (
let len = U32.v (Seq.index (B.as_seq h blen) 0) in
len <= U32.v pos1 /\ // necessary to prove that length computations do not overflow
len == L.length l1
))
(fun h l1 l2 pos1 h' ->
B.modifies_only_not_unused_in (B.loc_buffer blen) h2 h';
B.loc_unused_in_not_unused_in_disjoint h2
)
(fun pos1 pos2 l1 x l2 ->
B.upd blen 0ul (B.index blen 0ul `U32.add` 1ul);
Classical.forall_intro_2 (list_length_append #t)
)
;
let len = B.index blen 0ul in
HST.pop_frame ();
len
#push-options "--z3rlimit 32 --fuel 2 --ifuel 1" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Comment.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Math.fst.checked",
"LowParse.Low.ErrorCode.fst.checked",
"LowParse.Low.Base.Spec.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Base.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "BF"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "LowParse.Math",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "LowParse.Low.ErrorCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 32,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: LowParse.Spec.Base.parser k t ->
j: LowParse.Low.Base.jumper p ->
f: (_: t -> Prims.bool) ->
f':
(sl: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> x: FStar.Ghost.erased t
-> FStar.HyperStack.ST.Stack Prims.bool) ->
sl: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t ->
pos': FStar.UInt32.t ->
sl_out: LowParse.Slice.slice rrel_out rel_out ->
pos_out: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | FStar.HyperStack.ST.Stack | [] | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"Prims.bool",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"FStar.Ghost.erased",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Low.Base.Spec.valid_content",
"FStar.Ghost.reveal",
"Prims.l_and",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.eq2",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"LowStar.Monotonic.Buffer.index",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.__uint_to_t",
"LowParse.Low.Base.list_fold_left",
"FStar.Ghost.hide",
"LowStar.Monotonic.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_union",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowParse.Slice.loc_slice_from_to",
"FStar.UInt32.add",
"FStar.UInt32.sub",
"Prims.list",
"LowStar.Monotonic.Buffer.loc_unused_in_not_unused_in_disjoint",
"LowStar.Monotonic.Buffer.modifies_only_not_unused_in",
"FStar.Seq.Base.index",
"LowStar.Monotonic.Buffer.as_seq",
"LowParse.Low.Base.Spec.valid_list_append",
"LowParse.Low.Base.Spec.valid_list_cons",
"LowParse.Low.Base.Spec.valid_list_nil",
"LowParse.Low.Base.writable_modifies",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"FStar.UInt32.v",
"Prims.op_Addition",
"Prims.op_Subtraction",
"LowStar.Monotonic.Buffer.loc_region_only",
"FStar.Monotonic.HyperStack.get_tip",
"FStar.HyperStack.ST.get",
"LowStar.Monotonic.Buffer.upd",
"LowParse.Low.Base.copy_strong",
"LowParse.Low.Base.writable_weaken",
"Prims._assert",
"LowStar.Monotonic.Buffer.loc_includes",
"FStar.List.Tot.Properties.append_l_nil",
"FStar.List.Tot.Base.filter",
"LowParse.Low.Base.Spec.list_filter_append",
"Prims.Cons",
"Prims.Nil",
"LowStar.Monotonic.Buffer.live",
"LowParse.Low.Base.writable",
"LowParse.Low.Base.Spec.valid_list",
"LowParse.Low.Base.Spec.contents_list",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowStar.Buffer.pointer",
"LowStar.Buffer.alloca",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"LowStar.Monotonic.Buffer.length",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"FStar.HyperStack.ST.push_frame",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowStar.Monotonic.Buffer.loc_disjoint",
"LowParse.Slice.live_slice"
] | [] | false | true | false | false | false | let list_filter
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(j: jumper p)
(f: (t -> Tot bool))
(f':
(#rrel: _ -> #rel: _ -> sl: slice rrel rel -> pos: U32.t -> x: Ghost.erased t
-> HST.Stack bool
(requires (fun h -> valid_content p h sl pos (G.reveal x)))
(ensures (fun h res h' -> B.modifies B.loc_none h h' /\ res == f (G.reveal x)))))
(#rrel #rel: _)
(sl: slice rrel rel)
(pos pos': U32.t)
(#rrel_out #rel_out: _)
(sl_out: slice rrel_out rel_out)
(pos_out: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
U32.v pos_out + U32.v pos' - U32.v pos <= U32.v sl_out.len /\ valid_list p h sl pos pos' /\
B.loc_disjoint (loc_slice_from_to sl pos pos')
(loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))) /\
writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
live_slice h sl_out))
(ensures
(fun h pos_out' h' ->
B.modifies (loc_slice_from_to sl_out pos_out pos_out') h h' /\
U32.v pos_out' - U32.v pos_out <= U32.v pos' - U32.v pos /\
valid_list p h' sl_out pos_out pos_out' /\
contents_list p h' sl_out pos_out pos_out' == L.filter f (contents_list p h sl pos pos')
)) =
| let h0 = HST.get () in
HST.push_frame ();
let h1 = HST.get () in
let bpos_out':BF.pointer U32.t = BF.alloca pos_out 1ul in
let h2 = HST.get () in
let inv (h: HS.mem) (l1 l2: list t) (pos1: U32.t) : GTot Type0 =
B.live h bpos_out' /\
(let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies ((B.loc_buffer bpos_out') `B.loc_union` (loc_slice_from_to sl_out pos_out pos_out'))
h2
h /\ writable sl_out.base (U32.v pos_out) (U32.v pos_out + (U32.v pos' - U32.v pos)) h /\
valid_list p h sl_out pos_out pos_out' /\
contents_list p h sl_out pos_out pos_out' == L.filter f l1 /\
U32.v pos_out' - U32.v pos1 <= U32.v pos_out - U32.v pos)
in
valid_list_nil p h2 sl_out pos_out;
list_fold_left p j sl pos pos' h2
(Ghost.hide ((B.loc_buffer bpos_out')
`B.loc_union`
(loc_slice_from_to sl_out pos_out (pos_out `U32.add` (pos' `U32.sub` pos))))) inv
(fun h l1 l2 pos1 h' ->
let pos_out' = Seq.index (B.as_seq h bpos_out') 0 in
B.modifies_only_not_unused_in ((B.loc_buffer bpos_out')
`B.loc_union`
(loc_slice_from_to sl_out pos_out pos_out'))
h2
h';
B.loc_unused_in_not_unused_in_disjoint h2)
(fun pos1 pos2 l1 x l2 ->
let pos_out1 = B.index bpos_out' 0ul in
list_filter_append f (G.reveal l1) [G.reveal x];
if f' sl pos1 x
then
(assert (B.loc_includes (loc_slice_from_to sl_out
pos_out
(pos_out `U32.add` (pos' `U32.sub` pos)))
(loc_slice_from_to sl_out pos_out1 (pos_out1 `U32.add` (pos2 `U32.sub` pos1))));
let h = HST.get () in
writable_weaken sl_out.base
(U32.v pos_out)
(U32.v pos_out + (U32.v pos' - U32.v pos))
h
(U32.v pos_out1)
(U32.v pos_out1 + (U32.v pos2 - U32.v pos1));
let pos_out2 = copy_strong p sl pos1 pos2 sl_out pos_out1 in
B.upd bpos_out' 0ul pos_out2;
let h' = HST.get () in
writable_modifies sl_out.base
(U32.v pos_out)
(U32.v pos_out + (U32.v pos' - U32.v pos))
h
(B.loc_region_only true (HS.get_tip h1))
h';
valid_list_nil p h' sl_out pos_out2;
valid_list_cons p h' sl_out pos_out1 pos_out2;
valid_list_append p h' sl_out pos_out pos_out1 pos_out2)
else L.append_l_nil (L.filter f (G.reveal l1)));
let pos_out' = B.index bpos_out' 0ul in
HST.pop_frame ();
pos_out' | false |
GenericStability.fst | GenericStability.stable_append | val stable_append: #a:eqtype
-> (l1:list a)
-> (l2:list a)
-> (r1:list a)
-> (r2:list a)
-> k:(a -> Tot int)
-> Lemma (requires (stable l1 l2 k /\ stable r1 r2 k))
(ensures (stable (l1@r1) (l2@r2) k)) | val stable_append: #a:eqtype
-> (l1:list a)
-> (l2:list a)
-> (r1:list a)
-> (r2:list a)
-> k:(a -> Tot int)
-> Lemma (requires (stable l1 l2 k /\ stable r1 r2 k))
(ensures (stable (l1@r1) (l2@r2) k)) | let stable_append #a l1 l2 r1 r2 k =
stable_append_r l1 l2 r1 k;
stable_append_l l2 r1 r2 k | {
"file_name": "examples/algorithms/GenericStability.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 146,
"start_col": 0,
"start_line": 144
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
@summary: This module defines sorting stability on generic lists.
@author: A Manning
**)
module GenericStability
open FStar.List.Tot
open FStar.List.Tot
open GenericSort
(*
This module is heavily inspired by Leino and Lucio's 2012 paper,
'An Assertional Proof of the Stability and Correctness of Natural Mergesort'.
http://research.microsoft.com/en-us/um/people/leino/papers/krml241.pdf
*)
(**
filterEq returns the elements of a list that have the same key as n.
**)
val filter_eq: #a:Type -> (x:int) -> (xs: list a) -> k:(a -> Tot int) -> Tot (list a)
let rec filter_eq #a x xs k =
match xs with
| [] -> []
| hd::tl
-> if k hd = x then
hd::(filter_eq x tl k)
else filter_eq x tl k
val filter_eq_contains: #a:eqtype -> (k:int) -> (xs: list a) -> key:(a -> Tot int) ->
Lemma (ensures (forall x. (mem x xs /\ key x = k) <==> mem x (filter_eq k xs key)))
let rec filter_eq_contains #a k xs key =
match xs with
| [] -> ()
| hd::tl ->
filter_eq_contains k tl key
val filter_eq_append: #a:eqtype -> (l1: list a) -> (l2: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l1 k)@(filter_eq x l2 k) = filter_eq x (l1@l2) k))
let rec filter_eq_append #a l1 l2 k =
match l1 with
| [] -> ()
| hd::tl ->
filter_eq_append tl l2 k
val filter_eq_not_contains: #a:eqtype -> (l: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l k) = [] <==> ~(exists e. (mem e l /\ k e = x))))
let rec filter_eq_not_contains #a l k =
match l with
| [] -> ()
| hd::tl ->
filter_eq_not_contains tl k
val filter_eq_single: #a:eqtype ->
(l: list a{Cons? l /\ length l = 1}) ->
k:(a -> Tot int) ->
Lemma (ensures (forall x. (k (hd l) = x ) ==> filter_eq x l k = [hd l]))
let filter_eq_single #a l k = ()
val filter_eq_sorted_lt: #a:eqtype -> l:list a{Cons? l} -> k:(a -> Tot int) ->
Lemma (requires (sorted l k))
(ensures (forall x. (x < k (hd l)) ==> (filter_eq x l k = [])))
let filter_eq_sorted_lt #a l k =
sorted_lt l k;
filter_eq_not_contains l k
val filter_eq_first: #a:eqtype ->
(l1: list a{Cons? l1}) ->
(l2: list a{Cons? l2}) ->
k:(a -> Tot int) ->
Lemma (requires (sorted l1 k) /\ (k (hd l1) > k (hd l2)))
(ensures (forall x. (k (hd l2) = x ) ==>
filter_eq x (l1@l2) k = ((filter_eq x ((hd l2)::l1) k )@(filter_eq x (tl l2) k))))
let filter_eq_first #a l1 l2 k =
filter_eq_append l1 l2 k;
filter_eq_sorted_lt l1 k
type stable (#a:eqtype) (l1:list a) (l2:list a) (k:(a -> Tot int)) = forall x. (filter_eq x l1 k = filter_eq x l2 k)
val stable_lift: #a:eqtype ->
(l1: list a{Cons? l1}) ->
(l2: list a{Cons? l2}) ->
k:(a -> Tot int) ->
Lemma (requires (sorted l1 k) /\ (k (hd l1) > k (hd l2)))
(ensures (stable (l1@l2) (((hd l2)::l1)@(tl l2)) k))
let stable_lift #a l1 l2 k =
filter_eq_append l1 l2 k;
filter_eq_append ((hd l2)::l1) (tl l2) k;
filter_eq_first l1 l2 k;
filter_eq_append ((hd l2)::l1) (tl l2) k
val stable_append_l: #a:eqtype ->
(l: list a) ->
(r: list a) ->
(r': list a) ->
k:(a -> Tot int) ->
Lemma (ensures (stable r r' k ==> stable (l@r) (l@r') k))
let rec stable_append_l #a l r r' k =
match l with
| [] -> ()
| hd::tl -> stable_append_l tl r r' k
val stable_append_r: #a:eqtype ->
(l: list a) ->
(l': list a) ->
(r: list a) ->
k:(a -> Tot int) ->
Lemma (requires (stable l l' k))
(ensures(stable (l@r) (l'@r) k))
let rec stable_append_r #a l l' r k =
filter_eq_append l r k;
filter_eq_append l' r k
val stable_transitive: #a:eqtype
-> (l1:list a)
-> (l2:list a)
-> (l3:list a)
-> k:(a -> Tot int)
-> Lemma (requires (stable l1 l2 k /\ stable l2 l3 k))
(ensures (stable l1 l3 k))
let stable_transitive #a l1 l2 l3 k = ()
val stable_append: #a:eqtype
-> (l1:list a)
-> (l2:list a)
-> (r1:list a)
-> (r2:list a)
-> k:(a -> Tot int)
-> Lemma (requires (stable l1 l2 k /\ stable r1 r2 k)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"GenericSort.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "GenericStability.fst"
} | [
{
"abbrev": false,
"full_module": "GenericSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "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 |
l1: Prims.list a ->
l2: Prims.list a ->
r1: Prims.list a ->
r2: Prims.list a ->
k: (_: a -> Prims.int)
-> FStar.Pervasives.Lemma
(requires GenericStability.stable l1 l2 k /\ GenericStability.stable r1 r2 k)
(ensures GenericStability.stable (l1 @ r1) (l2 @ r2) k) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.int",
"GenericStability.stable_append_l",
"Prims.unit",
"GenericStability.stable_append_r"
] | [] | true | false | true | false | false | let stable_append #a l1 l2 r1 r2 k =
| stable_append_r l1 l2 r1 k;
stable_append_l l2 r1 r2 k | false |
GenericStability.fst | GenericStability.filter_eq_append | val filter_eq_append: #a:eqtype -> (l1: list a) -> (l2: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l1 k)@(filter_eq x l2 k) = filter_eq x (l1@l2) k)) | val filter_eq_append: #a:eqtype -> (l1: list a) -> (l2: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l1 k)@(filter_eq x l2 k) = filter_eq x (l1@l2) k)) | let rec filter_eq_append #a l1 l2 k =
match l1 with
| [] -> ()
| hd::tl ->
filter_eq_append tl l2 k | {
"file_name": "examples/algorithms/GenericStability.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 57,
"start_col": 0,
"start_line": 53
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
@summary: This module defines sorting stability on generic lists.
@author: A Manning
**)
module GenericStability
open FStar.List.Tot
open FStar.List.Tot
open GenericSort
(*
This module is heavily inspired by Leino and Lucio's 2012 paper,
'An Assertional Proof of the Stability and Correctness of Natural Mergesort'.
http://research.microsoft.com/en-us/um/people/leino/papers/krml241.pdf
*)
(**
filterEq returns the elements of a list that have the same key as n.
**)
val filter_eq: #a:Type -> (x:int) -> (xs: list a) -> k:(a -> Tot int) -> Tot (list a)
let rec filter_eq #a x xs k =
match xs with
| [] -> []
| hd::tl
-> if k hd = x then
hd::(filter_eq x tl k)
else filter_eq x tl k
val filter_eq_contains: #a:eqtype -> (k:int) -> (xs: list a) -> key:(a -> Tot int) ->
Lemma (ensures (forall x. (mem x xs /\ key x = k) <==> mem x (filter_eq k xs key)))
let rec filter_eq_contains #a k xs key =
match xs with
| [] -> ()
| hd::tl ->
filter_eq_contains k tl key
val filter_eq_append: #a:eqtype -> (l1: list a) -> (l2: list a) -> k:(a -> Tot int) -> | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"GenericSort.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "GenericStability.fst"
} | [
{
"abbrev": false,
"full_module": "GenericSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "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 | l1: Prims.list a -> l2: Prims.list a -> k: (_: a -> Prims.int)
-> FStar.Pervasives.Lemma
(ensures
forall (x: Prims.int).
GenericStability.filter_eq x l1 k @ GenericStability.filter_eq x l2 k =
GenericStability.filter_eq x (l1 @ l2) k) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.int",
"GenericStability.filter_eq_append",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec filter_eq_append #a l1 l2 k =
| match l1 with
| [] -> ()
| hd :: tl -> filter_eq_append tl l2 k | false |
GenericStability.fst | GenericStability.stable_lift | val stable_lift: #a:eqtype ->
(l1: list a{Cons? l1}) ->
(l2: list a{Cons? l2}) ->
k:(a -> Tot int) ->
Lemma (requires (sorted l1 k) /\ (k (hd l1) > k (hd l2)))
(ensures (stable (l1@l2) (((hd l2)::l1)@(tl l2)) k)) | val stable_lift: #a:eqtype ->
(l1: list a{Cons? l1}) ->
(l2: list a{Cons? l2}) ->
k:(a -> Tot int) ->
Lemma (requires (sorted l1 k) /\ (k (hd l1) > k (hd l2)))
(ensures (stable (l1@l2) (((hd l2)::l1)@(tl l2)) k)) | let stable_lift #a l1 l2 k =
filter_eq_append l1 l2 k;
filter_eq_append ((hd l2)::l1) (tl l2) k;
filter_eq_first l1 l2 k;
filter_eq_append ((hd l2)::l1) (tl l2) k | {
"file_name": "examples/algorithms/GenericStability.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 103,
"start_col": 0,
"start_line": 99
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
(**
@summary: This module defines sorting stability on generic lists.
@author: A Manning
**)
module GenericStability
open FStar.List.Tot
open FStar.List.Tot
open GenericSort
(*
This module is heavily inspired by Leino and Lucio's 2012 paper,
'An Assertional Proof of the Stability and Correctness of Natural Mergesort'.
http://research.microsoft.com/en-us/um/people/leino/papers/krml241.pdf
*)
(**
filterEq returns the elements of a list that have the same key as n.
**)
val filter_eq: #a:Type -> (x:int) -> (xs: list a) -> k:(a -> Tot int) -> Tot (list a)
let rec filter_eq #a x xs k =
match xs with
| [] -> []
| hd::tl
-> if k hd = x then
hd::(filter_eq x tl k)
else filter_eq x tl k
val filter_eq_contains: #a:eqtype -> (k:int) -> (xs: list a) -> key:(a -> Tot int) ->
Lemma (ensures (forall x. (mem x xs /\ key x = k) <==> mem x (filter_eq k xs key)))
let rec filter_eq_contains #a k xs key =
match xs with
| [] -> ()
| hd::tl ->
filter_eq_contains k tl key
val filter_eq_append: #a:eqtype -> (l1: list a) -> (l2: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l1 k)@(filter_eq x l2 k) = filter_eq x (l1@l2) k))
let rec filter_eq_append #a l1 l2 k =
match l1 with
| [] -> ()
| hd::tl ->
filter_eq_append tl l2 k
val filter_eq_not_contains: #a:eqtype -> (l: list a) -> k:(a -> Tot int) ->
Lemma (ensures (forall x. (filter_eq x l k) = [] <==> ~(exists e. (mem e l /\ k e = x))))
let rec filter_eq_not_contains #a l k =
match l with
| [] -> ()
| hd::tl ->
filter_eq_not_contains tl k
val filter_eq_single: #a:eqtype ->
(l: list a{Cons? l /\ length l = 1}) ->
k:(a -> Tot int) ->
Lemma (ensures (forall x. (k (hd l) = x ) ==> filter_eq x l k = [hd l]))
let filter_eq_single #a l k = ()
val filter_eq_sorted_lt: #a:eqtype -> l:list a{Cons? l} -> k:(a -> Tot int) ->
Lemma (requires (sorted l k))
(ensures (forall x. (x < k (hd l)) ==> (filter_eq x l k = [])))
let filter_eq_sorted_lt #a l k =
sorted_lt l k;
filter_eq_not_contains l k
val filter_eq_first: #a:eqtype ->
(l1: list a{Cons? l1}) ->
(l2: list a{Cons? l2}) ->
k:(a -> Tot int) ->
Lemma (requires (sorted l1 k) /\ (k (hd l1) > k (hd l2)))
(ensures (forall x. (k (hd l2) = x ) ==>
filter_eq x (l1@l2) k = ((filter_eq x ((hd l2)::l1) k )@(filter_eq x (tl l2) k))))
let filter_eq_first #a l1 l2 k =
filter_eq_append l1 l2 k;
filter_eq_sorted_lt l1 k
type stable (#a:eqtype) (l1:list a) (l2:list a) (k:(a -> Tot int)) = forall x. (filter_eq x l1 k = filter_eq x l2 k)
val stable_lift: #a:eqtype ->
(l1: list a{Cons? l1}) ->
(l2: list a{Cons? l2}) ->
k:(a -> Tot int) ->
Lemma (requires (sorted l1 k) /\ (k (hd l1) > k (hd l2))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"GenericSort.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "GenericStability.fst"
} | [
{
"abbrev": false,
"full_module": "GenericSort",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "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 | l1: Prims.list a {Cons? l1} -> l2: Prims.list a {Cons? l2} -> k: (_: a -> Prims.int)
-> FStar.Pervasives.Lemma
(requires
GenericSort.sorted l1 k /\ k (FStar.List.Tot.Base.hd l1) > k (FStar.List.Tot.Base.hd l2))
(ensures
GenericStability.stable (l1 @ l2)
(FStar.List.Tot.Base.hd l2 :: l1 @ FStar.List.Tot.Base.tl l2)
k) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Prims.b2t",
"Prims.uu___is_Cons",
"Prims.int",
"GenericStability.filter_eq_append",
"Prims.Cons",
"FStar.List.Tot.Base.hd",
"FStar.List.Tot.Base.tl",
"Prims.unit",
"GenericStability.filter_eq_first"
] | [] | true | false | true | false | false | let stable_lift #a l1 l2 k =
| filter_eq_append l1 l2 k;
filter_eq_append ((hd l2) :: l1) (tl l2) k;
filter_eq_first l1 l2 k;
filter_eq_append ((hd l2) :: l1) (tl l2) k | false |
Hacl.Bignum.SafeAPI.fst | Hacl.Bignum.SafeAPI.bn_mod_slow_safe_st | val bn_mod_slow_safe_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\
(r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n)) | {
"file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 136,
"start_col": 0,
"start_line": 126
} | module Hacl.Bignum.SafeAPI
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module E = Hacl.Spec.Exponentiation.Lemmas
module BL = Hacl.Bignum.Lib
module BB = Hacl.Bignum.Base
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
module BM = Hacl.Bignum.Montgomery
module BE = Hacl.Bignum.Exponentiation
module BR = Hacl.Bignum.ModReduction
module BC = Hacl.Bignum.Convert
module BI = Hacl.Bignum.ModInv
module SL = Hacl.Spec.Bignum.Lib
module SD = Hacl.Spec.Bignum.Definitions
module SE = Hacl.Spec.Bignum.Exponentiation
module SM = Hacl.Spec.Bignum.Montgomery
module SC = Hacl.Spec.Bignum.Convert
module SI = Hacl.Spec.Bignum.ModInv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let new_bn_from_bytes_be_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
let new_bn_from_bytes_be #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_be false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let new_bn_from_bytes_le_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t
let new_bn_from_bytes_le #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_le false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.ModInv.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.ModReduction.fst.checked",
"Hacl.Bignum.ModInv.fst.checked",
"Hacl.Bignum.Lib.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.SafeAPI.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.ModInv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Convert",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModReduction",
"short_module": "BR"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.bool",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Hacl.Spec.Bignum.Base.unsafe_bool_of_limb",
"Hacl.Spec.Bignum.Montgomery.bn_check_modulus",
"Lib.IntTypes.v",
"Lib.Buffer.as_seq",
"Prims.l_imp",
"Prims.b2t",
"Prims.int",
"Hacl.Bignum.Definitions.bn_v",
"Prims.op_Modulus"
] | [] | false | false | false | false | true | let bn_mod_slow_safe_st (t: limb_t) (len: BN.meta_len t) =
| n: lbignum t len -> a: lbignum t (len +! len) -> res: lbignum t len
-> Stack bool
(requires fun h -> live h n /\ live h a /\ live h res /\ disjoint res n /\ disjoint res a)
(ensures
fun h0 r h1 ->
modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\
(r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n)) | false |
|
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.lemma_slices_le_bytes_to_quad32 | val lemma_slices_le_bytes_to_quad32 (s: seq16 nat8)
: Lemma
(ensures
(let q = le_bytes_to_quad32 s in
q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\
q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\
q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\
q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16)))) | val lemma_slices_le_bytes_to_quad32 (s: seq16 nat8)
: Lemma
(ensures
(let q = le_bytes_to_quad32 s in
q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\
q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\
q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\
q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16)))) | let lemma_slices_le_bytes_to_quad32 (s:seq16 nat8) : Lemma
(ensures (
let q = le_bytes_to_quad32 s in
q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\
q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\
q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\
q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16))
))
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
le_bytes_to_quad32_reveal ();
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 414,
"start_col": 0,
"start_line": 403
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
)
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
()
(*
let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 16)
(ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes)))
=
()
let insert_0_is_padding (q:quad32) :
Lemma (let q' = insert_nat64_def q 0 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8)))
=
()
*)
#reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10"
let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) =
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert(i < 4 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4))) i))
(fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2");
assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4))
#reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1"
let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 2 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
assert (n == 0 \/ n == 1 \/ n == 2);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1);
assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100);
assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000);
()
let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 4 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else
assert (n == 3 \/ n == 4);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000);
assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000);
()
let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in
assert_norm (f 0);
assert_norm (f 1);
assert_norm (f 2);
assert_norm (f 3);
assert_norm (f 4);
()
let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma
(requires n <= 2)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 2);
assert_norm (f 1);
assert_norm (f 0);
()
let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
if n <= 2 then lemma_mod_n_8_lower2_helper q n else
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 4);
assert_norm (f 3);
()
let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n
let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n)))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n
let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
lo' == lo % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)
)
(ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0)
=
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
()
let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
lo' == lo % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)
)
(ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0)
=
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (pow2 (5 * 8) == 0x10000000000);
assert_norm (pow2 (6 * 8) == 0x1000000000000);
assert_norm (pow2 (7 * 8) == 0x100000000000000);
assert_norm (pow2 (8 * 8) == 0x10000000000000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
()
let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
hi' == hi % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')
)
(ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0)
=
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi');
()
let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
hi' == hi % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')
)
(ensures hi' == q'.hi2 + 0x100000000 * q'.hi3)
=
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (pow2 (5 * 8) == 0x10000000000);
assert_norm (pow2 (6 * 8) == 0x1000000000000);
assert_norm (pow2 (7 * 8) == 0x100000000000000);
assert_norm (pow2 (8 * 8) == 0x10000000000000000);
assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi');
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Vale.Def.Words.Seq_s.seq16 Vale.Def.Types_s.nat8
-> FStar.Pervasives.Lemma
(ensures
(let q = Vale.Def.Types_s.le_bytes_to_quad32 s in
Mkfour?.lo0 q ==
Vale.Def.Words.Four_s.four_to_nat 8
(Vale.Def.Words.Seq_s.seq_to_four_LE (FStar.Seq.Base.slice s 0 4)) /\
Mkfour?.lo1 q ==
Vale.Def.Words.Four_s.four_to_nat 8
(Vale.Def.Words.Seq_s.seq_to_four_LE (FStar.Seq.Base.slice s 4 8)) /\
Mkfour?.hi2 q ==
Vale.Def.Words.Four_s.four_to_nat 8
(Vale.Def.Words.Seq_s.seq_to_four_LE (FStar.Seq.Base.slice s 8 12)) /\
Mkfour?.hi3 q ==
Vale.Def.Words.Four_s.four_to_nat 8
(Vale.Def.Words.Seq_s.seq_to_four_LE (FStar.Seq.Base.slice s 12 16)))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words.Seq_s.seq16",
"Vale.Def.Types_s.nat8",
"Prims.unit",
"Vale.Def.Types_s.le_bytes_to_quad32_reveal",
"FStar.Pervasives.reveal_opaque",
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Vale.Def.Words_s.four",
"Prims.op_Division",
"Vale.Def.Words.Seq_s.seq_to_seq_four_LE",
"Prims.l_True",
"Prims.squash",
"Prims.l_and",
"Vale.Def.Words_s.natN",
"Vale.Def.Words_s.pow2_32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words.Seq_s.seq_to_four_LE",
"FStar.Seq.Base.slice",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Prims.pow2",
"FStar.Mul.op_Star",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.le_bytes_to_quad32",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_slices_le_bytes_to_quad32 (s: seq16 nat8)
: Lemma
(ensures
(let q = le_bytes_to_quad32 s in
q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\
q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\
q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\
q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16)))) =
| reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
le_bytes_to_quad32_reveal ();
() | false |
Hacl.Bignum.SafeAPI.fst | Hacl.Bignum.SafeAPI.mk_bn_mod_inv_prime_ctx | val mk_bn_mod_inv_prime_ctx:
#t:limb_t
-> len:Ghost.erased _
-> bn_mod_inv_precomp:BI.bn_mod_inv_prime_precomp_st t len ->
bn_mod_inv_prime_ctx_st t len | val mk_bn_mod_inv_prime_ctx:
#t:limb_t
-> len:Ghost.erased _
-> bn_mod_inv_precomp:BI.bn_mod_inv_prime_precomp_st t len ->
bn_mod_inv_prime_ctx_st t len | let mk_bn_mod_inv_prime_ctx #t len bn_mod_inv_precomp k a res =
let open LowStar.BufferOps in
let k1 = !*k in
bn_mod_inv_precomp k1.MA.n k1.MA.mu k1.MA.r2 a res | {
"file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 324,
"start_col": 0,
"start_line": 321
} | module Hacl.Bignum.SafeAPI
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module E = Hacl.Spec.Exponentiation.Lemmas
module BL = Hacl.Bignum.Lib
module BB = Hacl.Bignum.Base
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
module BM = Hacl.Bignum.Montgomery
module BE = Hacl.Bignum.Exponentiation
module BR = Hacl.Bignum.ModReduction
module BC = Hacl.Bignum.Convert
module BI = Hacl.Bignum.ModInv
module SL = Hacl.Spec.Bignum.Lib
module SD = Hacl.Spec.Bignum.Definitions
module SE = Hacl.Spec.Bignum.Exponentiation
module SM = Hacl.Spec.Bignum.Montgomery
module SC = Hacl.Spec.Bignum.Convert
module SI = Hacl.Spec.Bignum.ModInv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let new_bn_from_bytes_be_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
let new_bn_from_bytes_be #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_be false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let new_bn_from_bytes_le_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t
let new_bn_from_bytes_le #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_le false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\
(r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n))
inline_for_extraction noextract
val mk_bn_mod_slow_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_slow:BR.bn_mod_slow_st t len ->
bn_mod_slow_safe_st t len
let mk_bn_mod_slow_safe #t len bn_mod_slow n a res =
let h0 = ST.get () in
let is_valid_m = BM.bn_check_modulus n in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_slow nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t}
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\
(r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)))
inline_for_extraction noextract
val mk_bn_mod_exp_safe:
#t:limb_t
-> len:BN.meta_len t
-> exp_check:BE.bn_check_mod_exp_st t len
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_exp_safe_st t len
let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res =
let h0 = ST.get () in
let is_valid_m = exp_check n a bBits b in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_exp nBits n a bBits b res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_inv_prime_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> res:lbignum t len ->
Stack bool
(requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\
(r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1))
inline_for_extraction noextract
val mk_bn_mod_inv_prime_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_inv_prime_safe_st t len
let mk_bn_mod_inv_prime_safe #t len bn_mod_exp n a res =
let h0 = ST.get () in
let is_valid_m = BI.bn_check_mod_inv_prime #t len n a in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
BI.mk_bn_mod_inv_prime len bn_mod_exp nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_slow_ctx_st (t:limb_t) (len:BN.meta_len t) =
k:MA.pbn_mont_ctx t
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).MA.len == len /\
MA.pbn_mont_ctx_inv h k /\
live h a /\ live h res /\ disjoint res a /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
bn_v h1 res == bn_v h0 a % MA.bn_v_n h0 k)
inline_for_extraction noextract
val bn_mod_ctx:
#t:limb_t
-> len:Ghost.erased _
-> bn_mod_slow_precomp:BR.bn_mod_slow_precomp_st t len ->
bn_mod_slow_ctx_st t len
let bn_mod_ctx #t len bn_mod_slow_precomp k a res =
let open LowStar.BufferOps in
let k1 = !*k in
bn_mod_slow_precomp k1.MA.n k1.MA.mu k1.MA.r2 a res
inline_for_extraction noextract
let bn_mod_exp_ctx_st (t:limb_t) (len:BN.meta_len t) =
k:MA.pbn_mont_ctx t
-> a:lbignum t len
-> bBits:size_t
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).MA.len == len /\
MA.pbn_mont_ctx_inv h k /\
bn_v h a < MA.bn_v_n h k /\
bn_v h b < pow2 (v bBits) /\
live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
SE.bn_mod_exp_post (as_seq #MUT #(limb t) h0 (B.deref h0 k).MA.n)
(as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))
inline_for_extraction noextract
val mk_bn_mod_exp_ctx:
#t:limb_t
-> len:Ghost.erased _
-> bn_mod_exp_precomp:BE.bn_mod_exp_precomp_st t len ->
bn_mod_exp_ctx_st t len
let mk_bn_mod_exp_ctx #t len bn_mod_exp_precomp k a bBits b res =
let open LowStar.BufferOps in
let k1 = !*k in
bn_mod_exp_precomp k1.MA.n k1.MA.mu k1.MA.r2 a bBits b res
inline_for_extraction noextract
let bn_mod_inv_prime_ctx_st (t:limb_t) (len:BN.meta_len t) =
k:MA.pbn_mont_ctx t
-> a:lbignum t len
-> res:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).MA.len == len /\
MA.pbn_mont_ctx_inv h k /\
0 < bn_v h a /\ bn_v h a < MA.bn_v_n h k /\
FStar.Math.Euclid.is_prime (MA.bn_v_n h k) /\
live h a /\ live h res /\ disjoint res a /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t)))))
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
bn_v h1 res * bn_v h0 a % MA.bn_v_n h0 k = 1)
inline_for_extraction noextract
val mk_bn_mod_inv_prime_ctx:
#t:limb_t
-> len:Ghost.erased _
-> bn_mod_inv_precomp:BI.bn_mod_inv_prime_precomp_st t len ->
bn_mod_inv_prime_ctx_st t len | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.ModInv.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.ModReduction.fst.checked",
"Hacl.Bignum.ModInv.fst.checked",
"Hacl.Bignum.Lib.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.SafeAPI.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.ModInv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Convert",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModReduction",
"short_module": "BR"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: FStar.Ghost.erased (Hacl.Bignum.meta_len t) ->
bn_mod_inv_precomp: Hacl.Bignum.ModInv.bn_mod_inv_prime_precomp_st t (FStar.Ghost.reveal len)
-> Hacl.Bignum.SafeAPI.bn_mod_inv_prime_ctx_st t (FStar.Ghost.reveal len) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"FStar.Ghost.erased",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.ModInv.bn_mod_inv_prime_precomp_st",
"FStar.Ghost.reveal",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__n",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__mu",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__r2",
"Prims.unit",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.BufferOps.op_Bang_Star",
"LowStar.Buffer.trivial_preorder"
] | [] | false | false | false | false | false | let mk_bn_mod_inv_prime_ctx #t len bn_mod_inv_precomp k a res =
| let open LowStar.BufferOps in
let k1 = !*k in
bn_mod_inv_precomp k1.MA.n k1.MA.mu k1.MA.r2 a res | false |
Hacl.Bignum.SafeAPI.fst | Hacl.Bignum.SafeAPI.bn_mod_inv_prime_ctx_st | val bn_mod_inv_prime_ctx_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | let bn_mod_inv_prime_ctx_st (t:limb_t) (len:BN.meta_len t) =
k:MA.pbn_mont_ctx t
-> a:lbignum t len
-> res:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).MA.len == len /\
MA.pbn_mont_ctx_inv h k /\
0 < bn_v h a /\ bn_v h a < MA.bn_v_n h k /\
FStar.Math.Euclid.is_prime (MA.bn_v_n h k) /\
live h a /\ live h res /\ disjoint res a /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t)))))
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
bn_v h1 res * bn_v h0 a % MA.bn_v_n h0 k = 1) | {
"file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 311,
"start_col": 0,
"start_line": 296
} | module Hacl.Bignum.SafeAPI
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module E = Hacl.Spec.Exponentiation.Lemmas
module BL = Hacl.Bignum.Lib
module BB = Hacl.Bignum.Base
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
module BM = Hacl.Bignum.Montgomery
module BE = Hacl.Bignum.Exponentiation
module BR = Hacl.Bignum.ModReduction
module BC = Hacl.Bignum.Convert
module BI = Hacl.Bignum.ModInv
module SL = Hacl.Spec.Bignum.Lib
module SD = Hacl.Spec.Bignum.Definitions
module SE = Hacl.Spec.Bignum.Exponentiation
module SM = Hacl.Spec.Bignum.Montgomery
module SC = Hacl.Spec.Bignum.Convert
module SI = Hacl.Spec.Bignum.ModInv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let new_bn_from_bytes_be_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
let new_bn_from_bytes_be #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_be false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let new_bn_from_bytes_le_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t
let new_bn_from_bytes_le #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_le false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\
(r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n))
inline_for_extraction noextract
val mk_bn_mod_slow_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_slow:BR.bn_mod_slow_st t len ->
bn_mod_slow_safe_st t len
let mk_bn_mod_slow_safe #t len bn_mod_slow n a res =
let h0 = ST.get () in
let is_valid_m = BM.bn_check_modulus n in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_slow nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t}
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\
(r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)))
inline_for_extraction noextract
val mk_bn_mod_exp_safe:
#t:limb_t
-> len:BN.meta_len t
-> exp_check:BE.bn_check_mod_exp_st t len
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_exp_safe_st t len
let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res =
let h0 = ST.get () in
let is_valid_m = exp_check n a bBits b in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_exp nBits n a bBits b res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_inv_prime_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> res:lbignum t len ->
Stack bool
(requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\
(r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1))
inline_for_extraction noextract
val mk_bn_mod_inv_prime_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_inv_prime_safe_st t len
let mk_bn_mod_inv_prime_safe #t len bn_mod_exp n a res =
let h0 = ST.get () in
let is_valid_m = BI.bn_check_mod_inv_prime #t len n a in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
BI.mk_bn_mod_inv_prime len bn_mod_exp nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_slow_ctx_st (t:limb_t) (len:BN.meta_len t) =
k:MA.pbn_mont_ctx t
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).MA.len == len /\
MA.pbn_mont_ctx_inv h k /\
live h a /\ live h res /\ disjoint res a /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
bn_v h1 res == bn_v h0 a % MA.bn_v_n h0 k)
inline_for_extraction noextract
val bn_mod_ctx:
#t:limb_t
-> len:Ghost.erased _
-> bn_mod_slow_precomp:BR.bn_mod_slow_precomp_st t len ->
bn_mod_slow_ctx_st t len
let bn_mod_ctx #t len bn_mod_slow_precomp k a res =
let open LowStar.BufferOps in
let k1 = !*k in
bn_mod_slow_precomp k1.MA.n k1.MA.mu k1.MA.r2 a res
inline_for_extraction noextract
let bn_mod_exp_ctx_st (t:limb_t) (len:BN.meta_len t) =
k:MA.pbn_mont_ctx t
-> a:lbignum t len
-> bBits:size_t
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).MA.len == len /\
MA.pbn_mont_ctx_inv h k /\
bn_v h a < MA.bn_v_n h k /\
bn_v h b < pow2 (v bBits) /\
live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
SE.bn_mod_exp_post (as_seq #MUT #(limb t) h0 (B.deref h0 k).MA.n)
(as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))
inline_for_extraction noextract
val mk_bn_mod_exp_ctx:
#t:limb_t
-> len:Ghost.erased _
-> bn_mod_exp_precomp:BE.bn_mod_exp_precomp_st t len ->
bn_mod_exp_ctx_st t len
let mk_bn_mod_exp_ctx #t len bn_mod_exp_precomp k a bBits b res =
let open LowStar.BufferOps in
let k1 = !*k in
bn_mod_exp_precomp k1.MA.n k1.MA.mu k1.MA.r2 a bBits b res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.ModInv.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.ModReduction.fst.checked",
"Hacl.Bignum.ModInv.fst.checked",
"Hacl.Bignum.Lib.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.SafeAPI.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.ModInv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Convert",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModReduction",
"short_module": "BR"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.lbignum",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Prims.eq2",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__len",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"LowStar.Monotonic.Buffer.deref",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.Buffer.trivial_preorder",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx_inv",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.bn_v",
"Hacl.Bignum.MontArithmetic.bn_v_n",
"FStar.Math.Euclid.is_prime",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Hacl.Bignum.MontArithmetic.footprint",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Buffer.buffer",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"FStar.Mul.op_Star"
] | [] | false | false | false | false | true | let bn_mod_inv_prime_ctx_st (t: limb_t) (len: BN.meta_len t) =
| k: MA.pbn_mont_ctx t -> a: lbignum t len -> res: lbignum t len
-> Stack unit
(requires
fun h ->
(B.deref h k).MA.len == len /\ MA.pbn_mont_ctx_inv h k /\ 0 < bn_v h a /\
bn_v h a < MA.bn_v_n h k /\ FStar.Math.Euclid.is_prime (MA.bn_v_n h k) /\ live h a /\
live h res /\ disjoint res a /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (a <: buffer (limb t)))) /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t)))))
(ensures
fun h0 r h1 -> modifies (loc res) h0 h1 /\ bn_v h1 res * bn_v h0 a % MA.bn_v_n h0 k = 1) | false |
|
Hacl.Bignum.SafeAPI.fst | Hacl.Bignum.SafeAPI.new_bn_from_bytes_be_st | val new_bn_from_bytes_be_st : t: Hacl.Bignum.Definitions.limb_t -> Type0 | let new_bn_from_bytes_be_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b))) | {
"file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 114,
"end_line": 53,
"start_col": 0,
"start_line": 38
} | module Hacl.Bignum.SafeAPI
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module E = Hacl.Spec.Exponentiation.Lemmas
module BL = Hacl.Bignum.Lib
module BB = Hacl.Bignum.Base
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
module BM = Hacl.Bignum.Montgomery
module BE = Hacl.Bignum.Exponentiation
module BR = Hacl.Bignum.ModReduction
module BC = Hacl.Bignum.Convert
module BI = Hacl.Bignum.ModInv
module SL = Hacl.Spec.Bignum.Lib
module SD = Hacl.Spec.Bignum.Definitions
module SE = Hacl.Spec.Bignum.Exponentiation
module SM = Hacl.Spec.Bignum.Montgomery
module SC = Hacl.Spec.Bignum.Convert
module SI = Hacl.Spec.Bignum.ModInv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.ModInv.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.ModReduction.fst.checked",
"Hacl.Bignum.ModInv.fst.checked",
"Hacl.Bignum.Lib.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.SafeAPI.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.ModInv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Convert",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModReduction",
"short_module": "BR"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Hacl.Bignum.Definitions.limb_t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"FStar.Monotonic.HyperHeap.rid",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"LowStar.Buffer.buffer",
"Hacl.Bignum.Definitions.limb",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"FStar.HyperStack.ST.is_eternal_region",
"Prims.l_imp",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.b2t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.Buffer.trivial_preorder",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Bignum.Definitions.blocks",
"Lib.IntTypes.size",
"Lib.IntTypes.max_size_t",
"Prims.eq2",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.len",
"LowStar.Monotonic.Buffer.fresh_loc",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Monotonic.Buffer.loc_includes",
"LowStar.Monotonic.Buffer.loc_region_only",
"Lib.Sequence.seq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Hacl.Spec.Bignum.Definitions.blocks",
"Lib.Buffer.as_seq",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Convert.bn_from_bytes_be"
] | [] | false | false | false | true | true | let new_bn_from_bytes_be_st (t: limb_t) =
| r: HS.rid -> len: size_t -> b: lbuffer uint8 len
-> ST (B.buffer (limb t))
(requires fun h -> live h b /\ ST.is_eternal_region r)
(ensures
fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==>
(0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) ==
SC.bn_from_bytes_be (v len) (as_seq h0 b))) | false |
|
Hacl.Bignum.SafeAPI.fst | Hacl.Bignum.SafeAPI.new_bn_from_bytes_le | val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t | val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t | let new_bn_from_bytes_le #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_le false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res | {
"file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 9,
"end_line": 122,
"start_col": 0,
"start_line": 102
} | module Hacl.Bignum.SafeAPI
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module E = Hacl.Spec.Exponentiation.Lemmas
module BL = Hacl.Bignum.Lib
module BB = Hacl.Bignum.Base
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
module BM = Hacl.Bignum.Montgomery
module BE = Hacl.Bignum.Exponentiation
module BR = Hacl.Bignum.ModReduction
module BC = Hacl.Bignum.Convert
module BI = Hacl.Bignum.ModInv
module SL = Hacl.Spec.Bignum.Lib
module SD = Hacl.Spec.Bignum.Definitions
module SE = Hacl.Spec.Bignum.Exponentiation
module SM = Hacl.Spec.Bignum.Montgomery
module SC = Hacl.Spec.Bignum.Convert
module SI = Hacl.Spec.Bignum.ModInv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let new_bn_from_bytes_be_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
let new_bn_from_bytes_be #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_be false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let new_bn_from_bytes_le_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b)))
inline_for_extraction noextract | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.ModInv.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.ModReduction.fst.checked",
"Hacl.Bignum.ModInv.fst.checked",
"Hacl.Bignum.Lib.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.SafeAPI.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.ModInv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Convert",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModReduction",
"short_module": "BR"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Bignum.SafeAPI.new_bn_from_bytes_le_st t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"FStar.Monotonic.HyperHeap.rid",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.op_BarBar",
"Prims.op_Equality",
"FStar.UInt32.t",
"FStar.UInt32.__uint_to_t",
"Prims.op_Negation",
"Lib.IntTypes.op_Less_Equals_Dot",
"Lib.IntTypes.U32",
"Hacl.Bignum.Definitions.blocks",
"FStar.UInt32.div",
"LowStar.Buffer.null",
"Hacl.Bignum.Definitions.limb",
"LowStar.Buffer.buffer",
"Prims.bool",
"Prims.unit",
"LowStar.Monotonic.Buffer.modifies_only_not_unused_in",
"LowStar.Monotonic.Buffer.loc_none",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Bignum.Convert.mk_bn_from_bytes_le",
"Hacl.Bignum.Definitions.lbignum",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.v",
"Lib.Buffer.buffer_t",
"Lib.Buffer.MUT",
"LowStar.Monotonic.Buffer.len",
"LowStar.Monotonic.Buffer.is_null",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.l_imp",
"LowStar.Monotonic.Buffer.g_is_null",
"Prims.l_and",
"Prims.nat",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.Monotonic.Buffer.freeable",
"LowStar.Monotonic.Buffer.mmalloc_partial",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"LowStar.Monotonic.Buffer.lmbuffer_or_null",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"Lib.IntTypes.size",
"Lib.IntTypes.numbytes"
] | [] | false | false | false | false | false | let new_bn_from_bytes_le #t r len b =
| [@@ inline_let ]let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb)
then B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res
then res
else
let h1 = ST.get () in
(let open B in modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res:Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res:lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_le false len b res;
let h2 = ST.get () in
(let open B in modifies_only_not_unused_in loc_none h0 h2);
res | false |
Hacl.Bignum.SafeAPI.fst | Hacl.Bignum.SafeAPI.bn_mod_exp_safe_st | val bn_mod_exp_safe_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t}
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\
(r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))) | {
"file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 99,
"end_line": 172,
"start_col": 0,
"start_line": 160
} | module Hacl.Bignum.SafeAPI
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module E = Hacl.Spec.Exponentiation.Lemmas
module BL = Hacl.Bignum.Lib
module BB = Hacl.Bignum.Base
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
module BM = Hacl.Bignum.Montgomery
module BE = Hacl.Bignum.Exponentiation
module BR = Hacl.Bignum.ModReduction
module BC = Hacl.Bignum.Convert
module BI = Hacl.Bignum.ModInv
module SL = Hacl.Spec.Bignum.Lib
module SD = Hacl.Spec.Bignum.Definitions
module SE = Hacl.Spec.Bignum.Exponentiation
module SM = Hacl.Spec.Bignum.Montgomery
module SC = Hacl.Spec.Bignum.Convert
module SI = Hacl.Spec.Bignum.ModInv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let new_bn_from_bytes_be_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
let new_bn_from_bytes_be #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_be false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let new_bn_from_bytes_le_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t
let new_bn_from_bytes_le #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_le false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\
(r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n))
inline_for_extraction noextract
val mk_bn_mod_slow_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_slow:BR.bn_mod_slow_st t len ->
bn_mod_slow_safe_st t len
let mk_bn_mod_slow_safe #t len bn_mod_slow n a res =
let h0 = ST.get () in
let is_valid_m = BM.bn_check_modulus n in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_slow nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.ModInv.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.ModReduction.fst.checked",
"Hacl.Bignum.ModInv.fst.checked",
"Hacl.Bignum.Lib.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.SafeAPI.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.ModInv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Convert",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModReduction",
"short_module": "BR"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.bits",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Lib.IntTypes.max_size_t",
"Prims.bool",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Hacl.Spec.Bignum.Base.unsafe_bool_of_limb",
"Hacl.Spec.Bignum.Exponentiation.bn_check_mod_exp",
"Lib.Buffer.as_seq",
"Prims.l_imp",
"Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_post"
] | [] | false | false | false | false | true | let bn_mod_exp_safe_st (t: limb_t) (len: BN.meta_len t) =
|
n: lbignum t len ->
a: lbignum t len ->
bBits: size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t} ->
b: lbignum t (blocks0 bBits (size (bits t))) ->
res: lbignum t len
-> Stack bool
(requires
fun h ->
live h n /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\
disjoint res n /\ disjoint n a)
(ensures
fun h0 r h1 ->
modifies (loc res) h0 h1 /\
r ==
BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n)
(as_seq h0 a)
(v bBits)
(as_seq h0 b)) /\
(r ==>
SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))) | false |
|
Hacl.Bignum.SafeAPI.fst | Hacl.Bignum.SafeAPI.new_bn_from_bytes_le_st | val new_bn_from_bytes_le_st : t: Hacl.Bignum.Definitions.limb_t -> Type0 | let new_bn_from_bytes_le_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b))) | {
"file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 114,
"end_line": 97,
"start_col": 0,
"start_line": 82
} | module Hacl.Bignum.SafeAPI
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module E = Hacl.Spec.Exponentiation.Lemmas
module BL = Hacl.Bignum.Lib
module BB = Hacl.Bignum.Base
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
module BM = Hacl.Bignum.Montgomery
module BE = Hacl.Bignum.Exponentiation
module BR = Hacl.Bignum.ModReduction
module BC = Hacl.Bignum.Convert
module BI = Hacl.Bignum.ModInv
module SL = Hacl.Spec.Bignum.Lib
module SD = Hacl.Spec.Bignum.Definitions
module SE = Hacl.Spec.Bignum.Exponentiation
module SM = Hacl.Spec.Bignum.Montgomery
module SC = Hacl.Spec.Bignum.Convert
module SI = Hacl.Spec.Bignum.ModInv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let new_bn_from_bytes_be_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
let new_bn_from_bytes_be #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_be false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.ModInv.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.ModReduction.fst.checked",
"Hacl.Bignum.ModInv.fst.checked",
"Hacl.Bignum.Lib.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.SafeAPI.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.ModInv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Convert",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModReduction",
"short_module": "BR"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Hacl.Bignum.Definitions.limb_t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"FStar.Monotonic.HyperHeap.rid",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"LowStar.Buffer.buffer",
"Hacl.Bignum.Definitions.limb",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"FStar.HyperStack.ST.is_eternal_region",
"Prims.l_imp",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.b2t",
"Prims.op_Negation",
"LowStar.Monotonic.Buffer.g_is_null",
"LowStar.Buffer.trivial_preorder",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.numbytes",
"Hacl.Bignum.Definitions.blocks",
"Lib.IntTypes.size",
"Lib.IntTypes.max_size_t",
"Prims.eq2",
"FStar.UInt32.t",
"LowStar.Monotonic.Buffer.len",
"LowStar.Monotonic.Buffer.fresh_loc",
"LowStar.Monotonic.Buffer.loc_buffer",
"LowStar.Monotonic.Buffer.loc_includes",
"LowStar.Monotonic.Buffer.loc_region_only",
"Lib.Sequence.seq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Hacl.Spec.Bignum.Definitions.blocks",
"Lib.Buffer.as_seq",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Convert.bn_from_bytes_le"
] | [] | false | false | false | true | true | let new_bn_from_bytes_le_st (t: limb_t) =
| r: HS.rid -> len: size_t -> b: lbuffer uint8 len
-> ST (B.buffer (limb t))
(requires fun h -> live h b /\ ST.is_eternal_region r)
(ensures
fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\ not (B.g_is_null res) ==>
(0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\ B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) ==
SC.bn_from_bytes_le (v len) (as_seq h0 b))) | false |
|
Hacl.Bignum.SafeAPI.fst | Hacl.Bignum.SafeAPI.bn_mod_inv_prime_safe_st | val bn_mod_inv_prime_safe_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | let bn_mod_inv_prime_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> res:lbignum t len ->
Stack bool
(requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\
(r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1)) | {
"file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 207,
"start_col": 0,
"start_line": 197
} | module Hacl.Bignum.SafeAPI
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module E = Hacl.Spec.Exponentiation.Lemmas
module BL = Hacl.Bignum.Lib
module BB = Hacl.Bignum.Base
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
module BM = Hacl.Bignum.Montgomery
module BE = Hacl.Bignum.Exponentiation
module BR = Hacl.Bignum.ModReduction
module BC = Hacl.Bignum.Convert
module BI = Hacl.Bignum.ModInv
module SL = Hacl.Spec.Bignum.Lib
module SD = Hacl.Spec.Bignum.Definitions
module SE = Hacl.Spec.Bignum.Exponentiation
module SM = Hacl.Spec.Bignum.Montgomery
module SC = Hacl.Spec.Bignum.Convert
module SI = Hacl.Spec.Bignum.ModInv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let new_bn_from_bytes_be_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
let new_bn_from_bytes_be #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_be false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let new_bn_from_bytes_le_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t
let new_bn_from_bytes_le #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_le false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\
(r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n))
inline_for_extraction noextract
val mk_bn_mod_slow_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_slow:BR.bn_mod_slow_st t len ->
bn_mod_slow_safe_st t len
let mk_bn_mod_slow_safe #t len bn_mod_slow n a res =
let h0 = ST.get () in
let is_valid_m = BM.bn_check_modulus n in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_slow nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t}
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\
(r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)))
inline_for_extraction noextract
val mk_bn_mod_exp_safe:
#t:limb_t
-> len:BN.meta_len t
-> exp_check:BE.bn_check_mod_exp_st t len
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_exp_safe_st t len
let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res =
let h0 = ST.get () in
let is_valid_m = exp_check n a bBits b in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_exp nBits n a bBits b res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.ModInv.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.ModReduction.fst.checked",
"Hacl.Bignum.ModInv.fst.checked",
"Hacl.Bignum.Lib.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.SafeAPI.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.ModInv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Convert",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModReduction",
"short_module": "BR"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.Definitions.lbignum",
"Prims.bool",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"FStar.Math.Euclid.is_prime",
"Hacl.Bignum.Definitions.bn_v",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Hacl.Spec.Bignum.Base.unsafe_bool_of_limb",
"Hacl.Spec.Bignum.ModInv.bn_check_mod_inv_prime",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.as_seq",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"FStar.Mul.op_Star"
] | [] | false | false | false | false | true | let bn_mod_inv_prime_safe_st (t: limb_t) (len: BN.meta_len t) =
| n: lbignum t len -> a: lbignum t len -> res: lbignum t len
-> Stack bool
(requires
fun h ->
FStar.Math.Euclid.is_prime (bn_v h n) /\ live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a /\ disjoint n a)
(ensures
fun h0 r h1 ->
modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\
(r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1)) | false |
|
Hacl.Bignum.SafeAPI.fst | Hacl.Bignum.SafeAPI.bn_mod_ctx | val bn_mod_ctx:
#t:limb_t
-> len:Ghost.erased _
-> bn_mod_slow_precomp:BR.bn_mod_slow_precomp_st t len ->
bn_mod_slow_ctx_st t len | val bn_mod_ctx:
#t:limb_t
-> len:Ghost.erased _
-> bn_mod_slow_precomp:BR.bn_mod_slow_precomp_st t len ->
bn_mod_slow_ctx_st t len | let bn_mod_ctx #t len bn_mod_slow_precomp k a res =
let open LowStar.BufferOps in
let k1 = !*k in
bn_mod_slow_precomp k1.MA.n k1.MA.mu k1.MA.r2 a res | {
"file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 256,
"start_col": 0,
"start_line": 253
} | module Hacl.Bignum.SafeAPI
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module E = Hacl.Spec.Exponentiation.Lemmas
module BL = Hacl.Bignum.Lib
module BB = Hacl.Bignum.Base
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
module BM = Hacl.Bignum.Montgomery
module BE = Hacl.Bignum.Exponentiation
module BR = Hacl.Bignum.ModReduction
module BC = Hacl.Bignum.Convert
module BI = Hacl.Bignum.ModInv
module SL = Hacl.Spec.Bignum.Lib
module SD = Hacl.Spec.Bignum.Definitions
module SE = Hacl.Spec.Bignum.Exponentiation
module SM = Hacl.Spec.Bignum.Montgomery
module SC = Hacl.Spec.Bignum.Convert
module SI = Hacl.Spec.Bignum.ModInv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let new_bn_from_bytes_be_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t
let new_bn_from_bytes_be #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_be false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let new_bn_from_bytes_le_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_le (v len) (as_seq h0 b)))
inline_for_extraction noextract
val new_bn_from_bytes_le: #t:limb_t -> new_bn_from_bytes_le_st t
let new_bn_from_bytes_le #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_le false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res
inline_for_extraction noextract
let bn_mod_slow_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SM.bn_check_modulus (as_seq h0 n)) /\
(r ==> bn_v h1 res == bn_v h0 a % bn_v h0 n))
inline_for_extraction noextract
val mk_bn_mod_slow_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_slow:BR.bn_mod_slow_st t len ->
bn_mod_slow_safe_st t len
let mk_bn_mod_slow_safe #t len bn_mod_slow n a res =
let h0 = ST.get () in
let is_valid_m = BM.bn_check_modulus n in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_slow nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_exp_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t}
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack bool
(requires fun h ->
live h n /\ live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SE.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) /\
(r ==> SE.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)))
inline_for_extraction noextract
val mk_bn_mod_exp_safe:
#t:limb_t
-> len:BN.meta_len t
-> exp_check:BE.bn_check_mod_exp_st t len
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_exp_safe_st t len
let mk_bn_mod_exp_safe #t len exp_check bn_mod_exp n a bBits b res =
let h0 = ST.get () in
let is_valid_m = exp_check n a bBits b in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
bn_mod_exp nBits n a bBits b res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_inv_prime_safe_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> res:lbignum t len ->
Stack bool
(requires fun h -> FStar.Math.Euclid.is_prime (bn_v h n) /\
live h n /\ live h a /\ live h res /\
disjoint res n /\ disjoint res a /\ disjoint n a)
(ensures fun h0 r h1 -> modifies (loc res) h0 h1 /\
r == BB.unsafe_bool_of_limb (SI.bn_check_mod_inv_prime (as_seq h0 n) (as_seq h0 a)) /\
(r ==> bn_v h1 res * bn_v h0 a % bn_v h0 n = 1))
inline_for_extraction noextract
val mk_bn_mod_inv_prime_safe:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_exp:BE.bn_mod_exp_st t len ->
bn_mod_inv_prime_safe_st t len
let mk_bn_mod_inv_prime_safe #t len bn_mod_exp n a res =
let h0 = ST.get () in
let is_valid_m = BI.bn_check_mod_inv_prime #t len n a in
let nBits = size (bits t) *! BB.unsafe_size_from_limb (BL.bn_get_top_index len n) in
if BB.unsafe_bool_of_limb is_valid_m then begin
SL.bn_low_bound_bits_lemma #t #(v len) (as_seq h0 n);
BI.mk_bn_mod_inv_prime len bn_mod_exp nBits n a res end
else
memset res (uint #t 0) len;
BB.unsafe_bool_of_limb is_valid_m
inline_for_extraction noextract
let bn_mod_slow_ctx_st (t:limb_t) (len:BN.meta_len t) =
k:MA.pbn_mont_ctx t
-> a:lbignum t (len +! len)
-> res:lbignum t len ->
Stack unit
(requires fun h ->
(B.deref h k).MA.len == len /\
MA.pbn_mont_ctx_inv h k /\
live h a /\ live h res /\ disjoint res a /\
B.(loc_disjoint (MA.footprint h k) (loc_buffer (res <: buffer (limb t)))))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
bn_v h1 res == bn_v h0 a % MA.bn_v_n h0 k)
inline_for_extraction noextract
val bn_mod_ctx:
#t:limb_t
-> len:Ghost.erased _
-> bn_mod_slow_precomp:BR.bn_mod_slow_precomp_st t len ->
bn_mod_slow_ctx_st t len | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.ModInv.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.ModReduction.fst.checked",
"Hacl.Bignum.ModInv.fst.checked",
"Hacl.Bignum.Lib.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.SafeAPI.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.ModInv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Convert",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModReduction",
"short_module": "BR"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: FStar.Ghost.erased (Hacl.Bignum.meta_len t) ->
bn_mod_slow_precomp: Hacl.Bignum.ModReduction.bn_mod_slow_precomp_st t (FStar.Ghost.reveal len)
-> Hacl.Bignum.SafeAPI.bn_mod_slow_ctx_st t (FStar.Ghost.reveal len) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"FStar.Ghost.erased",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.ModReduction.bn_mod_slow_precomp_st",
"FStar.Ghost.reveal",
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.op_Plus_Bang",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__n",
"Hacl.Bignum.MontArithmetic.lb",
"Hacl.Bignum.MontArithmetic.ll",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__mu",
"Hacl.Bignum.MontArithmetic.__proj__Mkbn_mont_ctx'__item__r2",
"Prims.unit",
"Hacl.Bignum.MontArithmetic.bn_mont_ctx",
"LowStar.BufferOps.op_Bang_Star",
"LowStar.Buffer.trivial_preorder"
] | [] | false | false | false | false | false | let bn_mod_ctx #t len bn_mod_slow_precomp k a res =
| let open LowStar.BufferOps in
let k1 = !*k in
bn_mod_slow_precomp k1.MA.n k1.MA.mu k1.MA.r2 a res | false |
Hacl.Bignum.SafeAPI.fst | Hacl.Bignum.SafeAPI.new_bn_from_bytes_be | val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t | val new_bn_from_bytes_be: #t:limb_t -> new_bn_from_bytes_be_st t | let new_bn_from_bytes_be #t r len b =
[@inline_let]
let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb) then
B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res then
res
else
let h1 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res: Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res: lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_be false len b res;
let h2 = ST.get () in
B.(modifies_only_not_unused_in loc_none h0 h2);
res | {
"file_name": "code/bignum/Hacl.Bignum.SafeAPI.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 9,
"end_line": 78,
"start_col": 0,
"start_line": 58
} | module Hacl.Bignum.SafeAPI
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module LSeq = Lib.Sequence
module E = Hacl.Spec.Exponentiation.Lemmas
module BL = Hacl.Bignum.Lib
module BB = Hacl.Bignum.Base
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
module BM = Hacl.Bignum.Montgomery
module BE = Hacl.Bignum.Exponentiation
module BR = Hacl.Bignum.ModReduction
module BC = Hacl.Bignum.Convert
module BI = Hacl.Bignum.ModInv
module SL = Hacl.Spec.Bignum.Lib
module SD = Hacl.Spec.Bignum.Definitions
module SE = Hacl.Spec.Bignum.Exponentiation
module SM = Hacl.Spec.Bignum.Montgomery
module SC = Hacl.Spec.Bignum.Convert
module SI = Hacl.Spec.Bignum.ModInv
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let new_bn_from_bytes_be_st (t:limb_t) =
r:HS.rid
-> len:size_t
-> b:lbuffer uint8 len ->
ST (B.buffer (limb t))
(requires fun h ->
live h b /\
ST.is_eternal_region r)
(ensures fun h0 res h1 ->
B.(modifies loc_none h0 h1) /\
not (B.g_is_null res) ==> (
0 < v len /\ numbytes t * v (blocks len (size (numbytes t))) <= max_size_t /\
B.len res == blocks len (size (numbytes t)) /\
B.(fresh_loc (loc_buffer res) h0 h1) /\
B.(loc_includes (loc_region_only false r) (loc_buffer res)) /\
as_seq h1 (res <: lbignum t (blocks len (size (numbytes t)))) == SC.bn_from_bytes_be (v len) (as_seq h0 b)))
inline_for_extraction noextract | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.ModInv.fst.checked",
"Hacl.Spec.Bignum.Lib.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Convert.fst.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.ModReduction.fst.checked",
"Hacl.Bignum.ModInv.fst.checked",
"Hacl.Bignum.Lib.fst.checked",
"Hacl.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Convert.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Euclid.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.SafeAPI.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.ModInv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Convert",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModInv",
"short_module": "BI"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Convert",
"short_module": "BC"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.ModReduction",
"short_module": "BR"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Lib",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Bignum.SafeAPI.new_bn_from_bytes_be_st t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"FStar.Monotonic.HyperHeap.rid",
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"Prims.op_BarBar",
"Prims.op_Equality",
"FStar.UInt32.t",
"FStar.UInt32.__uint_to_t",
"Prims.op_Negation",
"Lib.IntTypes.op_Less_Equals_Dot",
"Lib.IntTypes.U32",
"Hacl.Bignum.Definitions.blocks",
"FStar.UInt32.div",
"LowStar.Buffer.null",
"Hacl.Bignum.Definitions.limb",
"LowStar.Buffer.buffer",
"Prims.bool",
"Prims.unit",
"LowStar.Monotonic.Buffer.modifies_only_not_unused_in",
"LowStar.Monotonic.Buffer.loc_none",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Bignum.Convert.mk_bn_from_bytes_be",
"Hacl.Bignum.Definitions.lbignum",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"LowStar.Monotonic.Buffer.length",
"LowStar.Buffer.trivial_preorder",
"FStar.UInt32.v",
"Lib.Buffer.buffer_t",
"Lib.Buffer.MUT",
"LowStar.Monotonic.Buffer.len",
"LowStar.Monotonic.Buffer.is_null",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.l_imp",
"LowStar.Monotonic.Buffer.g_is_null",
"Prims.l_and",
"Prims.nat",
"LowStar.Monotonic.Buffer.frameOf",
"LowStar.Monotonic.Buffer.freeable",
"LowStar.Monotonic.Buffer.mmalloc_partial",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"LowStar.Monotonic.Buffer.lmbuffer_or_null",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"Lib.IntTypes.size",
"Lib.IntTypes.numbytes"
] | [] | false | false | false | false | false | let new_bn_from_bytes_be #t r len b =
| [@@ inline_let ]let numb = size (numbytes t) in
if len = 0ul || not (blocks len numb <=. 0xfffffffful `FStar.UInt32.div` numb)
then B.null
else
let h0 = ST.get () in
let res = LowStar.Monotonic.Buffer.mmalloc_partial r (uint #t 0) (blocks len numb) in
if B.is_null res
then res
else
let h1 = ST.get () in
(let open B in modifies_only_not_unused_in loc_none h0 h1);
assert (B.len res == blocks len numb);
let res:Lib.Buffer.buffer (limb t) = res in
assert (B.length res == FStar.UInt32.v (blocks len numb));
let res:lbignum t (blocks len numb) = res in
BC.mk_bn_from_bytes_be false len b res;
let h2 = ST.get () in
(let open B in modifies_only_not_unused_in loc_none h0 h2);
res | false |
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.pad_to_128_bits_lower | val pad_to_128_bits_lower (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 8)
(ensures (let new_lo = (lo64 q) % pow2 (num_bytes * 8) in
new_lo < pow2_64 /\
(let q' = insert_nat64 (insert_nat64 q 0 1) new_lo 0 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes))))) | val pad_to_128_bits_lower (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 8)
(ensures (let new_lo = (lo64 q) % pow2 (num_bytes * 8) in
new_lo < pow2_64 /\
(let q' = insert_nat64 (insert_nat64 q 0 1) new_lo 0 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes))))) | let pad_to_128_bits_lower (q:quad32) (num_bytes:int) =
let n = num_bytes in
let new_lo = (lo64 q) % pow2 (n * 8) in
pow2_lt_compat 64 (n * 8);
let s = le_quad32_to_bytes q in
let s' = slice s 0 n in
let q' = insert_nat64_def (insert_nat64_def q 0 1) new_lo 0 in
insert_nat64_reveal ();
let s'' = pad_to_128_bits s' in
let q'' = le_bytes_to_quad32 s'' in
let s0_4 = slice s 0 4 in
let s4_8 = slice s 4 8 in
let s8_12 = slice s 8 12 in
let s12_16 = slice s 12 16 in
let s0_4'' = slice s'' 0 4 in
let s4_8'' = slice s'' 4 8 in
let s8_12'' = slice s'' 8 12 in
let s12_16'' = slice s'' 12 16 in
let Mkfour q0 q1 q2 q3 = q in
let Mkfour q0' q1' q2' q3' = q' in
let Mkfour q0'' q1'' q2'' q3'' = q'' in
if n < 4 then
(
lemma_mod_n_8_lower1 q n;
lemma_64_32_lo1 q' (lo64 q) new_lo n;
lemma_pad_to_32_bits s0_4 s0_4'' n;
()
)
else
(
lemma_mod_n_8_lower2 q (n - 4);
lemma_64_32_lo2 q' (lo64 q) new_lo (n - 4);
lemma_pad_to_32_bits s4_8 s4_8'' (n - 4);
()
);
lemma_slices_le_quad32_to_bytes q;
lemma_slices_le_bytes_to_quad32 s'';
lemma_four_zero ();
let zero_4 : seq nat8 = create 4 0 in
assert (n < 4 ==> equal s4_8'' zero_4);
assert (equal s8_12'' zero_4);
assert (equal s12_16'' zero_4);
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 470,
"start_col": 0,
"start_line": 423
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
)
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
()
(*
let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 16)
(ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes)))
=
()
let insert_0_is_padding (q:quad32) :
Lemma (let q' = insert_nat64_def q 0 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8)))
=
()
*)
#reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10"
let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) =
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert(i < 4 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4))) i))
(fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2");
assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4))
#reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1"
let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 2 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
assert (n == 0 \/ n == 1 \/ n == 2);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1);
assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100);
assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000);
()
let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 4 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else
assert (n == 3 \/ n == 4);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000);
assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000);
()
let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in
assert_norm (f 0);
assert_norm (f 1);
assert_norm (f 2);
assert_norm (f 3);
assert_norm (f 4);
()
let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma
(requires n <= 2)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 2);
assert_norm (f 1);
assert_norm (f 0);
()
let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
if n <= 2 then lemma_mod_n_8_lower2_helper q n else
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 4);
assert_norm (f 3);
()
let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n
let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n)))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n
let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
lo' == lo % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)
)
(ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0)
=
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
()
let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
lo' == lo % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)
)
(ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0)
=
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (pow2 (5 * 8) == 0x10000000000);
assert_norm (pow2 (6 * 8) == 0x1000000000000);
assert_norm (pow2 (7 * 8) == 0x100000000000000);
assert_norm (pow2 (8 * 8) == 0x10000000000000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
()
let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
hi' == hi % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')
)
(ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0)
=
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi');
()
let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
hi' == hi % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')
)
(ensures hi' == q'.hi2 + 0x100000000 * q'.hi3)
=
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (pow2 (5 * 8) == 0x10000000000);
assert_norm (pow2 (6 * 8) == 0x1000000000000);
assert_norm (pow2 (7 * 8) == 0x100000000000000);
assert_norm (pow2 (8 * 8) == 0x10000000000000000);
assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi');
()
let lemma_slices_le_bytes_to_quad32 (s:seq16 nat8) : Lemma
(ensures (
let q = le_bytes_to_quad32 s in
q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\
q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\
q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\
q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16))
))
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
le_bytes_to_quad32_reveal ();
()
let lemma_four_zero (_:unit) : Lemma
(ensures four_to_nat 8 (seq_to_four_LE (create 4 0)) == 0)
=
let s = create 4 0 in
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32 -> num_bytes: Prims.int
-> FStar.Pervasives.Lemma (requires 1 <= num_bytes /\ num_bytes < 8)
(ensures
(let new_lo = Vale.Arch.Types.lo64 q % Prims.pow2 (num_bytes * 8) in
new_lo < Vale.Def.Words_s.pow2_64 /\
(let q' = Vale.Def.Types_s.insert_nat64 (Vale.Def.Types_s.insert_nat64 q 0 1) new_lo 0 in
q' ==
Vale.Def.Types_s.le_bytes_to_quad32 (Vale.AES.GCTR_s.pad_to_128_bits (FStar.Seq.Base.slice
(Vale.Def.Types_s.le_quad32_to_bytes q)
0
num_bytes))))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.int",
"Vale.Def.Types_s.nat32",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Def.Types_s.nat8",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"FStar.Seq.Base.create",
"Vale.AES.GCM_helpers.lemma_four_zero",
"Vale.AES.GCM_helpers.lemma_slices_le_bytes_to_quad32",
"Vale.AES.Types_helpers.lemma_slices_le_quad32_to_bytes",
"Vale.AES.GCM_helpers.lemma_pad_to_32_bits",
"Vale.AES.GCM_helpers.lemma_64_32_lo1",
"Vale.Arch.Types.lo64",
"Vale.AES.GCM_helpers.lemma_mod_n_8_lower1",
"Prims.bool",
"Prims.op_Subtraction",
"Vale.AES.GCM_helpers.lemma_64_32_lo2",
"Vale.AES.GCM_helpers.lemma_mod_n_8_lower2",
"FStar.Seq.Base.slice",
"Vale.Def.Types_s.le_bytes_to_quad32",
"Vale.AES.GCTR_s.pad_to_128_bits",
"Vale.Def.Types_s.insert_nat64_reveal",
"Vale.Def.Types_s.insert_nat64_def",
"Vale.Def.Types_s.le_quad32_to_bytes",
"FStar.Math.Lemmas.pow2_lt_compat",
"FStar.Mul.op_Star",
"Prims.op_Modulus",
"Prims.pow2"
] | [] | false | false | true | false | false | let pad_to_128_bits_lower (q: quad32) (num_bytes: int) =
| let n = num_bytes in
let new_lo = (lo64 q) % pow2 (n * 8) in
pow2_lt_compat 64 (n * 8);
let s = le_quad32_to_bytes q in
let s' = slice s 0 n in
let q' = insert_nat64_def (insert_nat64_def q 0 1) new_lo 0 in
insert_nat64_reveal ();
let s'' = pad_to_128_bits s' in
let q'' = le_bytes_to_quad32 s'' in
let s0_4 = slice s 0 4 in
let s4_8 = slice s 4 8 in
let s8_12 = slice s 8 12 in
let s12_16 = slice s 12 16 in
let s0_4'' = slice s'' 0 4 in
let s4_8'' = slice s'' 4 8 in
let s8_12'' = slice s'' 8 12 in
let s12_16'' = slice s'' 12 16 in
let Mkfour q0 q1 q2 q3 = q in
let Mkfour q0' q1' q2' q3' = q' in
let Mkfour q0'' q1'' q2'' q3'' = q'' in
if n < 4
then
(lemma_mod_n_8_lower1 q n;
lemma_64_32_lo1 q' (lo64 q) new_lo n;
lemma_pad_to_32_bits s0_4 s0_4'' n;
())
else
(lemma_mod_n_8_lower2 q (n - 4);
lemma_64_32_lo2 q' (lo64 q) new_lo (n - 4);
lemma_pad_to_32_bits s4_8 s4_8'' (n - 4);
());
lemma_slices_le_quad32_to_bytes q;
lemma_slices_le_bytes_to_quad32 s'';
lemma_four_zero ();
let zero_4:seq nat8 = create 4 0 in
assert (n < 4 ==> equal s4_8'' zero_4);
assert (equal s8_12'' zero_4);
assert (equal s12_16'' zero_4);
() | false |
Vale.AES.GCM_helpers.fst | Vale.AES.GCM_helpers.pad_to_128_bits_upper | val pad_to_128_bits_upper (q:quad32) (num_bytes:int) : Lemma
(requires 8 <= num_bytes /\ num_bytes < 16)
(ensures (let new_hi = (hi64 q) % pow2 ((num_bytes - 8) * 8) in
new_hi < pow2_64 /\
(let q' = insert_nat64 q new_hi 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes))))) | val pad_to_128_bits_upper (q:quad32) (num_bytes:int) : Lemma
(requires 8 <= num_bytes /\ num_bytes < 16)
(ensures (let new_hi = (hi64 q) % pow2 ((num_bytes - 8) * 8) in
new_hi < pow2_64 /\
(let q' = insert_nat64 q new_hi 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 num_bytes))))) | let pad_to_128_bits_upper (q:quad32) (num_bytes:int) =
let n = num_bytes in
let new_hi = (hi64 q) % pow2 ((n - 8) * 8) in
pow2_lt_compat 64 ((n - 8) * 8);
let s = le_quad32_to_bytes q in
let s' = slice s 0 n in
let q' = insert_nat64_def q new_hi 1 in
insert_nat64_reveal ();
let s'' = pad_to_128_bits s' in
let q'' = le_bytes_to_quad32 s'' in
let s0_4 = slice s 0 4 in
let s4_8 = slice s 4 8 in
let s8_12 = slice s 8 12 in
let s12_16 = slice s 12 16 in
let s0_4'' = slice s'' 0 4 in
let s4_8'' = slice s'' 4 8 in
let s8_12'' = slice s'' 8 12 in
let s12_16'' = slice s'' 12 16 in
let Mkfour q0 q1 q2 q3 = q in
let Mkfour q0' q1' q2' q3' = q' in
let Mkfour q0'' q1'' q2'' q3'' = q'' in
if n < 12 then
(
lemma_mod_n_8_upper1 q (n - 8);
lemma_64_32_hi1 q' (hi64 q) new_hi (n - 8);
lemma_pad_to_32_bits s8_12 s8_12'' (n - 8);
()
)
else
(
lemma_mod_n_8_upper2 q (n - 12);
lemma_64_32_hi2 q' (hi64 q) new_hi (n - 12);
lemma_pad_to_32_bits s12_16 s12_16'' (n - 12);
()
);
lemma_slices_le_quad32_to_bytes q;
lemma_slices_le_bytes_to_quad32 s'';
lemma_four_zero ();
let zero_4 : seq nat8 = create 4 0 in
assert (n < 12 ==> equal s12_16'' zero_4);
() | {
"file_name": "vale/code/crypto/aes/Vale.AES.GCM_helpers.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 517,
"start_col": 0,
"start_line": 472
} | module Vale.AES.GCM_helpers
open FStar.Tactics
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Mul
open FStar.Seq
open Vale.Def.Opaque_s
open Vale.Def.Words.Two_s
open Vale.Def.Words.Four_s
open Vale.AES.AES_s
open Vale.AES.GCTR_s
open FStar.Math.Lemmas
open Vale.Lib.Seqs
open Vale.AES.Types_helpers
let extra_bytes_helper (n:nat) : Lemma
(requires n % 16 <> 0)
(ensures bytes_to_quad_size n == n / 16 + 1)
=
()
#reset-options "--smtencoding.elim_box true --z3rlimit 25 --max_ifuel 1 --initial_fuel 0 --max_fuel 1"
let bytes_to_quad_size_no_extra_bytes num_bytes = ()
let no_extra_bytes_helper s num_bytes =
slice_length (le_seq_quad32_to_bytes s)
let le_seq_quad32_to_bytes_tail_prefix (s:seq quad32) (num_bytes:nat) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let final = index s num_blocks in
let x = slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes in
let x' = slice (le_quad32_to_bytes final) 0 num_extra in
le_seq_quad32_to_bytes_of_singleton final;
assert (le_quad32_to_bytes final == le_seq_quad32_to_bytes (create 1 final));
assert (equal (create 1 final) (slice s num_blocks (length s)));
assert (x' == slice (le_seq_quad32_to_bytes (slice s num_blocks (length s))) 0 num_extra);
slice_commutes_le_seq_quad32_to_bytes s num_blocks (length s);
assert (x' == slice (slice (le_seq_quad32_to_bytes s) (num_blocks * 16) (length s * 16)) 0 num_extra);
assert (x' == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes);
assert (equal x' x);
()
let index_helper (s:seq quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\
num_bytes < 16 * length s /\
16 * (length s - 1) < num_bytes /\
num_bytes % 16 <> 0 /\
length s == bytes_to_quad_size num_bytes)
(ensures (let num_blocks = num_bytes / 16 in
index s num_blocks == index (slice s 0 (bytes_to_quad_size num_bytes)) num_blocks))
=
()
let pad_to_128_bits_multiples (b:seq nat8) : Lemma
(let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes)
=
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
if length b < 16 then (
assert (full_bytes == empty);
assert (partial_bytes == b);
append_empty_l(pad_to_128_bits partial_bytes);
()
) else (
assert (length full_bytes + length partial_bytes == length b);
assert (length full_bytes % 16 == 0);
let num_extra_bytes = length b % 16 in
assert (num_extra_bytes == (length partial_bytes) % 16);
if num_extra_bytes = 0 then (
lemma_split b full_blocks;
assert (b == full_bytes @| partial_bytes);
()
) else (
let pad = create (16 - num_extra_bytes) 0 in
assert (equal (b @| pad) (full_bytes @| (partial_bytes @| pad)));
()
);
()
)
let pad_to_128_bits_le_quad32_to_bytes (s:seq quad32) (num_bytes:int) =
let num_extra = num_bytes % 16 in
let num_blocks = num_bytes / 16 in
let full_quads,final_quads = split s num_blocks in
assert(length final_quads == 1);
let final_quad = index final_quads 0 in
let b = slice (le_seq_quad32_to_bytes s) 0 num_bytes in
pad_to_128_bits_multiples b; // ==> pad_to_128_bits b == full_bytes @| pad_to_128_bits partial_bytes
let full_blocks = (length b) / 16 * 16 in
let full_bytes, partial_bytes = split b full_blocks in
// Need to show that full_bytes == le_seq_quad32_to_bytes full_quads
// Need to show that le_quad32_to_bytes final_quad == partial_bytes
// full_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) 0 full_blocks
// This should be from slice_slice
// == slice (le_seq_quad32_bot_bytes s) 0 full_blocks
// == slice (le_seq_quad32_bot_bytes s) 0 (num_blocks * 16)
// This follows from slice_commutes_le_seq_quad32_to_bytes0
// le_seq_quad32_to_bytes full_quads == le_seq_quad32_to_bytes (slice s 0 num_blocks)
slice_commutes_le_seq_quad32_to_bytes0 s num_blocks;
// ==>
(*
assert (slice (le_seq_quad32_to_bytes s) 0 (num_blocks * 16) ==
le_seq_quad32_to_bytes (slice s 0 num_blocks));
*)
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes 0 full_blocks;
assert (full_bytes == le_seq_quad32_to_bytes full_quads);
// slice (le_quad32_to_bytes final_quad) 0 num_extra == slice (le_quad32_to_bytes (index (slice s num_blocks (length s)) 0)) 0 num_extra
// F* believes assert (final_quad == index s num_blocks), so we have:
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
//
// == slice (le_quad32_to_bytes (index s num_blocks)) 0 num_extra
// from le_seq_quad32_to_bytes_tail_prefix
// == slice (le_seq_quad32_to_bytes s) (num_blocks * 16) num_bytes
// == slice (le_seq_quad32_to_bytes s) full_blocks num_bytes
// From slice_slice
// partial_bytes == slice (slice (le_seq_quad32_to_bytes s) 0 num_bytes) full_blocks num_bytes
slice_slice (le_seq_quad32_to_bytes s) 0 num_bytes full_blocks num_bytes;
le_seq_quad32_to_bytes_tail_prefix s num_bytes;
()
(*
let slice_le_quad32_to_bytes_is_mod (q:quad32) (num_bytes:int) : Lemma
(requires 1 <= num_bytes /\ num_bytes < 16)
(ensures four_to_nat 32 (slice (le_quad32_to_bytes q) 0 num_bytes) == (four_to_nat 32 q) % (pow2 (8*num_bytes)))
=
()
let insert_0_is_padding (q:quad32) :
Lemma (let q' = insert_nat64_def q 0 1 in
q' == le_bytes_to_quad32 (pad_to_128_bits (slice (le_quad32_to_bytes q) 0 8)))
=
()
*)
#reset-options "--z3cliopt smt.QI.EAGER_THRESHOLD=100 --z3cliopt smt.CASE_SPLIT=3 --z3cliopt smt.arith.nl=true --max_fuel 2 --initial_fuel 2 --max_ifuel 0 --smtencoding.elim_box true --smtencoding.nl_arith_repr native --z3rlimit 10"
let le_quad32_to_bytes_sel (q : quad32) (i:nat{i < 16}) =
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let Mkfour q0 q1 q2 q3 = q in
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 0 == q0);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 1 == q1);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 2 == q2);
assert (index (Vale.Def.Words.Seq_s.four_to_seq_LE q) 3 == q3);
let Mkfour q00 q01 q02 q03 = nat_to_four 8 q0 in
let Mkfour q10 q11 q12 q13 = nat_to_four 8 q1 in
let Mkfour q20 q21 q22 q23 = nat_to_four 8 q2 in
let Mkfour q30 q31 q32 q33 = nat_to_four 8 q3 in
assert_by_tactic (four_select (nat_to_four 8 q0) 0 == q00)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 1 == q01)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 2 == q02)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q0) 3 == q03)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 0 == q10)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 1 == q11)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 2 == q12)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q1) 3 == q13)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 0 == q20)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 1 == q21)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 2 == q22)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q2) 3 == q23)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 0 == q30)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 1 == q31)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 2 == q32)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert_by_tactic (four_select (nat_to_four 8 q3) 3 == q33)
(fun () -> norm[delta_only [`%Vale.Def.Words.Four_s.four_select]]);
assert(i < 4 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> (fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4)) i == four_select (nat_to_four 8 q3) (i % 4));
assert_by_tactic (i < 16 ==> index (le_quad32_to_bytes q) i =
(index (init (length (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x))) *
4)
(fun n ->
four_select (index (init (length (four_to_seq_LE q))
(fun x -> nat_to_four 8 (index (four_to_seq_LE q) x)))
(n / 4))
(n % 4))) i))
(fun () -> norm[primops; delta_only [`%Vale.Def.Types_s.le_quad32_to_bytes;
`%Vale.Lib.Seqs_s.seq_map; `%Vale.Lib.Seqs_s.compose;
`%Vale.Def.Words.Seq_s.seq_four_to_seq_LE]]; dump " after norm2");
assert(i < 4 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q0) i);
assert(4 <= i /\ i < 8 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q1) (i % 4));
assert(8 <= i /\ i < 12 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q2) (i % 4));
assert(12 <= i /\ i < 16 ==> index (le_quad32_to_bytes q) i == four_select (nat_to_four 8 q3) (i % 4))
#reset-options "--smtencoding.elim_box true --z3rlimit 60 --z3refresh --initial_ifuel 0 --max_ifuel 1 --initial_fuel 1 --max_fuel 1"
let lemma_pad_to_32_bits_helper (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 2 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
assert (n == 0 \/ n == 1 \/ n == 2);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 0 ==> x % pow2 (8 * n) == x % 0x1);
assert (n == 1 ==> x % pow2 (8 * n) == x % 0x100);
assert (n == 2 ==> x % pow2 (8 * n) == x % 0x10000);
()
let lemma_pad_to_32_bits (s s'':seq4 nat8) (n:nat) : Lemma
(requires
n <= 4 /\
(forall (i:nat).{:pattern (index s i) \/ (index s'' i)} i < 4 ==>
index s'' i == (if i < n then index s i else 0))
)
(ensures four_to_nat 8 (seq_to_four_LE s'') == four_to_nat 8 (seq_to_four_LE s) % pow2 (8 * n))
=
if n <= 2 then lemma_pad_to_32_bits_helper s s'' n else
assert (n == 3 \/ n == 4);
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
assert_norm (four_to_nat 8 (seq_to_four_LE s'') == four_to_nat_unfold 8 (seq_to_four_LE s''));
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
let x = four_to_nat 8 (seq_to_four_LE s'') in
assert (n == 3 ==> x % pow2 (8 * n) == x % 0x1000000);
assert (n == 4 ==> x % pow2 (8 * n) == x % 0x100000000);
()
let lemma_mod_n_8_lower1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * n) == q.lo0 % pow2 (8 * n))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * n) == q.lo0 % pow2 (8 * n) in
assert_norm (f 0);
assert_norm (f 1);
assert_norm (f 2);
assert_norm (f 3);
assert_norm (f 4);
()
let lemma_mod_n_8_lower2_helper (q:quad32) (n:nat) : Lemma
(requires n <= 2)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 2);
assert_norm (f 1);
assert_norm (f 0);
()
let lemma_mod_n_8_lower2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures lo64 q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)))
=
lo64_reveal ();
if n <= 2 then lemma_mod_n_8_lower2_helper q n else
let Mkfour _ _ _ _ = q in // avoid ifuel
let f (n:nat{n <= 4}) = lo64_def q % pow2 (8 * (4 + n)) == q.lo0 + 0x100000000 * (q.lo1 % pow2 (8 * n)) in
assert_norm (f 4);
assert_norm (f 3);
()
let lemma_mod_n_8_upper1 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * n) == q.hi2 % pow2 (8 * n))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower1 (Mkfour q2 q3 0 0) n
let lemma_mod_n_8_upper2 (q:quad32) (n:nat) : Lemma
(requires n <= 4)
(ensures hi64 q % pow2 (8 * (4 + n)) == q.hi2 + 0x100000000 * (q.hi3 % pow2 (8 * n)))
=
hi64_reveal ();
lo64_reveal ();
let Mkfour _ _ q2 q3 = q in
lemma_mod_n_8_lower2 (Mkfour q2 q3 0 0) n
let lemma_64_32_lo1 (q':quad32) (lo lo':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
lo' == lo % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)
)
(ensures lo' < 0x100000000 /\ lo' == q'.lo0 /\ q' == Mkfour q'.lo0 0 0 0)
=
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
()
let lemma_64_32_lo2 (q':quad32) (lo lo':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
lo' == lo % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (nat_to_two 32 lo') (nat_to_two 32 0)
)
(ensures lo' == q'.lo0 + 0x100000000 * q'.lo1 /\ q' == Mkfour q'.lo0 q'.lo1 0 0)
=
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (pow2 (5 * 8) == 0x10000000000);
assert_norm (pow2 (6 * 8) == 0x1000000000000);
assert_norm (pow2 (7 * 8) == 0x100000000000000);
assert_norm (pow2 (8 * 8) == 0x10000000000000000);
assert_norm (nat_to_two 32 lo' == nat_to_two_unfold 32 lo');
assert_norm (nat_to_two 32 0 == nat_to_two_unfold 32 0);
()
let lemma_64_32_hi1 (q':quad32) (hi hi':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
hi' == hi % pow2 (8 * n) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')
)
(ensures hi' < 0x100000000 /\ hi' == q'.hi2 /\ q'.hi3 == 0)
=
assert_norm (pow2 (0 * 8) == 1);
assert_norm (pow2 (1 * 8) == 0x100);
assert_norm (pow2 (2 * 8) == 0x10000);
assert_norm (pow2 (3 * 8) == 0x1000000);
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi');
()
let lemma_64_32_hi2 (q':quad32) (hi hi':nat64) (n:nat) : Lemma
(requires
n <= 4 /\
hi' == hi % pow2 (8 * (n + 4)) /\
four_to_two_two q' == Mktwo (Mktwo q'.lo0 q'.lo1) (nat_to_two 32 hi')
)
(ensures hi' == q'.hi2 + 0x100000000 * q'.hi3)
=
assert_norm (pow2 (4 * 8) == 0x100000000);
assert_norm (pow2 (5 * 8) == 0x10000000000);
assert_norm (pow2 (6 * 8) == 0x1000000000000);
assert_norm (pow2 (7 * 8) == 0x100000000000000);
assert_norm (pow2 (8 * 8) == 0x10000000000000000);
assert_norm (nat_to_two 32 hi' == nat_to_two_unfold 32 hi');
()
let lemma_slices_le_bytes_to_quad32 (s:seq16 nat8) : Lemma
(ensures (
let q = le_bytes_to_quad32 s in
q.lo0 == four_to_nat 8 (seq_to_four_LE (slice s 0 4)) /\
q.lo1 == four_to_nat 8 (seq_to_four_LE (slice s 4 8)) /\
q.hi2 == four_to_nat 8 (seq_to_four_LE (slice s 8 12)) /\
q.hi3 == four_to_nat 8 (seq_to_four_LE (slice s 12 16))
))
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #nat8);
le_bytes_to_quad32_reveal ();
()
let lemma_four_zero (_:unit) : Lemma
(ensures four_to_nat 8 (seq_to_four_LE (create 4 0)) == 0)
=
let s = create 4 0 in
assert_norm (four_to_nat 8 (seq_to_four_LE s) == four_to_nat_unfold 8 (seq_to_four_LE s));
()
let pad_to_128_bits_lower (q:quad32) (num_bytes:int) =
let n = num_bytes in
let new_lo = (lo64 q) % pow2 (n * 8) in
pow2_lt_compat 64 (n * 8);
let s = le_quad32_to_bytes q in
let s' = slice s 0 n in
let q' = insert_nat64_def (insert_nat64_def q 0 1) new_lo 0 in
insert_nat64_reveal ();
let s'' = pad_to_128_bits s' in
let q'' = le_bytes_to_quad32 s'' in
let s0_4 = slice s 0 4 in
let s4_8 = slice s 4 8 in
let s8_12 = slice s 8 12 in
let s12_16 = slice s 12 16 in
let s0_4'' = slice s'' 0 4 in
let s4_8'' = slice s'' 4 8 in
let s8_12'' = slice s'' 8 12 in
let s12_16'' = slice s'' 12 16 in
let Mkfour q0 q1 q2 q3 = q in
let Mkfour q0' q1' q2' q3' = q' in
let Mkfour q0'' q1'' q2'' q3'' = q'' in
if n < 4 then
(
lemma_mod_n_8_lower1 q n;
lemma_64_32_lo1 q' (lo64 q) new_lo n;
lemma_pad_to_32_bits s0_4 s0_4'' n;
()
)
else
(
lemma_mod_n_8_lower2 q (n - 4);
lemma_64_32_lo2 q' (lo64 q) new_lo (n - 4);
lemma_pad_to_32_bits s4_8 s4_8'' (n - 4);
()
);
lemma_slices_le_quad32_to_bytes q;
lemma_slices_le_bytes_to_quad32 s'';
lemma_four_zero ();
let zero_4 : seq nat8 = create 4 0 in
assert (n < 4 ==> equal s4_8'' zero_4);
assert (equal s8_12'' zero_4);
assert (equal s12_16'' zero_4);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs_s.fst.checked",
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.Types_helpers.fsti.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": true,
"source_file": "Vale.AES.GCM_helpers.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.Types_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": 1,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": true,
"z3rlimit": 60,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32 -> num_bytes: Prims.int
-> FStar.Pervasives.Lemma (requires 8 <= num_bytes /\ num_bytes < 16)
(ensures
(let new_hi = Vale.Arch.Types.hi64 q % Prims.pow2 ((num_bytes - 8) * 8) in
new_hi < Vale.Def.Words_s.pow2_64 /\
(let q' = Vale.Def.Types_s.insert_nat64 q new_hi 1 in
q' ==
Vale.Def.Types_s.le_bytes_to_quad32 (Vale.AES.GCTR_s.pad_to_128_bits (FStar.Seq.Base.slice
(Vale.Def.Types_s.le_quad32_to_bytes q)
0
num_bytes))))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.int",
"Vale.Def.Types_s.nat32",
"Prims.unit",
"Prims._assert",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.equal",
"Vale.Def.Types_s.nat8",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"FStar.Seq.Base.create",
"Vale.AES.GCM_helpers.lemma_four_zero",
"Vale.AES.GCM_helpers.lemma_slices_le_bytes_to_quad32",
"Vale.AES.Types_helpers.lemma_slices_le_quad32_to_bytes",
"Vale.AES.GCM_helpers.lemma_pad_to_32_bits",
"Prims.op_Subtraction",
"Vale.AES.GCM_helpers.lemma_64_32_hi1",
"Vale.Arch.Types.hi64",
"Vale.AES.GCM_helpers.lemma_mod_n_8_upper1",
"Prims.bool",
"Vale.AES.GCM_helpers.lemma_64_32_hi2",
"Vale.AES.GCM_helpers.lemma_mod_n_8_upper2",
"FStar.Seq.Base.slice",
"Vale.Def.Types_s.le_bytes_to_quad32",
"Vale.AES.GCTR_s.pad_to_128_bits",
"Vale.Def.Types_s.insert_nat64_reveal",
"Vale.Def.Types_s.insert_nat64_def",
"Vale.Def.Types_s.le_quad32_to_bytes",
"FStar.Math.Lemmas.pow2_lt_compat",
"FStar.Mul.op_Star",
"Prims.op_Modulus",
"Prims.pow2"
] | [] | false | false | true | false | false | let pad_to_128_bits_upper (q: quad32) (num_bytes: int) =
| let n = num_bytes in
let new_hi = (hi64 q) % pow2 ((n - 8) * 8) in
pow2_lt_compat 64 ((n - 8) * 8);
let s = le_quad32_to_bytes q in
let s' = slice s 0 n in
let q' = insert_nat64_def q new_hi 1 in
insert_nat64_reveal ();
let s'' = pad_to_128_bits s' in
let q'' = le_bytes_to_quad32 s'' in
let s0_4 = slice s 0 4 in
let s4_8 = slice s 4 8 in
let s8_12 = slice s 8 12 in
let s12_16 = slice s 12 16 in
let s0_4'' = slice s'' 0 4 in
let s4_8'' = slice s'' 4 8 in
let s8_12'' = slice s'' 8 12 in
let s12_16'' = slice s'' 12 16 in
let Mkfour q0 q1 q2 q3 = q in
let Mkfour q0' q1' q2' q3' = q' in
let Mkfour q0'' q1'' q2'' q3'' = q'' in
if n < 12
then
(lemma_mod_n_8_upper1 q (n - 8);
lemma_64_32_hi1 q' (hi64 q) new_hi (n - 8);
lemma_pad_to_32_bits s8_12 s8_12'' (n - 8);
())
else
(lemma_mod_n_8_upper2 q (n - 12);
lemma_64_32_hi2 q' (hi64 q) new_hi (n - 12);
lemma_pad_to_32_bits s12_16 s12_16'' (n - 12);
());
lemma_slices_le_quad32_to_bytes q;
lemma_slices_le_bytes_to_quad32 s'';
lemma_four_zero ();
let zero_4:seq nat8 = create 4 0 in
assert (n < 12 ==> equal s12_16'' zero_4);
() | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.