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.Poly1305.Util.fsti | Vale.Poly1305.Util.seqTo128 | val seqTo128 (s: Seq.seq nat64) : t_seqTo128 | val seqTo128 (s: Seq.seq nat64) : t_seqTo128 | let seqTo128 (s:Seq.seq nat64) : t_seqTo128 =
let f (i:int) : nat128 =
if 0 <= i && i < Seq.length s / 2 then
(Seq.index s (2 * i)) + 0x10000000000000000 * (Seq.index s (2 * i + 1))
else
42
in f | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Util.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 6,
"end_line": 36,
"start_col": 0,
"start_line": 30
} | module Vale.Poly1305.Util
open FStar.Mul
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Poly1305.Spec_s
open Vale.X64.Machine_s
open Vale.Poly1305.Math
open Vale.X64.State
open Vale.X64.Decls
open Vale.Def.Opaque_s
open Vale.X64.Memory
let rec poly1305_heap_blocks'
(h:int) (pad:int) (r:int) (s:Seq.seq nat64) (k:int{0 <= k /\ k <= Seq.length s /\ k % 2 == 0})
: Tot int (decreases k) =
if k = 0 then h
else
let kk = k - 2 in
let hh = poly1305_heap_blocks' h pad r s kk in
modp ((hh + pad + pow2_64 * Seq.index s (kk + 1) + Seq.index s kk) * r)
val poly1305_heap_blocks (h:int) (pad:int) (r:int) (s:Seq.seq nat64) (k:int) : int
val reveal_poly1305_heap_blocks (h:int) (pad:int) (r:int) (s:Seq.seq nat64) (k:int) : Lemma
(requires 0 <= k /\ k <= Seq.length s /\ k % 2 == 0)
(ensures poly1305_heap_blocks h pad r s k = poly1305_heap_blocks' h pad r s k) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Poly1305.Spec_s.fst.checked",
"Vale.Poly1305.Math.fsti.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"prims.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Poly1305.Util.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"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.Poly1305.Math",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305.Spec_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Vale.X64.Memory.nat64 -> Vale.Poly1305.Util.t_seqTo128 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.X64.Memory.nat64",
"Prims.int",
"Vale.Def.Words_s.nat128",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"Prims.op_Division",
"FStar.Seq.Base.length",
"Prims.op_Addition",
"FStar.Seq.Base.index",
"FStar.Mul.op_Star",
"Prims.bool",
"Vale.X64.Machine_s.nat128",
"Vale.Poly1305.Util.t_seqTo128"
] | [] | false | false | false | true | false | let seqTo128 (s: Seq.seq nat64) : t_seqTo128 =
| let f (i: int) : nat128 =
if 0 <= i && i < Seq.length s / 2
then (Seq.index s (2 * i)) + 0x10000000000000000 * (Seq.index s (2 * i + 1))
else 42
in
f | false |
Hacl.Spec.Bignum.ModInvLimb.fst | Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_f | val mod_inv_limb_f:
#t:limb_t
-> alpha:limb t
-> beta:limb t
-> i:nat{i < bits t}
-> tuple2 (limb t) (limb t) ->
tuple2 (limb t) (limb t) | val mod_inv_limb_f:
#t:limb_t
-> alpha:limb t
-> beta:limb t
-> i:nat{i < bits t}
-> tuple2 (limb t) (limb t) ->
tuple2 (limb t) (limb t) | let mod_inv_limb_f #t alpha beta i (ub, vb) =
let u_is_odd = uint #t 0 -. (ub &. uint #t 1) in
let beta_if_u_is_odd = beta &. u_is_odd in
let u = ((ub ^. beta_if_u_is_odd) >>. 1ul) +. (ub &. beta_if_u_is_odd) in
let alpha_if_u_is_odd = alpha &. u_is_odd in
let v = (vb >>. 1ul) +. alpha_if_u_is_odd in
(u, v) | {
"file_name": "code/bignum/Hacl.Spec.Bignum.ModInvLimb.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 32,
"start_col": 0,
"start_line": 25
} | module Hacl.Spec.Bignum.ModInvLimb
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
open Hacl.Spec.Bignum.Definitions
module M = Hacl.Spec.Montgomery.Lemmas
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(**
the modular inverse function was taken from
https://github.com/google/boringssl/blob/master/crypto/fipsmodule/bn/montgomery_inv.c *)
val mod_inv_limb_f:
#t:limb_t
-> alpha:limb t
-> beta:limb t
-> i:nat{i < bits t}
-> tuple2 (limb t) (limb t) ->
tuple2 (limb t) (limb t) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.ModInvLimb.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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 |
alpha: Hacl.Spec.Bignum.Definitions.limb t ->
beta: Hacl.Spec.Bignum.Definitions.limb t ->
i: Prims.nat{i < Lib.IntTypes.bits t} ->
_: (Hacl.Spec.Bignum.Definitions.limb t * Hacl.Spec.Bignum.Definitions.limb t)
-> Hacl.Spec.Bignum.Definitions.limb t * Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.bits",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.op_Greater_Greater_Dot",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Amp_Dot",
"Lib.IntTypes.op_Hat_Dot",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.uint"
] | [] | false | false | false | false | false | let mod_inv_limb_f #t alpha beta i (ub, vb) =
| let u_is_odd = uint #t 0 -. (ub &. uint #t 1) in
let beta_if_u_is_odd = beta &. u_is_odd in
let u = ((ub ^. beta_if_u_is_odd) >>. 1ul) +. (ub &. beta_if_u_is_odd) in
let alpha_if_u_is_odd = alpha &. u_is_odd in
let v = (vb >>. 1ul) +. alpha_if_u_is_odd in
(u, v) | false |
Hacl.Impl.PrecompTable.fsti | Hacl.Impl.PrecompTable.lprecomp_get_st | val lprecomp_get_st : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len
-> Type0 | let lprecomp_get_st
(a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len) =
a:Ghost.erased (LSeq.lseq (uint_t a_t SEC) (v len))
-> table_len:size_t{1 < v table_len /\ v table_len * v len <= max_size_t}
-> table:clbuffer (uint_t a_t SEC) (table_len *! len)
-> bits_l:uint_t a_t SEC{v bits_l < v table_len}
-> tmp:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h table /\ live h tmp /\ disjoint table tmp /\
k.to.linv a /\
(forall (j:nat{j < v table_len}).
precomp_table_inv len ctx_len k a table_len (as_seq h table) j))
(ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\
k.to.linv (as_seq h1 tmp) /\
k.to.refl (as_seq h1 tmp) == S.pow k.to.comm_monoid (k.to.refl a) (v bits_l)) | {
"file_name": "code/bignum/Hacl.Impl.PrecompTable.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 81,
"end_line": 111,
"start_col": 0,
"start_line": 93
} | module Hacl.Impl.PrecompTable
open FStar.Mul
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Lib.Exponentiation.Definition
module BD = Hacl.Bignum.Definitions
include Hacl.Impl.Exponentiation.Definitions
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val lemma_table_sub_len: len:nat -> table_len:nat -> i:nat{i < table_len} ->
Lemma (i * len + len <= table_len * len)
inline_for_extraction noextract
let spec_table_sub_len
(#t:BD.limb_t)
(len:pos)
(table_len:size_nat{table_len * len <= max_size_t})
(table:LSeq.lseq (uint_t t SEC) (table_len * len))
(i:nat{i < table_len}) : LSeq.lseq (uint_t t SEC) len =
lemma_table_sub_len len table_len i;
LSeq.sub table (i * len) len
inline_for_extraction noextract
val table_select_consttime:
#t:BD.limb_t
-> len:size_t{v len > 0}
-> table_len:size_t{1 < v table_len /\ v table_len * v len <= max_size_t}
-> table:clbuffer (uint_t t SEC) (table_len *! len)
-> i:uint_t t SEC{v i < v table_len}
-> res:lbuffer (uint_t t SEC) len ->
Stack unit
(requires fun h ->
live h table /\ live h res /\ disjoint table res)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == spec_table_sub_len (v len) (v table_len) (as_seq h0 table) (v i))
// Precomputed table [a^0 = one; a^1; a^2; ..; a^(table_len - 1)]
//----------------------------------------------------------------
inline_for_extraction noextract
let precomp_table_inv
(#a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(a:LSeq.lseq (uint_t a_t SEC) (v len))
(table_len:size_t{v table_len * v len <= max_size_t})
(table:LSeq.lseq (uint_t a_t SEC) (v table_len * v len))
(j:nat{j < v table_len}) : Type0
=
let bj = spec_table_sub_len (v len) (v table_len) table j in
k.to.linv bj /\ k.to.linv a /\
k.to.refl bj == S.pow k.to.comm_monoid (k.to.refl a) j
// This function computes [a^0 = one; a^1; a^2; ..; a^(table_len - 1)]
inline_for_extraction noextract
val lprecomp_table:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> table_len:size_t{1 < v table_len /\ v table_len * v len <= max_size_t /\ v table_len % 2 = 0}
-> table:lbuffer (uint_t a_t SEC) (table_len *! len) ->
Stack unit
(requires fun h ->
live h a /\ live h table /\ live h ctx /\
disjoint a table /\ disjoint ctx table /\ disjoint a ctx /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc table) h0 h1 /\
(forall (j:nat{j < v table_len}).{:pattern precomp_table_inv len ctx_len k (as_seq h1 a) table_len (as_seq h1 table) j}
precomp_table_inv len ctx_len k (as_seq h1 a) table_len (as_seq h1 table) j)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Exponentiation.Definitions.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.PrecompTable.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"FStar.Ghost.erased",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.l_and",
"Prims.op_LessThan",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Lib.Buffer.clbuffer",
"Lib.IntTypes.op_Star_Bang",
"Lib.Buffer.lbuffer",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Lib.Buffer.CONST",
"Lib.Buffer.MUT",
"Lib.Buffer.disjoint",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Prims.l_Forall",
"Prims.nat",
"Hacl.Impl.PrecompTable.precomp_table_inv",
"Lib.Buffer.as_seq",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.Exponentiation.Definition.pow",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid"
] | [] | false | false | false | false | true | let lprecomp_get_st
(a_t: inttype_a)
(len: size_t{v len > 0})
(ctx_len: size_t)
(k: concrete_ops a_t len ctx_len)
=
|
a: Ghost.erased (LSeq.lseq (uint_t a_t SEC) (v len)) ->
table_len: size_t{1 < v table_len /\ v table_len * v len <= max_size_t} ->
table: clbuffer (uint_t a_t SEC) (table_len *! len) ->
bits_l: uint_t a_t SEC {v bits_l < v table_len} ->
tmp: lbuffer (uint_t a_t SEC) len
-> Stack unit
(requires
fun h ->
live h table /\ live h tmp /\ disjoint table tmp /\ k.to.linv a /\
(forall (j: nat{j < v table_len}).
precomp_table_inv len ctx_len k a table_len (as_seq h table) j))
(ensures
fun h0 _ h1 ->
modifies (loc tmp) h0 h1 /\ k.to.linv (as_seq h1 tmp) /\
k.to.refl (as_seq h1 tmp) == S.pow k.to.comm_monoid (k.to.refl a) (v bits_l)) | false |
|
Hacl.Spec.Bignum.ModInvLimb.fst | Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb | val mod_inv_limb: #t:limb_t -> n0:limb t -> limb t | val mod_inv_limb: #t:limb_t -> n0:limb t -> limb t | let mod_inv_limb #t n0 =
let alpha = uint #t 1 <<. size (bits t - 1) in
let beta = n0 in
let (u, v) = repeat_gen (bits t) (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
v | {
"file_name": "code/bignum/Hacl.Spec.Bignum.ModInvLimb.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 40,
"start_col": 0,
"start_line": 36
} | module Hacl.Spec.Bignum.ModInvLimb
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
open Hacl.Spec.Bignum.Definitions
module M = Hacl.Spec.Montgomery.Lemmas
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(**
the modular inverse function was taken from
https://github.com/google/boringssl/blob/master/crypto/fipsmodule/bn/montgomery_inv.c *)
val mod_inv_limb_f:
#t:limb_t
-> alpha:limb t
-> beta:limb t
-> i:nat{i < bits t}
-> tuple2 (limb t) (limb t) ->
tuple2 (limb t) (limb t)
let mod_inv_limb_f #t alpha beta i (ub, vb) =
let u_is_odd = uint #t 0 -. (ub &. uint #t 1) in
let beta_if_u_is_odd = beta &. u_is_odd in
let u = ((ub ^. beta_if_u_is_odd) >>. 1ul) +. (ub &. beta_if_u_is_odd) in
let alpha_if_u_is_odd = alpha &. u_is_odd in
let v = (vb >>. 1ul) +. alpha_if_u_is_odd in
(u, v)
let mod_inv_limb_t (t:limb_t) (i:nat{i <= bits t}) = tuple2 (limb t) (limb t) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.ModInvLimb.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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 | n0: Hacl.Spec.Bignum.Definitions.limb t -> Hacl.Spec.Bignum.Definitions.limb t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_t",
"Lib.IntTypes.bits",
"Lib.LoopCombinators.repeat_gen",
"Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_f",
"FStar.Pervasives.Native.Mktuple2",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.size",
"Prims.op_Subtraction"
] | [] | false | false | false | false | false | let mod_inv_limb #t n0 =
| let alpha = uint #t 1 <<. size (bits t - 1) in
let beta = n0 in
let u, v =
repeat_gen (bits t) (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0)
in
v | false |
Hacl.Impl.PrecompTable.fsti | Hacl.Impl.PrecompTable.precomp_table_inv | val precomp_table_inv
(#a_t: inttype_a)
(len: size_t{v len > 0})
(ctx_len: size_t)
(k: concrete_ops a_t len ctx_len)
(a: LSeq.lseq (uint_t a_t SEC) (v len))
(table_len: size_t{v table_len * v len <= max_size_t})
(table: LSeq.lseq (uint_t a_t SEC) (v table_len * v len))
(j: nat{j < v table_len})
: Type0 | val precomp_table_inv
(#a_t: inttype_a)
(len: size_t{v len > 0})
(ctx_len: size_t)
(k: concrete_ops a_t len ctx_len)
(a: LSeq.lseq (uint_t a_t SEC) (v len))
(table_len: size_t{v table_len * v len <= max_size_t})
(table: LSeq.lseq (uint_t a_t SEC) (v table_len * v len))
(j: nat{j < v table_len})
: Type0 | let precomp_table_inv
(#a_t:inttype_a)
(len:size_t{v len > 0})
(ctx_len:size_t)
(k:concrete_ops a_t len ctx_len)
(a:LSeq.lseq (uint_t a_t SEC) (v len))
(table_len:size_t{v table_len * v len <= max_size_t})
(table:LSeq.lseq (uint_t a_t SEC) (v table_len * v len))
(j:nat{j < v table_len}) : Type0
=
let bj = spec_table_sub_len (v len) (v table_len) table j in
k.to.linv bj /\ k.to.linv a /\
k.to.refl bj == S.pow k.to.comm_monoid (k.to.refl a) j | {
"file_name": "code/bignum/Hacl.Impl.PrecompTable.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 56,
"end_line": 68,
"start_col": 0,
"start_line": 56
} | module Hacl.Impl.PrecompTable
open FStar.Mul
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Lib.Exponentiation.Definition
module BD = Hacl.Bignum.Definitions
include Hacl.Impl.Exponentiation.Definitions
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val lemma_table_sub_len: len:nat -> table_len:nat -> i:nat{i < table_len} ->
Lemma (i * len + len <= table_len * len)
inline_for_extraction noextract
let spec_table_sub_len
(#t:BD.limb_t)
(len:pos)
(table_len:size_nat{table_len * len <= max_size_t})
(table:LSeq.lseq (uint_t t SEC) (table_len * len))
(i:nat{i < table_len}) : LSeq.lseq (uint_t t SEC) len =
lemma_table_sub_len len table_len i;
LSeq.sub table (i * len) len
inline_for_extraction noextract
val table_select_consttime:
#t:BD.limb_t
-> len:size_t{v len > 0}
-> table_len:size_t{1 < v table_len /\ v table_len * v len <= max_size_t}
-> table:clbuffer (uint_t t SEC) (table_len *! len)
-> i:uint_t t SEC{v i < v table_len}
-> res:lbuffer (uint_t t SEC) len ->
Stack unit
(requires fun h ->
live h table /\ live h res /\ disjoint table res)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == spec_table_sub_len (v len) (v table_len) (as_seq h0 table) (v i))
// Precomputed table [a^0 = one; a^1; a^2; ..; a^(table_len - 1)]
//---------------------------------------------------------------- | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Exponentiation.Definitions.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.PrecompTable.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
ctx_len: Lib.IntTypes.size_t ->
k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len ->
a: Lib.Sequence.lseq (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC) (Lib.IntTypes.v len) ->
table_len:
Lib.IntTypes.size_t{Lib.IntTypes.v table_len * Lib.IntTypes.v len <= Lib.IntTypes.max_size_t} ->
table:
Lib.Sequence.lseq (Lib.IntTypes.uint_t a_t Lib.IntTypes.SEC)
(Lib.IntTypes.v table_len * Lib.IntTypes.v len) ->
j: Prims.nat{j < Lib.IntTypes.v table_len}
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.Definitions.concrete_ops",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Prims.nat",
"Prims.op_LessThan",
"Prims.l_and",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv",
"FStar.Ghost.reveal",
"Hacl.Impl.Exponentiation.Definitions.to_comm_monoid",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to",
"Prims.eq2",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl",
"Lib.Exponentiation.Definition.pow",
"Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid",
"Lib.IntTypes.int_t",
"Hacl.Impl.PrecompTable.spec_table_sub_len"
] | [] | false | false | false | false | true | let precomp_table_inv
(#a_t: inttype_a)
(len: size_t{v len > 0})
(ctx_len: size_t)
(k: concrete_ops a_t len ctx_len)
(a: LSeq.lseq (uint_t a_t SEC) (v len))
(table_len: size_t{v table_len * v len <= max_size_t})
(table: LSeq.lseq (uint_t a_t SEC) (v table_len * v len))
(j: nat{j < v table_len})
: Type0 =
| let bj = spec_table_sub_len (v len) (v table_len) table j in
k.to.linv bj /\ k.to.linv a /\ k.to.refl bj == S.pow k.to.comm_monoid (k.to.refl a) j | false |
Hacl.Impl.PrecompTable.fsti | Hacl.Impl.PrecompTable.spec_table_sub_len | val spec_table_sub_len
(#t: BD.limb_t)
(len: pos)
(table_len: size_nat{table_len * len <= max_size_t})
(table: LSeq.lseq (uint_t t SEC) (table_len * len))
(i: nat{i < table_len})
: LSeq.lseq (uint_t t SEC) len | val spec_table_sub_len
(#t: BD.limb_t)
(len: pos)
(table_len: size_nat{table_len * len <= max_size_t})
(table: LSeq.lseq (uint_t t SEC) (table_len * len))
(i: nat{i < table_len})
: LSeq.lseq (uint_t t SEC) len | let spec_table_sub_len
(#t:BD.limb_t)
(len:pos)
(table_len:size_nat{table_len * len <= max_size_t})
(table:LSeq.lseq (uint_t t SEC) (table_len * len))
(i:nat{i < table_len}) : LSeq.lseq (uint_t t SEC) len =
lemma_table_sub_len len table_len i;
LSeq.sub table (i * len) len | {
"file_name": "code/bignum/Hacl.Impl.PrecompTable.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 34,
"start_col": 0,
"start_line": 26
} | module Hacl.Impl.PrecompTable
open FStar.Mul
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Lib.Exponentiation.Definition
module BD = Hacl.Bignum.Definitions
include Hacl.Impl.Exponentiation.Definitions
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val lemma_table_sub_len: len:nat -> table_len:nat -> i:nat{i < table_len} ->
Lemma (i * len + len <= table_len * len) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Exponentiation.Definitions.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.PrecompTable.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation.Definition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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: Prims.pos ->
table_len: Lib.IntTypes.size_nat{table_len * len <= Lib.IntTypes.max_size_t} ->
table: Lib.Sequence.lseq (Lib.IntTypes.uint_t t Lib.IntTypes.SEC) (table_len * len) ->
i: Prims.nat{i < table_len}
-> Lib.Sequence.lseq (Lib.IntTypes.uint_t t Lib.IntTypes.SEC) len | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Prims.pos",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Prims.nat",
"Prims.op_LessThan",
"Lib.Sequence.sub",
"Prims.unit",
"Hacl.Impl.PrecompTable.lemma_table_sub_len"
] | [] | false | false | false | false | false | let spec_table_sub_len
(#t: BD.limb_t)
(len: pos)
(table_len: size_nat{table_len * len <= max_size_t})
(table: LSeq.lseq (uint_t t SEC) (table_len * len))
(i: nat{i < table_len})
: LSeq.lseq (uint_t t SEC) len =
| lemma_table_sub_len len table_len i;
LSeq.sub table (i * len) len | false |
Hacl.Impl.Chacha20.Core32.fst | Hacl.Impl.Chacha20.Core32.state | val state : Type0 | let state = lbuffer uint32 16ul | {
"file_name": "code/chacha20/Hacl.Impl.Chacha20.Core32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 15,
"start_col": 0,
"start_line": 15
} | module Hacl.Impl.Chacha20.Core32
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Sequence
open Lib.Buffer
open Lib.ByteBuffer
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20 | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20.Core32.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint32",
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | true | let state =
| lbuffer uint32 16ul | false |
|
Hacl.Impl.Chacha20.Core32.fst | Hacl.Impl.Chacha20.Core32.index | val index : Type0 | let index = i:size_t{size_v i < 16} | {
"file_name": "code/chacha20/Hacl.Impl.Chacha20.Core32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 16,
"start_col": 0,
"start_line": 16
} | module Hacl.Impl.Chacha20.Core32
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Sequence
open Lib.Buffer
open Lib.ByteBuffer
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20 | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20.Core32.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.size_v"
] | [] | false | false | false | true | true | let index =
| i: size_t{size_v i < 16} | false |
|
Hacl.Spec.Bignum.ModInvLimb.fst | Hacl.Spec.Bignum.ModInvLimb.x_if_u_is_odd | val x_if_u_is_odd: #t:limb_t -> x:limb t -> u:limb t ->
Lemma (let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
v (x &. u_is_odd) == (if v u % 2 = 0 then 0 else v x)) | val x_if_u_is_odd: #t:limb_t -> x:limb t -> u:limb t ->
Lemma (let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
v (x &. u_is_odd) == (if v u % 2 = 0 then 0 else v x)) | let x_if_u_is_odd #t x u =
let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
logand_mask u (uint #t 1) 1;
assert (v (u &. uint #t 1) == v u % 2);
assert (v u_is_odd == (- v u % 2) % pow2 (bits t));
assert (v u_is_odd == (if v u % 2 = 0 then 0 else pow2 (bits t) - 1));
if v u % 2 = 0 then
logand_zeros x
else
logand_ones x | {
"file_name": "code/bignum/Hacl.Spec.Bignum.ModInvLimb.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 17,
"end_line": 62,
"start_col": 0,
"start_line": 53
} | module Hacl.Spec.Bignum.ModInvLimb
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
open Hacl.Spec.Bignum.Definitions
module M = Hacl.Spec.Montgomery.Lemmas
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(**
the modular inverse function was taken from
https://github.com/google/boringssl/blob/master/crypto/fipsmodule/bn/montgomery_inv.c *)
val mod_inv_limb_f:
#t:limb_t
-> alpha:limb t
-> beta:limb t
-> i:nat{i < bits t}
-> tuple2 (limb t) (limb t) ->
tuple2 (limb t) (limb t)
let mod_inv_limb_f #t alpha beta i (ub, vb) =
let u_is_odd = uint #t 0 -. (ub &. uint #t 1) in
let beta_if_u_is_odd = beta &. u_is_odd in
let u = ((ub ^. beta_if_u_is_odd) >>. 1ul) +. (ub &. beta_if_u_is_odd) in
let alpha_if_u_is_odd = alpha &. u_is_odd in
let v = (vb >>. 1ul) +. alpha_if_u_is_odd in
(u, v)
let mod_inv_limb_t (t:limb_t) (i:nat{i <= bits t}) = tuple2 (limb t) (limb t)
let mod_inv_limb #t n0 =
let alpha = uint #t 1 <<. size (bits t - 1) in
let beta = n0 in
let (u, v) = repeat_gen (bits t) (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
v
// Replace with `a >> 1 + b >> 1 + a & b & 1`?
val add_div_2_nooverflow: #t:limb_t -> a:limb t -> b:limb t ->
Lemma (v (((a ^. b) >>. 1ul) +. (a &. b)) == (v a + v b) / 2 % pow2 (bits t))
let add_div_2_nooverflow #t a b = admit()
val x_if_u_is_odd: #t:limb_t -> x:limb t -> u:limb t ->
Lemma (let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
v (x &. u_is_odd) == (if v u % 2 = 0 then 0 else v x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.ModInvLimb.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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 | x: Hacl.Spec.Bignum.Definitions.limb t -> u51: Hacl.Spec.Bignum.Definitions.limb t
-> FStar.Pervasives.Lemma
(ensures
(let u_is_odd = Lib.IntTypes.uint 0 -. (u51 &. Lib.IntTypes.uint 1) in
Lib.IntTypes.v (x &. u_is_odd) ==
(match Lib.IntTypes.v u51 % 2 = 0 with
| true -> 0
| _ -> Lib.IntTypes.v x))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Lib.IntTypes.logand_zeros",
"Prims.bool",
"Lib.IntTypes.logand_ones",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.op_Subtraction",
"Prims.pow2",
"Lib.IntTypes.bits",
"Prims.op_Minus",
"Lib.IntTypes.op_Amp_Dot",
"Lib.IntTypes.uint",
"Lib.IntTypes.logand_mask",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Subtraction_Dot"
] | [] | false | false | true | false | false | let x_if_u_is_odd #t x u =
| let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
logand_mask u (uint #t 1) 1;
assert (v (u &. uint #t 1) == v u % 2);
assert (v u_is_odd == (- v u % 2) % pow2 (bits t));
assert (v u_is_odd == (if v u % 2 = 0 then 0 else pow2 (bits t) - 1));
if v u % 2 = 0 then logand_zeros x else logand_ones x | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.gen_elim' | val gen_elim'
(#opened: _)
(enable_nondep_opt: bool)
(p: vprop)
(a: Type)
(q: Ghost.erased a -> Tot vprop)
(post: Ghost.erased a -> Tot prop)
(sq: squash (gen_elim_prop_placeholder enable_nondep_opt p a q post))
(_: unit)
: STGhost (Ghost.erased a) opened p (fun x -> guard_vprop (q x)) (gen_elim_prop enable_nondep_opt p a q post) post | val gen_elim'
(#opened: _)
(enable_nondep_opt: bool)
(p: vprop)
(a: Type)
(q: Ghost.erased a -> Tot vprop)
(post: Ghost.erased a -> Tot prop)
(sq: squash (gen_elim_prop_placeholder enable_nondep_opt p a q post))
(_: unit)
: STGhost (Ghost.erased a) opened p (fun x -> guard_vprop (q x)) (gen_elim_prop enable_nondep_opt p a q post) post | let gen_elim'
#opened enable_nondep_opt p a q post _ ()
=
let (i, j) = gen_elim_prop_elim enable_nondep_opt p a q post in
rewrite p (compute_gen_elim_p i);
let res' = compute_gen_elim_nondep_correct i j () _ in
let res : Ghost.erased a = Ghost.hide (coerce_with_smt (Ghost.reveal res')) in
rewrite (compute_gen_elim_nondep_q i j res') (guard_vprop (q res));
res | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 839,
"start_col": 0,
"start_line": 831
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit1
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists1
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec compute_gen_elim_tele_correct
(x: gen_elim_i)
: GTot (ge_to_tele_t x)
= match x returns ge_to_tele_t x with
| GEUnit v -> compute_gen_elim_tele_correct_unit v
| GEStarL l ru -> compute_gen_elim_tele_correct_star_l l (compute_gen_elim_tele_correct l) ru
| GEStarR lu r -> compute_gen_elim_tele_correct_star_r lu r (compute_gen_elim_tele_correct r)
| GEStar l r -> compute_gen_elim_tele_correct_star l (compute_gen_elim_tele_correct l) r (compute_gen_elim_tele_correct r)
| GEExistsNoAbs0 #ty body -> compute_gen_elim_tele_correct_exists_no_abs0 ty body
| GEExistsUnit0 #ty body -> compute_gen_elim_tele_correct_exists_unit0 ty body
| GEExists0 #ty body -> compute_gen_elim_tele_correct_exists0 ty body (fun x -> compute_gen_elim_tele_correct (body x))
| GEExistsNoAbs1 #ty body -> compute_gen_elim_tele_correct_exists_no_abs1 ty body
| GEExistsUnit1 #ty body -> compute_gen_elim_tele_correct_exists_unit1 ty body
| GEExists1 #ty body -> compute_gen_elim_tele_correct_exists1 ty body (fun x -> compute_gen_elim_tele_correct (body x))
let rec gen_elim_nondep_p (ty: list (Type u#a)) : Tot (curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop) =
match ty as ty' returns curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop with
| [] -> fun q post -> q (U.raise_val ()) `star` pure (post (U.raise_val ()))
| t :: tq -> fun q post -> exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x))
let rec gen_elim_nondep_sem_correct
(ty: list (Type u#a))
: Tot ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
= match ty returns ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
with
| [] -> fun q post -> equiv_refl (q (U.raise_val ()) `star` pure (post (U.raise_val ())))
| ta :: tq -> fun q post ->
let phi
(x: ta)
: Lemma
(tele_p (gen_elim_nondep_sem tq (q x) (post x)) `equiv` gen_elim_nondep_p tq (q x) (post x))
= gen_elim_nondep_sem_correct tq (q x) (post x)
in
Classical.forall_intro phi;
let prf () : Lemma
(exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) `equiv` exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)))
=
exists_equiv (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) (fun x -> gen_elim_nondep_p tq (q x) (post x))
in
assert_norm (tele_p (gen_elim_nondep_sem (ta :: tq) q post) == exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))));
assert_norm (gen_elim_nondep_p (ta :: tq) q post == exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)));
prf ()
let compute_gen_elim_nondep_correct_t
(i0: gen_elim_i)
(ty: list (Type u#1))
: Tot Type
= (q: _) ->
(post: _) ->
(intro: vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a' ty)
(fun x -> compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) ty q x (U.raise_val ()))
(fun x -> compute_uncurry _ (fun _ -> True) ty post x (U.raise_val ()))
)
let compute_gen_elim_nondep_correct0
(i0: gen_elim_i)
: Tot (compute_gen_elim_nondep_correct_t i0 [])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (q (U.raise_val ()) `star` pure (post (U.raise_val ())));
let res = U.raise_val () in
elim_pure _;
rewrite_with_trefl (q (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct1
(i0: gen_elim_i)
(t1: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> q x1 (U.raise_val ()) `star` pure (post x1 (U.raise_val ()))));
let res = elim_exists' () in
elim_pure _;
rewrite_with_trefl (q _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct2
(i0: gen_elim_i)
(t1 t2: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> q x1 x2 (U.raise_val ()) `star` pure (post x1 x2 (U.raise_val ())))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let res = Mktuple2 x1 x2 in
elim_pure _;
rewrite_with_trefl (q _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct3
(i0: gen_elim_i)
(t1 t2 t3: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> q x1 x2 x3 (U.raise_val ()) `star` pure (post x1 x2 x3 (U.raise_val ()))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let res = Mktuple3 x1 x2 x3 in
elim_pure _;
rewrite_with_trefl (q _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct4
(i0: gen_elim_i)
(t1 t2 t3 t4: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> q x1 x2 x3 x4 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 (U.raise_val ())))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let res = Mktuple4 x1 x2 x3 x4 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct5
(i0: gen_elim_i)
(t1 t2 t3 t4 t5: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> q x1 x2 x3 x4 x5 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 (U.raise_val ()))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let res = Mktuple5 x1 x2 x3 x4 x5 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct6
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> q x1 x2 x3 x4 x5 x6 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 (U.raise_val ())))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let res = Mktuple6 x1 x2 x3 x4 x5 x6 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct7
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> q x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let res = Mktuple7 x1 x2 x3 x4 x5 x6 x7 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct8
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> q x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ())))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let res = Mktuple8 x1 x2 x3 x4 x5 x6 x7 x8 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct9
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let res = Mktuple9 x1 x2 x3 x4 x5 x6 x7 x8 x9 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct10
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 (U.raise_val ())))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let res = Mktuple10 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct11
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 (U.raise_val ()))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let res = Mktuple11 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct12
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 (U.raise_val ())))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let res = Mktuple12 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct13
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> exists_ (fun x13 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 (U.raise_val ()))))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let x13 = elim_exists' () in
let res = Mktuple13 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct14
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13; t14])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> exists_ (fun x10 -> exists_ (fun x11 -> exists_ (fun x12 -> exists_ (fun x13 -> exists_ (fun x14 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 (U.raise_val ())))))))))))))))));
let x1 = elim_exists' () in
let x2 = elim_exists' () in
let x3 = elim_exists' () in
let x4 = elim_exists' () in
let x5 = elim_exists' () in
let x6 = elim_exists' () in
let x7 = elim_exists' () in
let x8 = elim_exists' () in
let x9 = elim_exists' () in
let x10 = elim_exists' () in
let x11 = elim_exists' () in
let x12 = elim_exists' () in
let x13 = elim_exists' () in
let x14 = elim_exists' () in
let res = Mktuple14 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 in
elim_pure _;
rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct_default
(i0: gen_elim_i)
(t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15: Type) (tq: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 (t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq))
= fun q post intro _ ->
// default case: no exists is opened
let res : compute_gen_elim_nondep_a' (t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq) = (U.raise_val ()) in
rewrite_with_trefl (compute_gen_elim_p i0) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res
let compute_gen_elim_nondep_correct'
(i0: gen_elim_i)
(ty: list Type)
: Tot (compute_gen_elim_nondep_correct_t i0 ty)
= match ty returns compute_gen_elim_nondep_correct_t i0 ty with
| [] -> compute_gen_elim_nondep_correct0 i0
| [t1] -> compute_gen_elim_nondep_correct1 i0 t1
| [t1; t2] -> compute_gen_elim_nondep_correct2 i0 t1 t2
| [t1; t2; t3] -> compute_gen_elim_nondep_correct3 i0 t1 t2 t3
| [t1; t2; t3; t4] -> compute_gen_elim_nondep_correct4 i0 t1 t2 t3 t4
| [t1; t2; t3; t4; t5] -> compute_gen_elim_nondep_correct5 i0 t1 t2 t3 t4 t5
| [t1; t2; t3; t4; t5; t6] -> compute_gen_elim_nondep_correct6 i0 t1 t2 t3 t4 t5 t6
| [t1; t2; t3; t4; t5; t6; t7] -> compute_gen_elim_nondep_correct7 i0 t1 t2 t3 t4 t5 t6 t7
| [t1; t2; t3; t4; t5; t6; t7; t8] -> compute_gen_elim_nondep_correct8 i0 t1 t2 t3 t4 t5 t6 t7 t8
| [t1; t2; t3; t4; t5; t6; t7; t8; t9] -> compute_gen_elim_nondep_correct9 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10] -> compute_gen_elim_nondep_correct10 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11] -> compute_gen_elim_nondep_correct11 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12] -> compute_gen_elim_nondep_correct12 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13] -> compute_gen_elim_nondep_correct13 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13
| [t1; t2; t3; t4; t5; t6; t7; t8; t9; t10; t11; t12; t13; t14] -> compute_gen_elim_nondep_correct14 i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14
| t1 :: t2 :: t3 :: t4 :: t5 :: t6 :: t7 :: t8 :: t9 :: t10 :: t11 :: t12 :: t13 :: t14 :: t15 :: tq -> compute_gen_elim_nondep_correct_default i0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 tq
let compute_gen_elim_nondep_correct_0
(i0: gen_elim_i)
(i: gen_elim_nondep_t)
= match i returns
(sq: squash (check_gen_elim_nondep_sem i0 i)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a i0 i)
(compute_gen_elim_nondep_q0 i0 i)
(compute_gen_elim_nondep_post0 i0 i)
)
with
| GEDep -> fun _ -> compute_gen_elim_f i0
| GENonDep ty q post -> fun _ ->
let intro : vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post) = fun _ ->
compute_gen_elim_tele_correct i0 _;
rewrite (tele_p _) (tele_p (gen_elim_nondep_sem ty q post));
gen_elim_nondep_sem_correct ty q post;
rewrite_equiv (tele_p _) (gen_elim_nondep_p _ _ _)
in
compute_gen_elim_nondep_correct' i0 ty q post intro
let compute_gen_elim_nondep_correct
(i0: gen_elim_i)
(i: gen_elim_nondep_t)
(sq: squash (check_gen_elim_nondep_sem i0 i))
: Tot (gen_elim_f
(compute_gen_elim_p i0)
(Ghost.erased (compute_gen_elim_nondep_a i0 i))
(compute_gen_elim_nondep_q i0 i)
(compute_gen_elim_nondep_post i0 i)
)
= fun _ ->
let res0 = compute_gen_elim_nondep_correct_0 i0 i sq _ in
let res = Ghost.hide res0 in
rewrite (compute_gen_elim_nondep_q0 i0 i res0) (compute_gen_elim_nondep_q i0 i res);
res
let coerce_with_smt (#tfrom #tto: Type) (x: tfrom) : Pure tto (requires ( (tfrom == tto))) (ensures (fun _ -> True)) = x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
enable_nondep_opt: Prims.bool ->
p: Steel.Effect.Common.vprop ->
a: Type ->
q: (_: FStar.Ghost.erased a -> Steel.Effect.Common.vprop) ->
post: (_: FStar.Ghost.erased a -> Prims.prop) ->
sq: Prims.squash (Steel.ST.GenElim1.Base.gen_elim_prop_placeholder enable_nondep_opt p a q post) ->
_: Prims.unit
-> Steel.ST.Effect.Ghost.STGhost (FStar.Ghost.erased a) | Steel.ST.Effect.Ghost.STGhost | [] | [] | [
"Steel.Memory.inames",
"Prims.bool",
"Steel.Effect.Common.vprop",
"FStar.Ghost.erased",
"Prims.prop",
"Prims.squash",
"Steel.ST.GenElim1.Base.gen_elim_prop_placeholder",
"Prims.unit",
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.Base.gen_elim_nondep_t",
"Steel.ST.Util.rewrite",
"Steel.ST.GenElim1.Base.compute_gen_elim_nondep_q",
"Steel.Effect.Common.guard_vprop",
"FStar.Ghost.hide",
"Steel.ST.GenElim1.coerce_with_smt",
"Steel.ST.GenElim1.Base.compute_gen_elim_nondep_a",
"FStar.Ghost.reveal",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"FStar.Pervasives.Native.tuple2",
"Steel.ST.GenElim1.Base.gen_elim_prop_elim"
] | [] | false | true | false | false | false | let gen_elim' #opened enable_nondep_opt p a q post _ () =
| let i, j = gen_elim_prop_elim enable_nondep_opt p a q post in
rewrite p (compute_gen_elim_p i);
let res' = compute_gen_elim_nondep_correct i j () _ in
let res:Ghost.erased a = Ghost.hide (coerce_with_smt (Ghost.reveal res')) in
rewrite (compute_gen_elim_nondep_q i j res') (guard_vprop (q res));
res | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_f_star_l | val compute_gen_elim_f_star_l (i1: gen_elim_i) (f1: gen_elim_t i1) (i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2)) | val compute_gen_elim_f_star_l (i1: gen_elim_i) (f1: gen_elim_t i1) (i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2)) | let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res' | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 6,
"end_line": 69,
"start_col": 0,
"start_line": 57
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i1: Steel.ST.GenElim1.Base.gen_elim_i ->
f1: Steel.ST.GenElim1.gen_elim_t i1 ->
i2: Steel.ST.GenElim1.Base.gen_unit_elim_i
-> Prims.GTot (Steel.ST.GenElim1.gen_elim_t (Steel.ST.GenElim1.Base.GEStarL i1 i2)) | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.gen_elim_t",
"Steel.ST.GenElim1.Base.gen_unit_elim_i",
"Steel.Memory.inames",
"Steel.ST.GenElim1.Base.compute_gen_elim_a",
"Steel.ST.GenElim1.Base.GEStarL",
"Prims.unit",
"Steel.ST.Util.rewrite",
"Steel.Effect.Common.star",
"Steel.ST.GenElim1.Base.compute_gen_elim_q",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_q",
"Steel.ST.GenElim1.Base.coerce_with_trefl",
"FStar.Universe.raise_t",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_p",
"Steel.ST.GenElim1.gen_unit_elim_t",
"Steel.ST.GenElim1.compute_gen_unit_elim_f"
] | [] | false | false | false | false | false | let compute_gen_elim_f_star_l (i1: gen_elim_i) (f1: gen_elim_t i1) (i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2)) =
| let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2))
((compute_gen_elim_p i1) `star` (compute_gen_unit_elim_p i2));
let res = f1 _ in
let _ = f2 _ in
let res':compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite ((compute_gen_elim_q i1 res) `star` (compute_gen_unit_elim_q i2))
(compute_gen_elim_q (GEStarL i1 i2) res');
res' | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_f_exists_unit1 | val compute_gen_elim_f_exists_unit1 (a: Type) (body: (a -> gen_unit_elim_i))
: Tot (gen_elim_t (GEExistsUnit1 body)) | val compute_gen_elim_f_exists_unit1 (a: Type) (body: (a -> gen_unit_elim_i))
: Tot (gen_elim_t (GEExistsUnit1 body)) | let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 164,
"start_col": 0,
"start_line": 154
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> body: (_: a -> Steel.ST.GenElim1.Base.gen_unit_elim_i)
-> Steel.ST.GenElim1.gen_elim_t (Steel.ST.GenElim1.Base.GEExistsUnit1 body) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_unit_elim_i",
"Steel.Memory.inames",
"Steel.ST.GenElim1.Base.compute_gen_elim_a",
"Steel.ST.GenElim1.Base.GEExistsUnit1",
"Prims.unit",
"Steel.ST.Util.rewrite",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_q",
"FStar.Ghost.reveal",
"Steel.ST.GenElim1.Base.compute_gen_elim_q",
"Steel.ST.GenElim1.Base.coerce_with_trefl",
"FStar.Universe.raise_t",
"Steel.ST.GenElim1.compute_gen_unit_elim_f",
"FStar.Ghost.erased",
"Steel.ST.Util.elim_exists",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_p",
"Steel.Effect.Common.vprop",
"Steel.ST.GenElim1.rewrite_with_trefl",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.ST.Util.exists_",
"Steel.ST.GenElim1.gen_elim_t"
] | [] | false | false | false | false | false | let compute_gen_elim_f_exists_unit1 (a: Type) (body: (a -> gen_unit_elim_i))
: Tot (gen_elim_t (GEExistsUnit1 body)) =
| fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body))
(exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res:compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_f_exists1 | val compute_gen_elim_f_exists1
(a: Type)
(body: (a -> gen_elim_i))
(f: (x: a -> GTot (gen_elim_t (body x))))
: Tot (gen_elim_t (GEExists1 body)) | val compute_gen_elim_f_exists1
(a: Type)
(body: (a -> gen_elim_i))
(f: (x: a -> GTot (gen_elim_t (body x))))
: Tot (gen_elim_t (GEExists1 body)) | let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 177,
"start_col": 0,
"start_line": 166
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type ->
body: (_: a -> Steel.ST.GenElim1.Base.gen_elim_i) ->
f: (x: a -> Prims.GTot (Steel.ST.GenElim1.gen_elim_t (body x)))
-> Steel.ST.GenElim1.gen_elim_t (Steel.ST.GenElim1.Base.GEExists1 body) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.gen_elim_t",
"Steel.Memory.inames",
"Steel.ST.GenElim1.Base.compute_gen_elim_a",
"Steel.ST.GenElim1.Base.GEExists1",
"Prims.unit",
"Steel.ST.Util.rewrite",
"Steel.ST.GenElim1.Base.compute_gen_elim_q",
"FStar.Ghost.reveal",
"Steel.ST.GenElim1.Base.coerce_with_trefl",
"Prims.dtuple2",
"Prims.Mkdtuple2",
"FStar.Ghost.hide",
"FStar.Ghost.erased",
"Steel.ST.Util.elim_exists",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.Effect.Common.vprop",
"Steel.ST.GenElim1.rewrite_with_trefl",
"Steel.ST.Util.exists_"
] | [] | false | false | false | false | false | let compute_gen_elim_f_exists1
(a: Type)
(body: (a -> gen_elim_i))
(f: (x: a -> GTot (gen_elim_t (body x))))
: Tot (gen_elim_t (GEExists1 body)) =
| fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body))
(exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res:compute_gen_elim_a (GEExists1 body) =
coerce_with_trefl (Mkdtuple2 #a
#(fun x -> compute_gen_elim_a (body x))
(Ghost.reveal gres1)
(Ghost.reveal gres2))
in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res | false |
Hacl.Spec.Bignum.ModInvLimb.fst | Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma | val bn_mod_inv_limb_lemma: #t:limb_t -> #nLen:size_pos -> n:lbignum t nLen -> Lemma
(requires 1 < bn_v n /\ bn_v n % 2 = 1)
(ensures (let mu = mod_inv_limb (Lib.Sequence.index n 0) in
(1 + bn_v n * v mu) % pow2 (bits t) == 0)) | val bn_mod_inv_limb_lemma: #t:limb_t -> #nLen:size_pos -> n:lbignum t nLen -> Lemma
(requires 1 < bn_v n /\ bn_v n % 2 = 1)
(ensures (let mu = mod_inv_limb (Lib.Sequence.index n 0) in
(1 + bn_v n * v mu) % pow2 (bits t) == 0)) | let bn_mod_inv_limb_lemma #t #nLen n =
let n0 = Lib.Sequence.index n 0 in
let mu = mod_inv_limb n0 in
bn_eval_index n 0;
assert (bn_v n % pow2 (bits t) == v n0);
Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v n) 2 (bits t);
assert (v n0 % 2 = 1); // since bn_v n % 2 = 1
mod_inv_limb_lemma n0;
assert ((1 + (bn_v n % pow2 (bits t)) * v mu) % pow2 (bits t) == 0);
M.mont_preconditions_n0 (bits t) (bn_v n) (v mu) | {
"file_name": "code/bignum/Hacl.Spec.Bignum.ModInvLimb.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 279,
"start_col": 0,
"start_line": 270
} | module Hacl.Spec.Bignum.ModInvLimb
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
open Hacl.Spec.Bignum.Definitions
module M = Hacl.Spec.Montgomery.Lemmas
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(**
the modular inverse function was taken from
https://github.com/google/boringssl/blob/master/crypto/fipsmodule/bn/montgomery_inv.c *)
val mod_inv_limb_f:
#t:limb_t
-> alpha:limb t
-> beta:limb t
-> i:nat{i < bits t}
-> tuple2 (limb t) (limb t) ->
tuple2 (limb t) (limb t)
let mod_inv_limb_f #t alpha beta i (ub, vb) =
let u_is_odd = uint #t 0 -. (ub &. uint #t 1) in
let beta_if_u_is_odd = beta &. u_is_odd in
let u = ((ub ^. beta_if_u_is_odd) >>. 1ul) +. (ub &. beta_if_u_is_odd) in
let alpha_if_u_is_odd = alpha &. u_is_odd in
let v = (vb >>. 1ul) +. alpha_if_u_is_odd in
(u, v)
let mod_inv_limb_t (t:limb_t) (i:nat{i <= bits t}) = tuple2 (limb t) (limb t)
let mod_inv_limb #t n0 =
let alpha = uint #t 1 <<. size (bits t - 1) in
let beta = n0 in
let (u, v) = repeat_gen (bits t) (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
v
// Replace with `a >> 1 + b >> 1 + a & b & 1`?
val add_div_2_nooverflow: #t:limb_t -> a:limb t -> b:limb t ->
Lemma (v (((a ^. b) >>. 1ul) +. (a &. b)) == (v a + v b) / 2 % pow2 (bits t))
let add_div_2_nooverflow #t a b = admit()
val x_if_u_is_odd: #t:limb_t -> x:limb t -> u:limb t ->
Lemma (let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
v (x &. u_is_odd) == (if v u % 2 = 0 then 0 else v x))
let x_if_u_is_odd #t x u =
let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
logand_mask u (uint #t 1) 1;
assert (v (u &. uint #t 1) == v u % 2);
assert (v u_is_odd == (- v u % 2) % pow2 (bits t));
assert (v u_is_odd == (if v u % 2 = 0 then 0 else pow2 (bits t) - 1));
if v u % 2 = 0 then
logand_zeros x
else
logand_ones x
val mod_inv_limb_inv_vb_is_even:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures v vb0 % 2 = 0)
private
let aux_mod_2_neg (n:nat) : Lemma (n % 2 == (-n) % 2) =
()
let mod_inv_limb_inv_vb_is_even #t n0 i ub0 vb0 =
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 1 (bits t - i + 1);
assert (pow2 (bits t - i + 1) % 2 == 0);
calc (==) {
pow2 (bits t - i + 1) % 2;
(==) { }
(v ub0 * 2 * v alpha - v vb0 * v beta) % 2;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (v ub0 * 2 * v alpha) (- v vb0 * v beta) 2 }
(- v vb0 * v beta) % 2;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (- v vb0) (v beta) 2 }
(- v vb0) % 2;
(==) { aux_mod_2_neg (v vb0) } // flaky without the lemma call
v vb0 % 2;
}
val mod_inv_limb_inv_step_even:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ v ub0 % 2 = 0 /\
pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = v ub0 / 2 % pow2 (bits t) in
let vb = v vb0 / 2 % pow2 (bits t) in
pow2 (bits t - i + 1) == 2 * (ub * 2 * v alpha - vb * v beta)))
let mod_inv_limb_inv_step_even #t n0 i ub0 vb0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = v ub0 / 2 % pow2 pbits in
let vb = v vb0 / 2 % pow2 pbits in
Math.Lemmas.small_mod (v ub0 / 2) (pow2 pbits);
Math.Lemmas.small_mod (v vb0 / 2) (pow2 pbits);
assert (ub * 2 * v alpha - vb * v beta == v ub0 / 2 * 2 * v alpha - v vb0 / 2 * v beta);
calc (==) {
2 * (ub * 2 * v alpha - vb * v beta);
(==) { }
2 * (v ub0 / 2 * 2 * v alpha - v vb0 / 2 * v beta);
(==) { Math.Lemmas.distributivity_sub_right 2 (v ub0 / 2 * 2 * v alpha) (v vb0 / 2 * v beta) }
2 * v ub0 / 2 * 2 * v alpha - 2 * (v vb0 / 2) * v beta;
(==) { Math.Lemmas.div_exact_r (v ub0) 2 }
v ub0 * 2 * v alpha - 2 * (v vb0 / 2) * v beta;
(==) { mod_inv_limb_inv_vb_is_even n0 i ub0 vb0; Math.Lemmas.div_exact_r (v vb0) 2 }
v ub0 * 2 * v alpha - v vb0 * v beta;
(==) {assert (pow2 (pbits - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta) }
pow2 (pbits - i + 1);
};
assert (2 * (ub * 2 * v alpha - vb * v beta) == pow2 (pbits - i + 1))
#push-options "--z3rlimit 150"
val mod_inv_limb_inv_step_odd:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ v ub0 % 2 = 1 /\
pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = (v ub0 + v beta) / 2 % pow2 (bits t) in
let vb = (v vb0 / 2 + v alpha) % pow2 (bits t) in
pow2 (bits t - i + 1) == 2 * (ub * 2 * v alpha - vb * v beta)))
let mod_inv_limb_inv_step_odd #t n0 i ub0 vb0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = (v ub0 + v beta) / 2 % pow2 pbits in
let vb = (v vb0 / 2 + v alpha) % pow2 pbits in
calc (==) {
2 * (ub * 2 * v alpha - vb * v beta);
(==) { Math.Lemmas.small_mod ((v ub0 + v beta) / 2) (pow2 pbits) }
2 * ((v ub0 + v beta) / 2 * 2 * v alpha - vb * v beta);
(==) { Math.Lemmas.small_mod (v vb0 / 2 + v alpha) (pow2 pbits) }
2 * ((v ub0 + v beta) / 2 * 2 * v alpha - (v vb0 / 2 + v alpha) * v beta);
(==) { Math.Lemmas.distributivity_sub_right 2 ((v ub0 + v beta) / 2 * 2 * v alpha) ((v vb0 / 2 + v alpha) * v beta) }
2 * (v ub0 + v beta) / 2 * 2 * v alpha - 2 * (v vb0 / 2 + v alpha) * v beta;
(==) { Math.Lemmas.div_exact_r (v ub0 + v beta) 2 }
(v ub0 + v beta) * 2 * v alpha - 2 * (v vb0 / 2 + v alpha) * v beta;
(==) { Math.Lemmas.paren_mul_right 2 (v vb0 / 2 + v alpha) (v beta) }
(v ub0 + v beta) * 2 * v alpha - 2 * ((v vb0 / 2 + v alpha) * v beta);
(==) { Math.Lemmas.distributivity_add_left (v vb0 / 2) (v alpha) (v beta) }
(v ub0 + v beta) * 2 * v alpha - 2 * (v vb0 / 2 * v beta + v alpha * v beta);
(==) { Math.Lemmas.distributivity_add_right 2 (v vb0 / 2 * v beta) (v alpha * v beta);
Math.Lemmas.paren_mul_right 2 (v vb0 / 2) (v beta);
Math.Lemmas.paren_mul_right 2 (v alpha) (v beta) }
(v ub0 + v beta) * 2 * v alpha - (2 * (v vb0 / 2) * v beta + 2 * v alpha * v beta);
(==) { mod_inv_limb_inv_vb_is_even n0 i ub0 vb0; Math.Lemmas.div_exact_r (v vb0) 2 }
(v ub0 + v beta) * 2 * v alpha - (v vb0 * v beta + 2 * v alpha * v beta);
(==) { Math.Lemmas.distributivity_add_left (v ub0) (v beta) (2 * v alpha) }
v ub0 * 2 * v alpha + v beta * 2 * v alpha - (v vb0 * v beta + 2 * v alpha * v beta);
(==) { Math.Lemmas.paren_mul_right (v beta) 2 (v alpha); Math.Lemmas.swap_mul (v beta) (2 * v alpha) }
v ub0 * 2 * v alpha + 2 * v alpha * v beta - v vb0 * v beta - 2 * v alpha * v beta;
(==) { }
v ub0 * 2 * v alpha - v vb0 * v beta;
(==) { assert (pow2 (pbits - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta) }
pow2 (pbits - i + 1);
};
assert (2 * (ub * 2 * v alpha - vb * v beta) == pow2 (pbits - i + 1))
#pop-options
val mod_inv_limb_inv_step:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let (ub, vb) = mod_inv_limb_f alpha beta (i - 1) (ub0, vb0) in
pow2 (bits t - i) == v ub * 2 * v alpha - v vb * v beta))
let mod_inv_limb_inv_step #t n0 i ub0 vb0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let u_is_odd = uint #t 0 -. (ub0 &. uint #t 1) in
let beta_if_u_is_odd = beta &. u_is_odd in
let ub = ((ub0 ^. beta_if_u_is_odd) >>. 1ul) +. (ub0 &. beta_if_u_is_odd) in
let alpha_if_u_is_odd = alpha &. u_is_odd in
let vb = (vb0 >>. 1ul) +. alpha_if_u_is_odd in
x_if_u_is_odd beta ub0;
x_if_u_is_odd alpha ub0;
assert (v beta_if_u_is_odd == (if v ub0 % 2 = 0 then 0 else v beta));
assert (v alpha_if_u_is_odd == (if v ub0 % 2 = 0 then 0 else v alpha));
add_div_2_nooverflow ub0 beta_if_u_is_odd;
assert (v ub == (v ub0 + v beta_if_u_is_odd) / 2 % pow2 pbits);
assert (v ub == (if v ub0 % 2 = 0 then v ub0 / 2 % pow2 pbits else (v ub0 + v beta) / 2 % pow2 pbits));
Math.Lemmas.lemma_mod_plus_distr_l (v vb0 / 2) (v alpha_if_u_is_odd) (pow2 pbits);
assert (v vb == (v vb0 / 2 + v alpha_if_u_is_odd) % pow2 pbits);
assert (v vb == (if v ub0 % 2 = 0 then v vb0 / 2 % pow2 pbits else (v vb0 / 2 + v alpha) % pow2 pbits));
if v ub0 % 2 = 0 then
mod_inv_limb_inv_step_even n0 i ub0 vb0
else
mod_inv_limb_inv_step_odd n0 i ub0 vb0;
assert (2 * (v ub * 2 * v alpha - v vb * v beta) == pow2 (pbits - i + 1));
Math.Lemmas.cancel_mul_div (v ub * 2 * v alpha - v vb * v beta) 2;
Math.Lemmas.pow2_minus (pbits - i + 1) 1
val mod_inv_limb_inv: #t:limb_t -> n0:limb t -> i:nat{i <= bits t} -> Lemma
(requires v n0 % 2 = 1)
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let (ub, vb) = repeat_gen i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
pow2 (bits t - i) == v ub * 2 * v alpha - v vb * v beta))
let rec mod_inv_limb_inv #t n0 i =
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let (ub, vb) = repeat_gen i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
if i = 0 then
eq_repeat_gen0 i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0)
else begin
let (ub0, vb0) = repeat_gen (i - 1) (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
mod_inv_limb_inv n0 (i - 1);
assert (pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta);
unfold_repeat_gen i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) (i - 1);
assert ((ub, vb) == mod_inv_limb_f alpha beta (i - 1) (ub0, vb0));
mod_inv_limb_inv_step n0 i ub0 vb0;
() end
let mod_inv_limb_lemma #t n0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let (ub, vb) = repeat_gen pbits (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
mod_inv_limb_inv n0 pbits;
calc (==) {
(1 + v vb * v n0) % pow2 pbits;
(==) { }
(v ub * 2 * v alpha) % pow2 pbits;
(==) { Math.Lemmas.pow2_plus 1 (pbits - 1) }
(v ub * pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.cancel_mul_mod (v ub) (pow2 pbits) }
0;
};
assert ((1 + v vb * v n0) % pow2 pbits == 0) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.ModInvLimb.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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 | n: Hacl.Spec.Bignum.Definitions.lbignum t nLen
-> FStar.Pervasives.Lemma
(requires
1 < Hacl.Spec.Bignum.Definitions.bn_v n /\ Hacl.Spec.Bignum.Definitions.bn_v n % 2 = 1)
(ensures
(let mu = Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb (Lib.Sequence.index n 0) in
(1 + Hacl.Spec.Bignum.Definitions.bn_v n * Lib.IntTypes.v mu) %
Prims.pow2 (Lib.IntTypes.bits t) ==
0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Montgomery.Lemmas.mont_preconditions_n0",
"Lib.IntTypes.bits",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.pow2",
"Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_lemma",
"Prims.b2t",
"Prims.op_Equality",
"FStar.Math.Lemmas.pow2_modulo_modulo_lemma_1",
"Hacl.Spec.Bignum.Definitions.bn_eval_index",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.index"
] | [] | true | false | true | false | false | let bn_mod_inv_limb_lemma #t #nLen n =
| let n0 = Lib.Sequence.index n 0 in
let mu = mod_inv_limb n0 in
bn_eval_index n 0;
assert (bn_v n % pow2 (bits t) == v n0);
Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v n) 2 (bits t);
assert (v n0 % 2 = 1);
mod_inv_limb_lemma n0;
assert ((1 + (bn_v n % pow2 (bits t)) * v mu) % pow2 (bits t) == 0);
M.mont_preconditions_n0 (bits t) (bn_v n) (v mu) | false |
Hacl.Spec.Bignum.ModInvLimb.fst | Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_inv_step_even | val mod_inv_limb_inv_step_even:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ v ub0 % 2 = 0 /\
pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = v ub0 / 2 % pow2 (bits t) in
let vb = v vb0 / 2 % pow2 (bits t) in
pow2 (bits t - i + 1) == 2 * (ub * 2 * v alpha - vb * v beta))) | val mod_inv_limb_inv_step_even:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ v ub0 % 2 = 0 /\
pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = v ub0 / 2 % pow2 (bits t) in
let vb = v vb0 / 2 % pow2 (bits t) in
pow2 (bits t - i + 1) == 2 * (ub * 2 * v alpha - vb * v beta))) | let mod_inv_limb_inv_step_even #t n0 i ub0 vb0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = v ub0 / 2 % pow2 pbits in
let vb = v vb0 / 2 % pow2 pbits in
Math.Lemmas.small_mod (v ub0 / 2) (pow2 pbits);
Math.Lemmas.small_mod (v vb0 / 2) (pow2 pbits);
assert (ub * 2 * v alpha - vb * v beta == v ub0 / 2 * 2 * v alpha - v vb0 / 2 * v beta);
calc (==) {
2 * (ub * 2 * v alpha - vb * v beta);
(==) { }
2 * (v ub0 / 2 * 2 * v alpha - v vb0 / 2 * v beta);
(==) { Math.Lemmas.distributivity_sub_right 2 (v ub0 / 2 * 2 * v alpha) (v vb0 / 2 * v beta) }
2 * v ub0 / 2 * 2 * v alpha - 2 * (v vb0 / 2) * v beta;
(==) { Math.Lemmas.div_exact_r (v ub0) 2 }
v ub0 * 2 * v alpha - 2 * (v vb0 / 2) * v beta;
(==) { mod_inv_limb_inv_vb_is_even n0 i ub0 vb0; Math.Lemmas.div_exact_r (v vb0) 2 }
v ub0 * 2 * v alpha - v vb0 * v beta;
(==) {assert (pow2 (pbits - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta) }
pow2 (pbits - i + 1);
};
assert (2 * (ub * 2 * v alpha - vb * v beta) == pow2 (pbits - i + 1)) | {
"file_name": "code/bignum/Hacl.Spec.Bignum.ModInvLimb.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 129,
"start_col": 0,
"start_line": 107
} | module Hacl.Spec.Bignum.ModInvLimb
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
open Hacl.Spec.Bignum.Definitions
module M = Hacl.Spec.Montgomery.Lemmas
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(**
the modular inverse function was taken from
https://github.com/google/boringssl/blob/master/crypto/fipsmodule/bn/montgomery_inv.c *)
val mod_inv_limb_f:
#t:limb_t
-> alpha:limb t
-> beta:limb t
-> i:nat{i < bits t}
-> tuple2 (limb t) (limb t) ->
tuple2 (limb t) (limb t)
let mod_inv_limb_f #t alpha beta i (ub, vb) =
let u_is_odd = uint #t 0 -. (ub &. uint #t 1) in
let beta_if_u_is_odd = beta &. u_is_odd in
let u = ((ub ^. beta_if_u_is_odd) >>. 1ul) +. (ub &. beta_if_u_is_odd) in
let alpha_if_u_is_odd = alpha &. u_is_odd in
let v = (vb >>. 1ul) +. alpha_if_u_is_odd in
(u, v)
let mod_inv_limb_t (t:limb_t) (i:nat{i <= bits t}) = tuple2 (limb t) (limb t)
let mod_inv_limb #t n0 =
let alpha = uint #t 1 <<. size (bits t - 1) in
let beta = n0 in
let (u, v) = repeat_gen (bits t) (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
v
// Replace with `a >> 1 + b >> 1 + a & b & 1`?
val add_div_2_nooverflow: #t:limb_t -> a:limb t -> b:limb t ->
Lemma (v (((a ^. b) >>. 1ul) +. (a &. b)) == (v a + v b) / 2 % pow2 (bits t))
let add_div_2_nooverflow #t a b = admit()
val x_if_u_is_odd: #t:limb_t -> x:limb t -> u:limb t ->
Lemma (let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
v (x &. u_is_odd) == (if v u % 2 = 0 then 0 else v x))
let x_if_u_is_odd #t x u =
let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
logand_mask u (uint #t 1) 1;
assert (v (u &. uint #t 1) == v u % 2);
assert (v u_is_odd == (- v u % 2) % pow2 (bits t));
assert (v u_is_odd == (if v u % 2 = 0 then 0 else pow2 (bits t) - 1));
if v u % 2 = 0 then
logand_zeros x
else
logand_ones x
val mod_inv_limb_inv_vb_is_even:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures v vb0 % 2 = 0)
private
let aux_mod_2_neg (n:nat) : Lemma (n % 2 == (-n) % 2) =
()
let mod_inv_limb_inv_vb_is_even #t n0 i ub0 vb0 =
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 1 (bits t - i + 1);
assert (pow2 (bits t - i + 1) % 2 == 0);
calc (==) {
pow2 (bits t - i + 1) % 2;
(==) { }
(v ub0 * 2 * v alpha - v vb0 * v beta) % 2;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (v ub0 * 2 * v alpha) (- v vb0 * v beta) 2 }
(- v vb0 * v beta) % 2;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (- v vb0) (v beta) 2 }
(- v vb0) % 2;
(==) { aux_mod_2_neg (v vb0) } // flaky without the lemma call
v vb0 % 2;
}
val mod_inv_limb_inv_step_even:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ v ub0 % 2 = 0 /\
pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = v ub0 / 2 % pow2 (bits t) in
let vb = v vb0 / 2 % pow2 (bits t) in
pow2 (bits t - i + 1) == 2 * (ub * 2 * v alpha - vb * v beta))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.ModInvLimb.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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 |
n0: Hacl.Spec.Bignum.Definitions.limb t ->
i: Prims.pos{i <= Lib.IntTypes.bits t} ->
ub0: Hacl.Spec.Bignum.Definitions.limb t ->
vb0: Hacl.Spec.Bignum.Definitions.limb t
-> FStar.Pervasives.Lemma
(requires
(let alpha = Lib.IntTypes.uint 1 <<. Lib.IntTypes.size (Lib.IntTypes.bits t - 1) in
let beta = n0 in
Lib.IntTypes.v n0 % 2 = 1 /\ Lib.IntTypes.v ub0 % 2 = 0 /\
Prims.pow2 (Lib.IntTypes.bits t - i + 1) ==
(Lib.IntTypes.v ub0 * 2) * Lib.IntTypes.v alpha - Lib.IntTypes.v vb0 * Lib.IntTypes.v beta
))
(ensures
(let alpha = Lib.IntTypes.uint 1 <<. Lib.IntTypes.size (Lib.IntTypes.bits t - 1) in
let beta = n0 in
let ub = Lib.IntTypes.v ub0 / 2 % Prims.pow2 (Lib.IntTypes.bits t) in
let vb = Lib.IntTypes.v vb0 / 2 % Prims.pow2 (Lib.IntTypes.bits t) in
Prims.pow2 (Lib.IntTypes.bits t - i + 1) ==
2 * ((ub * 2) * Lib.IntTypes.v alpha - vb * Lib.IntTypes.v beta))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.bits",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.op_Subtraction",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Prims.op_Addition",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Prims.op_Division",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.distributivity_sub_right",
"FStar.Math.Lemmas.div_exact_r",
"Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_inv_vb_is_even",
"FStar.Math.Lemmas.small_mod",
"Prims.op_Modulus",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.uint",
"Lib.IntTypes.size"
] | [] | false | false | true | false | false | let mod_inv_limb_inv_step_even #t n0 i ub0 vb0 =
| let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let ub = v ub0 / 2 % pow2 pbits in
let vb = v vb0 / 2 % pow2 pbits in
Math.Lemmas.small_mod (v ub0 / 2) (pow2 pbits);
Math.Lemmas.small_mod (v vb0 / 2) (pow2 pbits);
assert ((ub * 2) * v alpha - vb * v beta == ((v ub0 / 2) * 2) * v alpha - (v vb0 / 2) * v beta);
calc ( == ) {
2 * ((ub * 2) * v alpha - vb * v beta);
( == ) { () }
2 * (((v ub0 / 2) * 2) * v alpha - (v vb0 / 2) * v beta);
( == ) { Math.Lemmas.distributivity_sub_right 2
(((v ub0 / 2) * 2) * v alpha)
((v vb0 / 2) * v beta) }
((2 * v ub0 / 2) * 2) * v alpha - (2 * (v vb0 / 2)) * v beta;
( == ) { Math.Lemmas.div_exact_r (v ub0) 2 }
(v ub0 * 2) * v alpha - (2 * (v vb0 / 2)) * v beta;
( == ) { (mod_inv_limb_inv_vb_is_even n0 i ub0 vb0;
Math.Lemmas.div_exact_r (v vb0) 2) }
(v ub0 * 2) * v alpha - v vb0 * v beta;
( == ) { assert (pow2 (pbits - i + 1) == (v ub0 * 2) * v alpha - v vb0 * v beta) }
pow2 (pbits - i + 1);
};
assert (2 * ((ub * 2) * v alpha - vb * v beta) == pow2 (pbits - i + 1)) | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_sorted_cons_elim | val list_sorted_cons_elim
(#t1: Type)
(key_order:
(t1 -> t1 -> bool){forall x y z. (key_order x y /\ key_order y z) ==> key_order x z})
(a: t1)
(q: list t1)
: Lemma (requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q) | val list_sorted_cons_elim
(#t1: Type)
(key_order:
(t1 -> t1 -> bool){forall x y z. (key_order x y /\ key_order y z) ==> key_order x z})
(a: t1)
(q: list t1)
: Lemma (requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q) | let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 53,
"end_line": 47,
"start_col": 0,
"start_line": 32
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
key_order:
(_: t1 -> _: t1 -> Prims.bool)
{forall (x: t1) (y: t1) (z: t1). key_order x y /\ key_order y z ==> key_order x z} ->
a: t1 ->
q: Prims.list t1
-> FStar.Pervasives.Lemma (requires FStar.List.Tot.Properties.sorted key_order (a :: q))
(ensures FStar.List.Tot.Base.for_all (key_order a) q)
(decreases q) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.bool",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_and",
"Prims.b2t",
"Prims.list",
"CBOR.Spec.Map.list_for_all_weaken",
"Prims.unit",
"CBOR.Spec.Map.list_sorted_cons_elim",
"FStar.List.Tot.Properties.sorted",
"Prims.Cons",
"Prims.squash",
"FStar.List.Tot.Base.for_all",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_sorted_cons_elim
(#t1: Type)
(key_order:
(t1 -> t1 -> bool){forall x y z. (key_order x y /\ key_order y z) ==> key_order x z})
(a: t1)
(q: list t1)
: Lemma (requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q) =
| match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_for_all_weaken | val list_for_all_weaken
(#t: Type)
(p1: (t -> bool))
(p2: (t -> bool){forall x. p1 x ==> p2 x})
(l: list t)
: Lemma (requires (List.Tot.for_all p1 l)) (ensures (List.Tot.for_all p2 l)) | val list_for_all_weaken
(#t: Type)
(p1: (t -> bool))
(p2: (t -> bool){forall x. p1 x ==> p2 x})
(l: list t)
: Lemma (requires (List.Tot.for_all p1 l)) (ensures (List.Tot.for_all p2 l)) | let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 41,
"end_line": 30,
"start_col": 0,
"start_line": 20
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: (_: t -> Prims.bool) ->
p2: (_: t -> Prims.bool){forall (x: t). p1 x ==> p2 x} ->
l: Prims.list t
-> FStar.Pervasives.Lemma (requires FStar.List.Tot.Base.for_all p1 l)
(ensures FStar.List.Tot.Base.for_all p2 l) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.bool",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.b2t",
"Prims.list",
"CBOR.Spec.Map.list_for_all_weaken",
"Prims.unit",
"FStar.List.Tot.Base.for_all",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_for_all_weaken
(#t: Type)
(p1: (t -> bool))
(p2: (t -> bool){forall x. p1 x ==> p2 x})
(l: list t)
: Lemma (requires (List.Tot.for_all p1 l)) (ensures (List.Tot.for_all p2 l)) =
| match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_sorted_map_entry_order_lt_tail | val list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order:
(t1 -> t1 -> bool){(forall x y z. (key_order x y /\ key_order y z) ==> key_order x z)})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires
(List.Tot.sorted (map_entry_order key_order _) (a :: l) /\
List.Tot.memP k (List.Tot.map fst l))) (ensures (key_order (fst a) k)) (decreases l) | val list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order:
(t1 -> t1 -> bool){(forall x y z. (key_order x y /\ key_order y z) ==> key_order x z)})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires
(List.Tot.sorted (map_entry_order key_order _) (a :: l) /\
List.Tot.memP k (List.Tot.map fst l))) (ensures (key_order (fst a) k)) (decreases l) | let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 58,
"end_line": 64,
"start_col": 0,
"start_line": 49
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
key_order:
(_: t1 -> _: t1 -> Prims.bool)
{forall (x: t1) (y: t1) (z: t1). key_order x y /\ key_order y z ==> key_order x z} ->
a: (t1 * t2) ->
l: Prims.list (t1 * t2) ->
k: t1
-> FStar.Pervasives.Lemma
(requires
FStar.List.Tot.Properties.sorted (CBOR.Spec.Type.map_entry_order key_order t2) (a :: l) /\
FStar.List.Tot.Base.memP k (FStar.List.Tot.Base.map FStar.Pervasives.Native.fst l))
(ensures key_order (FStar.Pervasives.Native.fst a) k)
(decreases l) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.bool",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_and",
"Prims.b2t",
"FStar.Pervasives.Native.tuple2",
"Prims.list",
"FStar.StrongExcludedMiddle.strong_excluded_middle",
"Prims.eq2",
"FStar.Pervasives.Native.fst",
"CBOR.Spec.Map.list_sorted_map_entry_order_lt_tail",
"Prims.unit",
"FStar.List.Tot.Properties.sorted",
"CBOR.Spec.Type.map_entry_order",
"Prims.Cons",
"FStar.List.Tot.Base.memP",
"FStar.List.Tot.Base.map",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order:
(t1 -> t1 -> bool){(forall x y z. (key_order x y /\ key_order y z) ==> key_order x z)})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires
(List.Tot.sorted (map_entry_order key_order _) (a :: l) /\
List.Tot.memP k (List.Tot.map fst l))) (ensures (key_order (fst a) k)) (decreases l) =
| let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k | false |
Hacl.Spec.Bignum.ModInvLimb.fst | Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_lemma | val mod_inv_limb_lemma: #t:limb_t -> n0:limb t -> Lemma
(requires v n0 % 2 == 1)
(ensures (1 + v n0 * v (mod_inv_limb n0)) % pow2 (bits t) == 0) | val mod_inv_limb_lemma: #t:limb_t -> n0:limb t -> Lemma
(requires v n0 % 2 == 1)
(ensures (1 + v n0 * v (mod_inv_limb n0)) % pow2 (bits t) == 0) | let mod_inv_limb_lemma #t n0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let (ub, vb) = repeat_gen pbits (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
mod_inv_limb_inv n0 pbits;
calc (==) {
(1 + v vb * v n0) % pow2 pbits;
(==) { }
(v ub * 2 * v alpha) % pow2 pbits;
(==) { Math.Lemmas.pow2_plus 1 (pbits - 1) }
(v ub * pow2 pbits) % pow2 pbits;
(==) { Math.Lemmas.cancel_mul_mod (v ub) (pow2 pbits) }
0;
};
assert ((1 + v vb * v n0) % pow2 pbits == 0) | {
"file_name": "code/bignum/Hacl.Spec.Bignum.ModInvLimb.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 267,
"start_col": 0,
"start_line": 252
} | module Hacl.Spec.Bignum.ModInvLimb
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
open Hacl.Spec.Bignum.Definitions
module M = Hacl.Spec.Montgomery.Lemmas
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(**
the modular inverse function was taken from
https://github.com/google/boringssl/blob/master/crypto/fipsmodule/bn/montgomery_inv.c *)
val mod_inv_limb_f:
#t:limb_t
-> alpha:limb t
-> beta:limb t
-> i:nat{i < bits t}
-> tuple2 (limb t) (limb t) ->
tuple2 (limb t) (limb t)
let mod_inv_limb_f #t alpha beta i (ub, vb) =
let u_is_odd = uint #t 0 -. (ub &. uint #t 1) in
let beta_if_u_is_odd = beta &. u_is_odd in
let u = ((ub ^. beta_if_u_is_odd) >>. 1ul) +. (ub &. beta_if_u_is_odd) in
let alpha_if_u_is_odd = alpha &. u_is_odd in
let v = (vb >>. 1ul) +. alpha_if_u_is_odd in
(u, v)
let mod_inv_limb_t (t:limb_t) (i:nat{i <= bits t}) = tuple2 (limb t) (limb t)
let mod_inv_limb #t n0 =
let alpha = uint #t 1 <<. size (bits t - 1) in
let beta = n0 in
let (u, v) = repeat_gen (bits t) (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
v
// Replace with `a >> 1 + b >> 1 + a & b & 1`?
val add_div_2_nooverflow: #t:limb_t -> a:limb t -> b:limb t ->
Lemma (v (((a ^. b) >>. 1ul) +. (a &. b)) == (v a + v b) / 2 % pow2 (bits t))
let add_div_2_nooverflow #t a b = admit()
val x_if_u_is_odd: #t:limb_t -> x:limb t -> u:limb t ->
Lemma (let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
v (x &. u_is_odd) == (if v u % 2 = 0 then 0 else v x))
let x_if_u_is_odd #t x u =
let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
logand_mask u (uint #t 1) 1;
assert (v (u &. uint #t 1) == v u % 2);
assert (v u_is_odd == (- v u % 2) % pow2 (bits t));
assert (v u_is_odd == (if v u % 2 = 0 then 0 else pow2 (bits t) - 1));
if v u % 2 = 0 then
logand_zeros x
else
logand_ones x
val mod_inv_limb_inv_vb_is_even:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures v vb0 % 2 = 0)
private
let aux_mod_2_neg (n:nat) : Lemma (n % 2 == (-n) % 2) =
()
let mod_inv_limb_inv_vb_is_even #t n0 i ub0 vb0 =
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 1 (bits t - i + 1);
assert (pow2 (bits t - i + 1) % 2 == 0);
calc (==) {
pow2 (bits t - i + 1) % 2;
(==) { }
(v ub0 * 2 * v alpha - v vb0 * v beta) % 2;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (v ub0 * 2 * v alpha) (- v vb0 * v beta) 2 }
(- v vb0 * v beta) % 2;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (- v vb0) (v beta) 2 }
(- v vb0) % 2;
(==) { aux_mod_2_neg (v vb0) } // flaky without the lemma call
v vb0 % 2;
}
val mod_inv_limb_inv_step_even:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ v ub0 % 2 = 0 /\
pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = v ub0 / 2 % pow2 (bits t) in
let vb = v vb0 / 2 % pow2 (bits t) in
pow2 (bits t - i + 1) == 2 * (ub * 2 * v alpha - vb * v beta)))
let mod_inv_limb_inv_step_even #t n0 i ub0 vb0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = v ub0 / 2 % pow2 pbits in
let vb = v vb0 / 2 % pow2 pbits in
Math.Lemmas.small_mod (v ub0 / 2) (pow2 pbits);
Math.Lemmas.small_mod (v vb0 / 2) (pow2 pbits);
assert (ub * 2 * v alpha - vb * v beta == v ub0 / 2 * 2 * v alpha - v vb0 / 2 * v beta);
calc (==) {
2 * (ub * 2 * v alpha - vb * v beta);
(==) { }
2 * (v ub0 / 2 * 2 * v alpha - v vb0 / 2 * v beta);
(==) { Math.Lemmas.distributivity_sub_right 2 (v ub0 / 2 * 2 * v alpha) (v vb0 / 2 * v beta) }
2 * v ub0 / 2 * 2 * v alpha - 2 * (v vb0 / 2) * v beta;
(==) { Math.Lemmas.div_exact_r (v ub0) 2 }
v ub0 * 2 * v alpha - 2 * (v vb0 / 2) * v beta;
(==) { mod_inv_limb_inv_vb_is_even n0 i ub0 vb0; Math.Lemmas.div_exact_r (v vb0) 2 }
v ub0 * 2 * v alpha - v vb0 * v beta;
(==) {assert (pow2 (pbits - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta) }
pow2 (pbits - i + 1);
};
assert (2 * (ub * 2 * v alpha - vb * v beta) == pow2 (pbits - i + 1))
#push-options "--z3rlimit 150"
val mod_inv_limb_inv_step_odd:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ v ub0 % 2 = 1 /\
pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = (v ub0 + v beta) / 2 % pow2 (bits t) in
let vb = (v vb0 / 2 + v alpha) % pow2 (bits t) in
pow2 (bits t - i + 1) == 2 * (ub * 2 * v alpha - vb * v beta)))
let mod_inv_limb_inv_step_odd #t n0 i ub0 vb0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = (v ub0 + v beta) / 2 % pow2 pbits in
let vb = (v vb0 / 2 + v alpha) % pow2 pbits in
calc (==) {
2 * (ub * 2 * v alpha - vb * v beta);
(==) { Math.Lemmas.small_mod ((v ub0 + v beta) / 2) (pow2 pbits) }
2 * ((v ub0 + v beta) / 2 * 2 * v alpha - vb * v beta);
(==) { Math.Lemmas.small_mod (v vb0 / 2 + v alpha) (pow2 pbits) }
2 * ((v ub0 + v beta) / 2 * 2 * v alpha - (v vb0 / 2 + v alpha) * v beta);
(==) { Math.Lemmas.distributivity_sub_right 2 ((v ub0 + v beta) / 2 * 2 * v alpha) ((v vb0 / 2 + v alpha) * v beta) }
2 * (v ub0 + v beta) / 2 * 2 * v alpha - 2 * (v vb0 / 2 + v alpha) * v beta;
(==) { Math.Lemmas.div_exact_r (v ub0 + v beta) 2 }
(v ub0 + v beta) * 2 * v alpha - 2 * (v vb0 / 2 + v alpha) * v beta;
(==) { Math.Lemmas.paren_mul_right 2 (v vb0 / 2 + v alpha) (v beta) }
(v ub0 + v beta) * 2 * v alpha - 2 * ((v vb0 / 2 + v alpha) * v beta);
(==) { Math.Lemmas.distributivity_add_left (v vb0 / 2) (v alpha) (v beta) }
(v ub0 + v beta) * 2 * v alpha - 2 * (v vb0 / 2 * v beta + v alpha * v beta);
(==) { Math.Lemmas.distributivity_add_right 2 (v vb0 / 2 * v beta) (v alpha * v beta);
Math.Lemmas.paren_mul_right 2 (v vb0 / 2) (v beta);
Math.Lemmas.paren_mul_right 2 (v alpha) (v beta) }
(v ub0 + v beta) * 2 * v alpha - (2 * (v vb0 / 2) * v beta + 2 * v alpha * v beta);
(==) { mod_inv_limb_inv_vb_is_even n0 i ub0 vb0; Math.Lemmas.div_exact_r (v vb0) 2 }
(v ub0 + v beta) * 2 * v alpha - (v vb0 * v beta + 2 * v alpha * v beta);
(==) { Math.Lemmas.distributivity_add_left (v ub0) (v beta) (2 * v alpha) }
v ub0 * 2 * v alpha + v beta * 2 * v alpha - (v vb0 * v beta + 2 * v alpha * v beta);
(==) { Math.Lemmas.paren_mul_right (v beta) 2 (v alpha); Math.Lemmas.swap_mul (v beta) (2 * v alpha) }
v ub0 * 2 * v alpha + 2 * v alpha * v beta - v vb0 * v beta - 2 * v alpha * v beta;
(==) { }
v ub0 * 2 * v alpha - v vb0 * v beta;
(==) { assert (pow2 (pbits - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta) }
pow2 (pbits - i + 1);
};
assert (2 * (ub * 2 * v alpha - vb * v beta) == pow2 (pbits - i + 1))
#pop-options
val mod_inv_limb_inv_step:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let (ub, vb) = mod_inv_limb_f alpha beta (i - 1) (ub0, vb0) in
pow2 (bits t - i) == v ub * 2 * v alpha - v vb * v beta))
let mod_inv_limb_inv_step #t n0 i ub0 vb0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let u_is_odd = uint #t 0 -. (ub0 &. uint #t 1) in
let beta_if_u_is_odd = beta &. u_is_odd in
let ub = ((ub0 ^. beta_if_u_is_odd) >>. 1ul) +. (ub0 &. beta_if_u_is_odd) in
let alpha_if_u_is_odd = alpha &. u_is_odd in
let vb = (vb0 >>. 1ul) +. alpha_if_u_is_odd in
x_if_u_is_odd beta ub0;
x_if_u_is_odd alpha ub0;
assert (v beta_if_u_is_odd == (if v ub0 % 2 = 0 then 0 else v beta));
assert (v alpha_if_u_is_odd == (if v ub0 % 2 = 0 then 0 else v alpha));
add_div_2_nooverflow ub0 beta_if_u_is_odd;
assert (v ub == (v ub0 + v beta_if_u_is_odd) / 2 % pow2 pbits);
assert (v ub == (if v ub0 % 2 = 0 then v ub0 / 2 % pow2 pbits else (v ub0 + v beta) / 2 % pow2 pbits));
Math.Lemmas.lemma_mod_plus_distr_l (v vb0 / 2) (v alpha_if_u_is_odd) (pow2 pbits);
assert (v vb == (v vb0 / 2 + v alpha_if_u_is_odd) % pow2 pbits);
assert (v vb == (if v ub0 % 2 = 0 then v vb0 / 2 % pow2 pbits else (v vb0 / 2 + v alpha) % pow2 pbits));
if v ub0 % 2 = 0 then
mod_inv_limb_inv_step_even n0 i ub0 vb0
else
mod_inv_limb_inv_step_odd n0 i ub0 vb0;
assert (2 * (v ub * 2 * v alpha - v vb * v beta) == pow2 (pbits - i + 1));
Math.Lemmas.cancel_mul_div (v ub * 2 * v alpha - v vb * v beta) 2;
Math.Lemmas.pow2_minus (pbits - i + 1) 1
val mod_inv_limb_inv: #t:limb_t -> n0:limb t -> i:nat{i <= bits t} -> Lemma
(requires v n0 % 2 = 1)
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let (ub, vb) = repeat_gen i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
pow2 (bits t - i) == v ub * 2 * v alpha - v vb * v beta))
let rec mod_inv_limb_inv #t n0 i =
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let (ub, vb) = repeat_gen i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
if i = 0 then
eq_repeat_gen0 i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0)
else begin
let (ub0, vb0) = repeat_gen (i - 1) (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
mod_inv_limb_inv n0 (i - 1);
assert (pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta);
unfold_repeat_gen i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) (i - 1);
assert ((ub, vb) == mod_inv_limb_f alpha beta (i - 1) (ub0, vb0));
mod_inv_limb_inv_step n0 i ub0 vb0;
() end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.ModInvLimb.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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 | n0: Hacl.Spec.Bignum.Definitions.limb t
-> FStar.Pervasives.Lemma (requires Lib.IntTypes.v n0 % 2 == 1)
(ensures
(1 + Lib.IntTypes.v n0 * Lib.IntTypes.v (Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb n0)) %
Prims.pow2 (Lib.IntTypes.bits t) ==
0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.pow2_plus",
"Prims.op_Subtraction",
"FStar.Math.Lemmas.cancel_mul_mod",
"Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_inv",
"Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_t",
"Lib.LoopCombinators.repeat_gen",
"Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_f",
"FStar.Pervasives.Native.Mktuple2",
"Lib.IntTypes.uint",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.size",
"Lib.IntTypes.bits"
] | [] | false | false | true | false | false | let mod_inv_limb_lemma #t n0 =
| let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let ub, vb =
repeat_gen pbits (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0)
in
mod_inv_limb_inv n0 pbits;
calc ( == ) {
(1 + v vb * v n0) % pow2 pbits;
( == ) { () }
((v ub * 2) * v alpha) % pow2 pbits;
( == ) { Math.Lemmas.pow2_plus 1 (pbits - 1) }
(v ub * pow2 pbits) % pow2 pbits;
( == ) { Math.Lemmas.cancel_mul_mod (v ub) (pow2 pbits) }
0;
};
assert ((1 + v vb * v n0) % pow2 pbits == 0) | false |
Hacl.Spec.Bignum.ModInvLimb.fst | Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_inv_step | val mod_inv_limb_inv_step:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let (ub, vb) = mod_inv_limb_f alpha beta (i - 1) (ub0, vb0) in
pow2 (bits t - i) == v ub * 2 * v alpha - v vb * v beta)) | val mod_inv_limb_inv_step:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let (ub, vb) = mod_inv_limb_f alpha beta (i - 1) (ub0, vb0) in
pow2 (bits t - i) == v ub * 2 * v alpha - v vb * v beta)) | let mod_inv_limb_inv_step #t n0 i ub0 vb0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let u_is_odd = uint #t 0 -. (ub0 &. uint #t 1) in
let beta_if_u_is_odd = beta &. u_is_odd in
let ub = ((ub0 ^. beta_if_u_is_odd) >>. 1ul) +. (ub0 &. beta_if_u_is_odd) in
let alpha_if_u_is_odd = alpha &. u_is_odd in
let vb = (vb0 >>. 1ul) +. alpha_if_u_is_odd in
x_if_u_is_odd beta ub0;
x_if_u_is_odd alpha ub0;
assert (v beta_if_u_is_odd == (if v ub0 % 2 = 0 then 0 else v beta));
assert (v alpha_if_u_is_odd == (if v ub0 % 2 = 0 then 0 else v alpha));
add_div_2_nooverflow ub0 beta_if_u_is_odd;
assert (v ub == (v ub0 + v beta_if_u_is_odd) / 2 % pow2 pbits);
assert (v ub == (if v ub0 % 2 = 0 then v ub0 / 2 % pow2 pbits else (v ub0 + v beta) / 2 % pow2 pbits));
Math.Lemmas.lemma_mod_plus_distr_l (v vb0 / 2) (v alpha_if_u_is_odd) (pow2 pbits);
assert (v vb == (v vb0 / 2 + v alpha_if_u_is_odd) % pow2 pbits);
assert (v vb == (if v ub0 % 2 = 0 then v vb0 / 2 % pow2 pbits else (v vb0 / 2 + v alpha) % pow2 pbits));
if v ub0 % 2 = 0 then
mod_inv_limb_inv_step_even n0 i ub0 vb0
else
mod_inv_limb_inv_step_odd n0 i ub0 vb0;
assert (2 * (v ub * 2 * v alpha - v vb * v beta) == pow2 (pbits - i + 1));
Math.Lemmas.cancel_mul_div (v ub * 2 * v alpha - v vb * v beta) 2;
Math.Lemmas.pow2_minus (pbits - i + 1) 1 | {
"file_name": "code/bignum/Hacl.Spec.Bignum.ModInvLimb.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 225,
"start_col": 0,
"start_line": 196
} | module Hacl.Spec.Bignum.ModInvLimb
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
open Hacl.Spec.Bignum.Definitions
module M = Hacl.Spec.Montgomery.Lemmas
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(**
the modular inverse function was taken from
https://github.com/google/boringssl/blob/master/crypto/fipsmodule/bn/montgomery_inv.c *)
val mod_inv_limb_f:
#t:limb_t
-> alpha:limb t
-> beta:limb t
-> i:nat{i < bits t}
-> tuple2 (limb t) (limb t) ->
tuple2 (limb t) (limb t)
let mod_inv_limb_f #t alpha beta i (ub, vb) =
let u_is_odd = uint #t 0 -. (ub &. uint #t 1) in
let beta_if_u_is_odd = beta &. u_is_odd in
let u = ((ub ^. beta_if_u_is_odd) >>. 1ul) +. (ub &. beta_if_u_is_odd) in
let alpha_if_u_is_odd = alpha &. u_is_odd in
let v = (vb >>. 1ul) +. alpha_if_u_is_odd in
(u, v)
let mod_inv_limb_t (t:limb_t) (i:nat{i <= bits t}) = tuple2 (limb t) (limb t)
let mod_inv_limb #t n0 =
let alpha = uint #t 1 <<. size (bits t - 1) in
let beta = n0 in
let (u, v) = repeat_gen (bits t) (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
v
// Replace with `a >> 1 + b >> 1 + a & b & 1`?
val add_div_2_nooverflow: #t:limb_t -> a:limb t -> b:limb t ->
Lemma (v (((a ^. b) >>. 1ul) +. (a &. b)) == (v a + v b) / 2 % pow2 (bits t))
let add_div_2_nooverflow #t a b = admit()
val x_if_u_is_odd: #t:limb_t -> x:limb t -> u:limb t ->
Lemma (let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
v (x &. u_is_odd) == (if v u % 2 = 0 then 0 else v x))
let x_if_u_is_odd #t x u =
let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
logand_mask u (uint #t 1) 1;
assert (v (u &. uint #t 1) == v u % 2);
assert (v u_is_odd == (- v u % 2) % pow2 (bits t));
assert (v u_is_odd == (if v u % 2 = 0 then 0 else pow2 (bits t) - 1));
if v u % 2 = 0 then
logand_zeros x
else
logand_ones x
val mod_inv_limb_inv_vb_is_even:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures v vb0 % 2 = 0)
private
let aux_mod_2_neg (n:nat) : Lemma (n % 2 == (-n) % 2) =
()
let mod_inv_limb_inv_vb_is_even #t n0 i ub0 vb0 =
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 1 (bits t - i + 1);
assert (pow2 (bits t - i + 1) % 2 == 0);
calc (==) {
pow2 (bits t - i + 1) % 2;
(==) { }
(v ub0 * 2 * v alpha - v vb0 * v beta) % 2;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (v ub0 * 2 * v alpha) (- v vb0 * v beta) 2 }
(- v vb0 * v beta) % 2;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (- v vb0) (v beta) 2 }
(- v vb0) % 2;
(==) { aux_mod_2_neg (v vb0) } // flaky without the lemma call
v vb0 % 2;
}
val mod_inv_limb_inv_step_even:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ v ub0 % 2 = 0 /\
pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = v ub0 / 2 % pow2 (bits t) in
let vb = v vb0 / 2 % pow2 (bits t) in
pow2 (bits t - i + 1) == 2 * (ub * 2 * v alpha - vb * v beta)))
let mod_inv_limb_inv_step_even #t n0 i ub0 vb0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = v ub0 / 2 % pow2 pbits in
let vb = v vb0 / 2 % pow2 pbits in
Math.Lemmas.small_mod (v ub0 / 2) (pow2 pbits);
Math.Lemmas.small_mod (v vb0 / 2) (pow2 pbits);
assert (ub * 2 * v alpha - vb * v beta == v ub0 / 2 * 2 * v alpha - v vb0 / 2 * v beta);
calc (==) {
2 * (ub * 2 * v alpha - vb * v beta);
(==) { }
2 * (v ub0 / 2 * 2 * v alpha - v vb0 / 2 * v beta);
(==) { Math.Lemmas.distributivity_sub_right 2 (v ub0 / 2 * 2 * v alpha) (v vb0 / 2 * v beta) }
2 * v ub0 / 2 * 2 * v alpha - 2 * (v vb0 / 2) * v beta;
(==) { Math.Lemmas.div_exact_r (v ub0) 2 }
v ub0 * 2 * v alpha - 2 * (v vb0 / 2) * v beta;
(==) { mod_inv_limb_inv_vb_is_even n0 i ub0 vb0; Math.Lemmas.div_exact_r (v vb0) 2 }
v ub0 * 2 * v alpha - v vb0 * v beta;
(==) {assert (pow2 (pbits - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta) }
pow2 (pbits - i + 1);
};
assert (2 * (ub * 2 * v alpha - vb * v beta) == pow2 (pbits - i + 1))
#push-options "--z3rlimit 150"
val mod_inv_limb_inv_step_odd:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ v ub0 % 2 = 1 /\
pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = (v ub0 + v beta) / 2 % pow2 (bits t) in
let vb = (v vb0 / 2 + v alpha) % pow2 (bits t) in
pow2 (bits t - i + 1) == 2 * (ub * 2 * v alpha - vb * v beta)))
let mod_inv_limb_inv_step_odd #t n0 i ub0 vb0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = (v ub0 + v beta) / 2 % pow2 pbits in
let vb = (v vb0 / 2 + v alpha) % pow2 pbits in
calc (==) {
2 * (ub * 2 * v alpha - vb * v beta);
(==) { Math.Lemmas.small_mod ((v ub0 + v beta) / 2) (pow2 pbits) }
2 * ((v ub0 + v beta) / 2 * 2 * v alpha - vb * v beta);
(==) { Math.Lemmas.small_mod (v vb0 / 2 + v alpha) (pow2 pbits) }
2 * ((v ub0 + v beta) / 2 * 2 * v alpha - (v vb0 / 2 + v alpha) * v beta);
(==) { Math.Lemmas.distributivity_sub_right 2 ((v ub0 + v beta) / 2 * 2 * v alpha) ((v vb0 / 2 + v alpha) * v beta) }
2 * (v ub0 + v beta) / 2 * 2 * v alpha - 2 * (v vb0 / 2 + v alpha) * v beta;
(==) { Math.Lemmas.div_exact_r (v ub0 + v beta) 2 }
(v ub0 + v beta) * 2 * v alpha - 2 * (v vb0 / 2 + v alpha) * v beta;
(==) { Math.Lemmas.paren_mul_right 2 (v vb0 / 2 + v alpha) (v beta) }
(v ub0 + v beta) * 2 * v alpha - 2 * ((v vb0 / 2 + v alpha) * v beta);
(==) { Math.Lemmas.distributivity_add_left (v vb0 / 2) (v alpha) (v beta) }
(v ub0 + v beta) * 2 * v alpha - 2 * (v vb0 / 2 * v beta + v alpha * v beta);
(==) { Math.Lemmas.distributivity_add_right 2 (v vb0 / 2 * v beta) (v alpha * v beta);
Math.Lemmas.paren_mul_right 2 (v vb0 / 2) (v beta);
Math.Lemmas.paren_mul_right 2 (v alpha) (v beta) }
(v ub0 + v beta) * 2 * v alpha - (2 * (v vb0 / 2) * v beta + 2 * v alpha * v beta);
(==) { mod_inv_limb_inv_vb_is_even n0 i ub0 vb0; Math.Lemmas.div_exact_r (v vb0) 2 }
(v ub0 + v beta) * 2 * v alpha - (v vb0 * v beta + 2 * v alpha * v beta);
(==) { Math.Lemmas.distributivity_add_left (v ub0) (v beta) (2 * v alpha) }
v ub0 * 2 * v alpha + v beta * 2 * v alpha - (v vb0 * v beta + 2 * v alpha * v beta);
(==) { Math.Lemmas.paren_mul_right (v beta) 2 (v alpha); Math.Lemmas.swap_mul (v beta) (2 * v alpha) }
v ub0 * 2 * v alpha + 2 * v alpha * v beta - v vb0 * v beta - 2 * v alpha * v beta;
(==) { }
v ub0 * 2 * v alpha - v vb0 * v beta;
(==) { assert (pow2 (pbits - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta) }
pow2 (pbits - i + 1);
};
assert (2 * (ub * 2 * v alpha - vb * v beta) == pow2 (pbits - i + 1))
#pop-options
val mod_inv_limb_inv_step:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let (ub, vb) = mod_inv_limb_f alpha beta (i - 1) (ub0, vb0) in
pow2 (bits t - i) == v ub * 2 * v alpha - v vb * v beta)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.ModInvLimb.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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 |
n0: Hacl.Spec.Bignum.Definitions.limb t ->
i: Prims.pos{i <= Lib.IntTypes.bits t} ->
ub0: Hacl.Spec.Bignum.Definitions.limb t ->
vb0: Hacl.Spec.Bignum.Definitions.limb t
-> FStar.Pervasives.Lemma
(requires
(let alpha = Lib.IntTypes.uint 1 <<. Lib.IntTypes.size (Lib.IntTypes.bits t - 1) in
let beta = n0 in
Lib.IntTypes.v n0 % 2 = 1 /\
Prims.pow2 (Lib.IntTypes.bits t - i + 1) ==
(Lib.IntTypes.v ub0 * 2) * Lib.IntTypes.v alpha - Lib.IntTypes.v vb0 * Lib.IntTypes.v beta
))
(ensures
(let alpha = Lib.IntTypes.uint 1 <<. Lib.IntTypes.size (Lib.IntTypes.bits t - 1) in
let beta = n0 in
let _ = Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_f alpha beta (i - 1) (ub0, vb0) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ ub vb = _ in
Prims.pow2 (Lib.IntTypes.bits t - i) ==
(Lib.IntTypes.v ub * 2) * Lib.IntTypes.v alpha - Lib.IntTypes.v vb * Lib.IntTypes.v beta
)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.bits",
"FStar.Math.Lemmas.pow2_minus",
"Prims.op_Addition",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Math.Lemmas.cancel_mul_div",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.pow2",
"Prims.op_Equality",
"Prims.op_Modulus",
"Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_inv_step_even",
"Prims.bool",
"Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_inv_step_odd",
"Prims.op_Division",
"FStar.Math.Lemmas.lemma_mod_plus_distr_l",
"Hacl.Spec.Bignum.ModInvLimb.add_div_2_nooverflow",
"Hacl.Spec.Bignum.ModInvLimb.x_if_u_is_odd",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.op_Greater_Greater_Dot",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Amp_Dot",
"Lib.IntTypes.op_Hat_Dot",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.uint",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.size"
] | [] | false | false | true | false | false | let mod_inv_limb_inv_step #t n0 i ub0 vb0 =
| let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let u_is_odd = uint #t 0 -. (ub0 &. uint #t 1) in
let beta_if_u_is_odd = beta &. u_is_odd in
let ub = ((ub0 ^. beta_if_u_is_odd) >>. 1ul) +. (ub0 &. beta_if_u_is_odd) in
let alpha_if_u_is_odd = alpha &. u_is_odd in
let vb = (vb0 >>. 1ul) +. alpha_if_u_is_odd in
x_if_u_is_odd beta ub0;
x_if_u_is_odd alpha ub0;
assert (v beta_if_u_is_odd == (if v ub0 % 2 = 0 then 0 else v beta));
assert (v alpha_if_u_is_odd == (if v ub0 % 2 = 0 then 0 else v alpha));
add_div_2_nooverflow ub0 beta_if_u_is_odd;
assert (v ub == (v ub0 + v beta_if_u_is_odd) / 2 % pow2 pbits);
assert (v ub ==
(if v ub0 % 2 = 0 then v ub0 / 2 % pow2 pbits else (v ub0 + v beta) / 2 % pow2 pbits));
Math.Lemmas.lemma_mod_plus_distr_l (v vb0 / 2) (v alpha_if_u_is_odd) (pow2 pbits);
assert (v vb == (v vb0 / 2 + v alpha_if_u_is_odd) % pow2 pbits);
assert (v vb ==
(if v ub0 % 2 = 0 then v vb0 / 2 % pow2 pbits else (v vb0 / 2 + v alpha) % pow2 pbits));
if v ub0 % 2 = 0
then mod_inv_limb_inv_step_even n0 i ub0 vb0
else mod_inv_limb_inv_step_odd n0 i ub0 vb0;
assert (2 * ((v ub * 2) * v alpha - v vb * v beta) == pow2 (pbits - i + 1));
Math.Lemmas.cancel_mul_div ((v ub * 2) * v alpha - v vb * v beta) 2;
Math.Lemmas.pow2_minus (pbits - i + 1) 1 | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_tot_for_all_order_trans | val list_tot_for_all_order_trans
(#t1: Type)
(order:
(t1 -> t1 -> bool)
{ (forall x. order x x == false) /\
(forall x y z. (order x y /\ order y z) ==> order x z) })
(k1v1 k2v2: _)
(l1: list t1)
: Lemma (requires (order k1v1 k2v2 /\ List.Tot.for_all (order k2v2) l1))
(ensures (List.Tot.for_all (order k1v1) l1))
(decreases l1) | val list_tot_for_all_order_trans
(#t1: Type)
(order:
(t1 -> t1 -> bool)
{ (forall x. order x x == false) /\
(forall x y z. (order x y /\ order y z) ==> order x z) })
(k1v1 k2v2: _)
(l1: list t1)
: Lemma (requires (order k1v1 k2v2 /\ List.Tot.for_all (order k2v2) l1))
(ensures (List.Tot.for_all (order k1v1) l1))
(decreases l1) | let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 60,
"end_line": 114,
"start_col": 0,
"start_line": 95
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
order:
(_: t1 -> _: t1 -> Prims.bool)
{ (forall (x: t1). order x x == false) /\
(forall (x: t1) (y: t1) (z: t1). order x y /\ order y z ==> order x z) } ->
k1v1: t1 ->
k2v2: t1 ->
l1: Prims.list t1
-> FStar.Pervasives.Lemma
(requires order k1v1 k2v2 /\ FStar.List.Tot.Base.for_all (order k2v2) l1)
(ensures FStar.List.Tot.Base.for_all (order k1v1) l1)
(decreases l1) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.bool",
"Prims.l_and",
"Prims.l_Forall",
"Prims.eq2",
"Prims.l_imp",
"Prims.b2t",
"Prims.list",
"CBOR.Spec.Map.list_tot_for_all_order_trans",
"Prims.unit",
"FStar.List.Tot.Base.for_all",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_tot_for_all_order_trans
(#t1: Type)
(order:
(t1 -> t1 -> bool)
{ (forall x. order x x == false) /\
(forall x y z. (order x y /\ order y z) ==> order x z) })
(k1v1 k2v2: _)
(l1: list t1)
: Lemma (requires (order k1v1 k2v2 /\ List.Tot.for_all (order k2v2) l1))
(ensures (List.Tot.for_all (order k1v1) l1))
(decreases l1) =
| match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_ghost_assoc | val list_ghost_assoc (#key #value: Type) (k: key) (m: list (key & value))
: GTot (option value) (decreases m) | val list_ghost_assoc (#key #value: Type) (k: key) (m: list (key & value))
: GTot (option value) (decreases m) | let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m' | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 30,
"end_line": 128,
"start_col": 0,
"start_line": 116
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: key -> m: Prims.list (key * value) -> Prims.GTot (FStar.Pervasives.Native.option value) | Prims.GTot | [
"sometrivial",
""
] | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.None",
"FStar.StrongExcludedMiddle.strong_excluded_middle",
"Prims.eq2",
"FStar.Pervasives.Native.Some",
"Prims.bool",
"CBOR.Spec.Map.list_ghost_assoc",
"FStar.Pervasives.Native.option"
] | [
"recursion"
] | false | false | false | false | false | let rec list_ghost_assoc (#key #value: Type) (k: key) (m: list (key & value))
: GTot (option value) (decreases m) =
| match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m' | false |
Hacl.Impl.Chacha20.Core32.fst | Hacl.Impl.Chacha20.Core32.copy_state | val copy_state:
st:state
-> ost:state ->
Stack unit
(requires fun h -> live h st /\ live h ost /\ disjoint st ost)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == as_seq h0 ost) | val copy_state:
st:state
-> ost:state ->
Stack unit
(requires fun h -> live h st /\ live h ost /\ disjoint st ost)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == as_seq h0 ost) | let copy_state st ost = copy #MUT #uint32 #(size 16) st ost | {
"file_name": "code/chacha20/Hacl.Impl.Chacha20.Core32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 59,
"end_line": 90,
"start_col": 0,
"start_line": 90
} | module Hacl.Impl.Chacha20.Core32
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Sequence
open Lib.Buffer
open Lib.ByteBuffer
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20
let state = lbuffer uint32 16ul
let index = i:size_t{size_v i < 16}
inline_for_extraction
val create_state: unit ->
StackInline state
(requires fun h -> True)
(ensures fun h0 r h1 -> live h1 r /\
as_seq h1 r == Seq.create 16 (u32 0) /\
stack_allocated r h0 h1 (Seq.create 16 (u32 0)))
let create_state () = create (size 16) (u32 0)
inline_for_extraction
val load_state:
st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Lib.ByteSequence.uints_from_bytes_le (as_seq h0 b))
let load_state st b =
uints_from_bytes_le st b
inline_for_extraction
val store_state:
b:lbuffer uint8 64ul
-> st:state ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == Lib.ByteSequence.uints_to_bytes_le (as_seq h0 st))
let store_state st b =
uints_to_bytes_le 16ul st b
inline_for_extraction
val set_counter:
st:state
-> c:size_t ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Seq.upd (as_seq h0 st) 12 (size_to_uint32 c))
let set_counter st c =
st.(size 12) <- size_to_uint32 c
inline_for_extraction
val incr_counter:
st:state ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1)
let incr_counter st =
let c = st.(size 12) in
st.(size 12) <- c +. u32 1
inline_for_extraction
val copy_state:
st:state
-> ost:state ->
Stack unit
(requires fun h -> live h st /\ live h ost /\ disjoint st ost)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == as_seq h0 ost) | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20.Core32.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | st: Hacl.Impl.Chacha20.Core32.state -> ost: Hacl.Impl.Chacha20.Core32.state
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Chacha20.Core32.state",
"Lib.Buffer.copy",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint32",
"Lib.IntTypes.size",
"Prims.unit"
] | [] | false | true | false | false | false | let copy_state st ost =
| copy #MUT #uint32 #(size 16) st ost | false |
Hacl.Spec.Bignum.ModInvLimb.fst | Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_inv | val mod_inv_limb_inv: #t:limb_t -> n0:limb t -> i:nat{i <= bits t} -> Lemma
(requires v n0 % 2 = 1)
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let (ub, vb) = repeat_gen i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
pow2 (bits t - i) == v ub * 2 * v alpha - v vb * v beta)) | val mod_inv_limb_inv: #t:limb_t -> n0:limb t -> i:nat{i <= bits t} -> Lemma
(requires v n0 % 2 = 1)
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let (ub, vb) = repeat_gen i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
pow2 (bits t - i) == v ub * 2 * v alpha - v vb * v beta)) | let rec mod_inv_limb_inv #t n0 i =
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let (ub, vb) = repeat_gen i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
if i = 0 then
eq_repeat_gen0 i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0)
else begin
let (ub0, vb0) = repeat_gen (i - 1) (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
mod_inv_limb_inv n0 (i - 1);
assert (pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta);
unfold_repeat_gen i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) (i - 1);
assert ((ub, vb) == mod_inv_limb_f alpha beta (i - 1) (ub0, vb0));
mod_inv_limb_inv_step n0 i ub0 vb0;
() end | {
"file_name": "code/bignum/Hacl.Spec.Bignum.ModInvLimb.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 249,
"start_col": 0,
"start_line": 236
} | module Hacl.Spec.Bignum.ModInvLimb
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
open Hacl.Spec.Bignum.Definitions
module M = Hacl.Spec.Montgomery.Lemmas
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(**
the modular inverse function was taken from
https://github.com/google/boringssl/blob/master/crypto/fipsmodule/bn/montgomery_inv.c *)
val mod_inv_limb_f:
#t:limb_t
-> alpha:limb t
-> beta:limb t
-> i:nat{i < bits t}
-> tuple2 (limb t) (limb t) ->
tuple2 (limb t) (limb t)
let mod_inv_limb_f #t alpha beta i (ub, vb) =
let u_is_odd = uint #t 0 -. (ub &. uint #t 1) in
let beta_if_u_is_odd = beta &. u_is_odd in
let u = ((ub ^. beta_if_u_is_odd) >>. 1ul) +. (ub &. beta_if_u_is_odd) in
let alpha_if_u_is_odd = alpha &. u_is_odd in
let v = (vb >>. 1ul) +. alpha_if_u_is_odd in
(u, v)
let mod_inv_limb_t (t:limb_t) (i:nat{i <= bits t}) = tuple2 (limb t) (limb t)
let mod_inv_limb #t n0 =
let alpha = uint #t 1 <<. size (bits t - 1) in
let beta = n0 in
let (u, v) = repeat_gen (bits t) (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
v
// Replace with `a >> 1 + b >> 1 + a & b & 1`?
val add_div_2_nooverflow: #t:limb_t -> a:limb t -> b:limb t ->
Lemma (v (((a ^. b) >>. 1ul) +. (a &. b)) == (v a + v b) / 2 % pow2 (bits t))
let add_div_2_nooverflow #t a b = admit()
val x_if_u_is_odd: #t:limb_t -> x:limb t -> u:limb t ->
Lemma (let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
v (x &. u_is_odd) == (if v u % 2 = 0 then 0 else v x))
let x_if_u_is_odd #t x u =
let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
logand_mask u (uint #t 1) 1;
assert (v (u &. uint #t 1) == v u % 2);
assert (v u_is_odd == (- v u % 2) % pow2 (bits t));
assert (v u_is_odd == (if v u % 2 = 0 then 0 else pow2 (bits t) - 1));
if v u % 2 = 0 then
logand_zeros x
else
logand_ones x
val mod_inv_limb_inv_vb_is_even:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures v vb0 % 2 = 0)
private
let aux_mod_2_neg (n:nat) : Lemma (n % 2 == (-n) % 2) =
()
let mod_inv_limb_inv_vb_is_even #t n0 i ub0 vb0 =
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 1 (bits t - i + 1);
assert (pow2 (bits t - i + 1) % 2 == 0);
calc (==) {
pow2 (bits t - i + 1) % 2;
(==) { }
(v ub0 * 2 * v alpha - v vb0 * v beta) % 2;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (v ub0 * 2 * v alpha) (- v vb0 * v beta) 2 }
(- v vb0 * v beta) % 2;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (- v vb0) (v beta) 2 }
(- v vb0) % 2;
(==) { aux_mod_2_neg (v vb0) } // flaky without the lemma call
v vb0 % 2;
}
val mod_inv_limb_inv_step_even:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ v ub0 % 2 = 0 /\
pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = v ub0 / 2 % pow2 (bits t) in
let vb = v vb0 / 2 % pow2 (bits t) in
pow2 (bits t - i + 1) == 2 * (ub * 2 * v alpha - vb * v beta)))
let mod_inv_limb_inv_step_even #t n0 i ub0 vb0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = v ub0 / 2 % pow2 pbits in
let vb = v vb0 / 2 % pow2 pbits in
Math.Lemmas.small_mod (v ub0 / 2) (pow2 pbits);
Math.Lemmas.small_mod (v vb0 / 2) (pow2 pbits);
assert (ub * 2 * v alpha - vb * v beta == v ub0 / 2 * 2 * v alpha - v vb0 / 2 * v beta);
calc (==) {
2 * (ub * 2 * v alpha - vb * v beta);
(==) { }
2 * (v ub0 / 2 * 2 * v alpha - v vb0 / 2 * v beta);
(==) { Math.Lemmas.distributivity_sub_right 2 (v ub0 / 2 * 2 * v alpha) (v vb0 / 2 * v beta) }
2 * v ub0 / 2 * 2 * v alpha - 2 * (v vb0 / 2) * v beta;
(==) { Math.Lemmas.div_exact_r (v ub0) 2 }
v ub0 * 2 * v alpha - 2 * (v vb0 / 2) * v beta;
(==) { mod_inv_limb_inv_vb_is_even n0 i ub0 vb0; Math.Lemmas.div_exact_r (v vb0) 2 }
v ub0 * 2 * v alpha - v vb0 * v beta;
(==) {assert (pow2 (pbits - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta) }
pow2 (pbits - i + 1);
};
assert (2 * (ub * 2 * v alpha - vb * v beta) == pow2 (pbits - i + 1))
#push-options "--z3rlimit 150"
val mod_inv_limb_inv_step_odd:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ v ub0 % 2 = 1 /\
pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = (v ub0 + v beta) / 2 % pow2 (bits t) in
let vb = (v vb0 / 2 + v alpha) % pow2 (bits t) in
pow2 (bits t - i + 1) == 2 * (ub * 2 * v alpha - vb * v beta)))
let mod_inv_limb_inv_step_odd #t n0 i ub0 vb0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = (v ub0 + v beta) / 2 % pow2 pbits in
let vb = (v vb0 / 2 + v alpha) % pow2 pbits in
calc (==) {
2 * (ub * 2 * v alpha - vb * v beta);
(==) { Math.Lemmas.small_mod ((v ub0 + v beta) / 2) (pow2 pbits) }
2 * ((v ub0 + v beta) / 2 * 2 * v alpha - vb * v beta);
(==) { Math.Lemmas.small_mod (v vb0 / 2 + v alpha) (pow2 pbits) }
2 * ((v ub0 + v beta) / 2 * 2 * v alpha - (v vb0 / 2 + v alpha) * v beta);
(==) { Math.Lemmas.distributivity_sub_right 2 ((v ub0 + v beta) / 2 * 2 * v alpha) ((v vb0 / 2 + v alpha) * v beta) }
2 * (v ub0 + v beta) / 2 * 2 * v alpha - 2 * (v vb0 / 2 + v alpha) * v beta;
(==) { Math.Lemmas.div_exact_r (v ub0 + v beta) 2 }
(v ub0 + v beta) * 2 * v alpha - 2 * (v vb0 / 2 + v alpha) * v beta;
(==) { Math.Lemmas.paren_mul_right 2 (v vb0 / 2 + v alpha) (v beta) }
(v ub0 + v beta) * 2 * v alpha - 2 * ((v vb0 / 2 + v alpha) * v beta);
(==) { Math.Lemmas.distributivity_add_left (v vb0 / 2) (v alpha) (v beta) }
(v ub0 + v beta) * 2 * v alpha - 2 * (v vb0 / 2 * v beta + v alpha * v beta);
(==) { Math.Lemmas.distributivity_add_right 2 (v vb0 / 2 * v beta) (v alpha * v beta);
Math.Lemmas.paren_mul_right 2 (v vb0 / 2) (v beta);
Math.Lemmas.paren_mul_right 2 (v alpha) (v beta) }
(v ub0 + v beta) * 2 * v alpha - (2 * (v vb0 / 2) * v beta + 2 * v alpha * v beta);
(==) { mod_inv_limb_inv_vb_is_even n0 i ub0 vb0; Math.Lemmas.div_exact_r (v vb0) 2 }
(v ub0 + v beta) * 2 * v alpha - (v vb0 * v beta + 2 * v alpha * v beta);
(==) { Math.Lemmas.distributivity_add_left (v ub0) (v beta) (2 * v alpha) }
v ub0 * 2 * v alpha + v beta * 2 * v alpha - (v vb0 * v beta + 2 * v alpha * v beta);
(==) { Math.Lemmas.paren_mul_right (v beta) 2 (v alpha); Math.Lemmas.swap_mul (v beta) (2 * v alpha) }
v ub0 * 2 * v alpha + 2 * v alpha * v beta - v vb0 * v beta - 2 * v alpha * v beta;
(==) { }
v ub0 * 2 * v alpha - v vb0 * v beta;
(==) { assert (pow2 (pbits - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta) }
pow2 (pbits - i + 1);
};
assert (2 * (ub * 2 * v alpha - vb * v beta) == pow2 (pbits - i + 1))
#pop-options
val mod_inv_limb_inv_step:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let (ub, vb) = mod_inv_limb_f alpha beta (i - 1) (ub0, vb0) in
pow2 (bits t - i) == v ub * 2 * v alpha - v vb * v beta))
let mod_inv_limb_inv_step #t n0 i ub0 vb0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let u_is_odd = uint #t 0 -. (ub0 &. uint #t 1) in
let beta_if_u_is_odd = beta &. u_is_odd in
let ub = ((ub0 ^. beta_if_u_is_odd) >>. 1ul) +. (ub0 &. beta_if_u_is_odd) in
let alpha_if_u_is_odd = alpha &. u_is_odd in
let vb = (vb0 >>. 1ul) +. alpha_if_u_is_odd in
x_if_u_is_odd beta ub0;
x_if_u_is_odd alpha ub0;
assert (v beta_if_u_is_odd == (if v ub0 % 2 = 0 then 0 else v beta));
assert (v alpha_if_u_is_odd == (if v ub0 % 2 = 0 then 0 else v alpha));
add_div_2_nooverflow ub0 beta_if_u_is_odd;
assert (v ub == (v ub0 + v beta_if_u_is_odd) / 2 % pow2 pbits);
assert (v ub == (if v ub0 % 2 = 0 then v ub0 / 2 % pow2 pbits else (v ub0 + v beta) / 2 % pow2 pbits));
Math.Lemmas.lemma_mod_plus_distr_l (v vb0 / 2) (v alpha_if_u_is_odd) (pow2 pbits);
assert (v vb == (v vb0 / 2 + v alpha_if_u_is_odd) % pow2 pbits);
assert (v vb == (if v ub0 % 2 = 0 then v vb0 / 2 % pow2 pbits else (v vb0 / 2 + v alpha) % pow2 pbits));
if v ub0 % 2 = 0 then
mod_inv_limb_inv_step_even n0 i ub0 vb0
else
mod_inv_limb_inv_step_odd n0 i ub0 vb0;
assert (2 * (v ub * 2 * v alpha - v vb * v beta) == pow2 (pbits - i + 1));
Math.Lemmas.cancel_mul_div (v ub * 2 * v alpha - v vb * v beta) 2;
Math.Lemmas.pow2_minus (pbits - i + 1) 1
val mod_inv_limb_inv: #t:limb_t -> n0:limb t -> i:nat{i <= bits t} -> Lemma
(requires v n0 % 2 = 1)
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let (ub, vb) = repeat_gen i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
pow2 (bits t - i) == v ub * 2 * v alpha - v vb * v beta)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.ModInvLimb.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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 | n0: Hacl.Spec.Bignum.Definitions.limb t -> i: Prims.nat{i <= Lib.IntTypes.bits t}
-> FStar.Pervasives.Lemma (requires Lib.IntTypes.v n0 % 2 = 1)
(ensures
(let alpha = Lib.IntTypes.uint 1 <<. Lib.IntTypes.size (Lib.IntTypes.bits t - 1) in
let beta = n0 in
let _ =
Lib.LoopCombinators.repeat_gen i
(Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_t t)
(Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_f alpha beta)
(Lib.IntTypes.uint 1,
Lib.IntTypes.uint 0)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ ub vb = _ in
Prims.pow2 (Lib.IntTypes.bits t - i) ==
(Lib.IntTypes.v ub * 2) * Lib.IntTypes.v alpha - Lib.IntTypes.v vb * Lib.IntTypes.v beta
)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.bits",
"Prims.op_Equality",
"Prims.int",
"Lib.LoopCombinators.eq_repeat_gen0",
"Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_t",
"Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_f",
"FStar.Pervasives.Native.Mktuple2",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"Prims.bool",
"Prims.unit",
"Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_inv_step",
"Prims._assert",
"Prims.eq2",
"FStar.Pervasives.Native.tuple2",
"Prims.op_Subtraction",
"Lib.LoopCombinators.unfold_repeat_gen",
"Prims.pow2",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_inv",
"Lib.LoopCombinators.repeat_gen",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.size"
] | [
"recursion"
] | false | false | true | false | false | let rec mod_inv_limb_inv #t n0 i =
| let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let ub, vb = repeat_gen i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
if i = 0
then eq_repeat_gen0 i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0)
else
let ub0, vb0 =
repeat_gen (i - 1) (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0)
in
mod_inv_limb_inv n0 (i - 1);
assert (pow2 (bits t - i + 1) == (v ub0 * 2) * v alpha - v vb0 * v beta);
unfold_repeat_gen i (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) (i - 1);
assert ((ub, vb) == mod_inv_limb_f alpha beta (i - 1) (ub0, vb0));
mod_inv_limb_inv_step n0 i ub0 vb0;
() | false |
Hacl.Impl.Chacha20.Core32.fst | Hacl.Impl.Chacha20.Core32.load_state | val load_state:
st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Lib.ByteSequence.uints_from_bytes_le (as_seq h0 b)) | val load_state:
st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Lib.ByteSequence.uints_from_bytes_le (as_seq h0 b)) | let load_state st b =
uints_from_bytes_le st b | {
"file_name": "code/chacha20/Hacl.Impl.Chacha20.Core32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 40,
"start_col": 0,
"start_line": 39
} | module Hacl.Impl.Chacha20.Core32
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Sequence
open Lib.Buffer
open Lib.ByteBuffer
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20
let state = lbuffer uint32 16ul
let index = i:size_t{size_v i < 16}
inline_for_extraction
val create_state: unit ->
StackInline state
(requires fun h -> True)
(ensures fun h0 r h1 -> live h1 r /\
as_seq h1 r == Seq.create 16 (u32 0) /\
stack_allocated r h0 h1 (Seq.create 16 (u32 0)))
let create_state () = create (size 16) (u32 0)
inline_for_extraction
val load_state:
st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Lib.ByteSequence.uints_from_bytes_le (as_seq h0 b)) | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20.Core32.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | st: Hacl.Impl.Chacha20.Core32.state -> b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Chacha20.Core32.state",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Lib.ByteBuffer.uints_from_bytes_le",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Prims.unit"
] | [] | false | true | false | false | false | let load_state st b =
| uints_from_bytes_le st b | false |
Hacl.Streaming.Poly1305_256.fsti | Hacl.Streaming.Poly1305_256.malloc | val malloc : Hacl.Streaming.Functor.malloc_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M256)
()
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M256)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | let malloc = F.malloc (poly1305 M256) () (t M256) (poly1305_key.I.s ()) | {
"file_name": "code/streaming/Hacl.Streaming.Poly1305_256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 17,
"start_col": 0,
"start_line": 17
} | module Hacl.Streaming.Poly1305_256
module G = FStar.Ghost
module F = Hacl.Streaming.Functor
module I = Hacl.Streaming.Interface
open Hacl.Impl.Poly1305.Fields
open Hacl.Streaming.Poly1305
#set-options "--fuel 0 --ifuel 0 --z3rlimit 100"
/// Type abbreviation - makes KaRaMeL use pretty names in the generated code
let state_t = F.state_s (poly1305 M256) () (t M256) (poly1305_key.I.s ())
noextract | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Streaming.Poly1305.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Poly1305_256.fsti"
} | [
{
"abbrev": false,
"full_module": "Hacl.Streaming.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Interface",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Streaming.Functor.malloc_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M256)
()
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M256)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.malloc",
"Prims.unit",
"Hacl.Streaming.Poly1305.poly1305",
"Hacl.Impl.Poly1305.Fields.M256",
"Hacl.Streaming.Poly1305.t",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"Hacl.Streaming.Poly1305.poly1305_key"
] | [] | false | false | false | false | false | let malloc =
| F.malloc (poly1305 M256) () (t M256) (poly1305_key.I.s ()) | false |
|
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_sorted_map_entry_order_not_memP_tail | val list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order:
(t1 -> t1 -> bool)
{ (forall x. key_order x x == false) /\
(forall x y z. (key_order x y /\ key_order y z) ==> key_order x z) })
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma (requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~(List.Tot.memP (fst a) (List.Tot.map fst l)))) | val list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order:
(t1 -> t1 -> bool)
{ (forall x. key_order x x == false) /\
(forall x y z. (key_order x y /\ key_order y z) ==> key_order x z) })
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma (requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~(List.Tot.memP (fst a) (List.Tot.map fst l)))) | let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 85,
"end_line": 77,
"start_col": 0,
"start_line": 66
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
key_order:
(_: t1 -> _: t1 -> Prims.bool)
{ (forall (x: t1). key_order x x == false) /\
(forall (x: t1) (y: t1) (z: t1). key_order x y /\ key_order y z ==> key_order x z) } ->
a: (t1 * t2) ->
l: Prims.list (t1 * t2)
-> FStar.Pervasives.Lemma
(requires
FStar.List.Tot.Properties.sorted (CBOR.Spec.Type.map_entry_order key_order t2) (a :: l))
(ensures
~(FStar.List.Tot.Base.memP (FStar.Pervasives.Native.fst a)
(FStar.List.Tot.Base.map FStar.Pervasives.Native.fst l))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.bool",
"Prims.l_and",
"Prims.l_Forall",
"Prims.eq2",
"Prims.l_imp",
"Prims.b2t",
"FStar.Pervasives.Native.tuple2",
"Prims.list",
"FStar.Classical.move_requires",
"FStar.List.Tot.Properties.sorted",
"CBOR.Spec.Type.map_entry_order",
"Prims.Cons",
"FStar.List.Tot.Base.memP",
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.fst",
"CBOR.Spec.Map.list_sorted_map_entry_order_lt_tail",
"Prims.unit",
"Prims.squash",
"Prims.l_not",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order:
(t1 -> t1 -> bool)
{ (forall x. key_order x x == false) /\
(forall x y z. (key_order x y /\ key_order y z) ==> key_order x z) })
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma (requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~(List.Tot.memP (fst a) (List.Tot.map fst l)))) =
| Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a) | false |
Hacl.Impl.Chacha20.Core32.fst | Hacl.Impl.Chacha20.Core32.incr_counter | val incr_counter:
st:state ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1) | val incr_counter:
st:state ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1) | let incr_counter st =
let c = st.(size 12) in
st.(size 12) <- c +. u32 1 | {
"file_name": "code/chacha20/Hacl.Impl.Chacha20.Core32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 78,
"start_col": 0,
"start_line": 76
} | module Hacl.Impl.Chacha20.Core32
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Sequence
open Lib.Buffer
open Lib.ByteBuffer
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20
let state = lbuffer uint32 16ul
let index = i:size_t{size_v i < 16}
inline_for_extraction
val create_state: unit ->
StackInline state
(requires fun h -> True)
(ensures fun h0 r h1 -> live h1 r /\
as_seq h1 r == Seq.create 16 (u32 0) /\
stack_allocated r h0 h1 (Seq.create 16 (u32 0)))
let create_state () = create (size 16) (u32 0)
inline_for_extraction
val load_state:
st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Lib.ByteSequence.uints_from_bytes_le (as_seq h0 b))
let load_state st b =
uints_from_bytes_le st b
inline_for_extraction
val store_state:
b:lbuffer uint8 64ul
-> st:state ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == Lib.ByteSequence.uints_to_bytes_le (as_seq h0 st))
let store_state st b =
uints_to_bytes_le 16ul st b
inline_for_extraction
val set_counter:
st:state
-> c:size_t ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Seq.upd (as_seq h0 st) 12 (size_to_uint32 c))
let set_counter st c =
st.(size 12) <- size_to_uint32 c
inline_for_extraction
val incr_counter:
st:state ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1) | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20.Core32.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | st: Hacl.Impl.Chacha20.Core32.state -> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Chacha20.Core32.state",
"Lib.Buffer.op_Array_Assignment",
"Lib.IntTypes.uint32",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.size",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Lib.IntTypes.u32",
"Prims.unit",
"Lib.IntTypes.int_t",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT"
] | [] | false | true | false | false | false | let incr_counter st =
| let c = st.(size 12) in
st.(size 12) <- c +. u32 1 | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_sorted_map_entry_order_no_repeats | val list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order:
(t1 -> t1 -> bool)
{ (forall x. key_order x x == false) /\
(forall x y z. (key_order x y /\ key_order y z) ==> key_order x z) })
(l: list (t1 & t2))
: Lemma (requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l))) | val list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order:
(t1 -> t1 -> bool)
{ (forall x. key_order x x == false) /\
(forall x y z. (key_order x y /\ key_order y z) ==> key_order x z) })
(l: list (t1 & t2))
: Lemma (requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l))) | let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 59,
"end_line": 93,
"start_col": 0,
"start_line": 79
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
key_order:
(_: t1 -> _: t1 -> Prims.bool)
{ (forall (x: t1). key_order x x == false) /\
(forall (x: t1) (y: t1) (z: t1). key_order x y /\ key_order y z ==> key_order x z) } ->
l: Prims.list (t1 * t2)
-> FStar.Pervasives.Lemma
(requires FStar.List.Tot.Properties.sorted (CBOR.Spec.Type.map_entry_order key_order t2) l)
(ensures
FStar.List.Tot.Base.no_repeats_p (FStar.List.Tot.Base.map FStar.Pervasives.Native.fst l)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.bool",
"Prims.l_and",
"Prims.l_Forall",
"Prims.eq2",
"Prims.l_imp",
"Prims.b2t",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"CBOR.Spec.Map.list_sorted_map_entry_order_not_memP_tail",
"Prims.unit",
"CBOR.Spec.Map.list_sorted_map_entry_order_no_repeats",
"FStar.List.Tot.Properties.sorted",
"CBOR.Spec.Type.map_entry_order",
"Prims.squash",
"FStar.List.Tot.Base.no_repeats_p",
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.fst",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order:
(t1 -> t1 -> bool)
{ (forall x. key_order x x == false) /\
(forall x y z. (key_order x y /\ key_order y z) ==> key_order x z) })
(l: list (t1 & t2))
: Lemma (requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l))) =
| match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_ghost_assoc_append | val list_ghost_assoc_append (#tk #tv: Type) (k: tk) (l1 l2: list (tk & tv))
: Lemma
(ensures
(list_ghost_assoc k (l1 `List.Tot.append` l2) ==
(match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2))) (decreases l1) | val list_ghost_assoc_append (#tk #tv: Type) (k: tk) (l1 l2: list (tk & tv))
: Lemma
(ensures
(list_ghost_assoc k (l1 `List.Tot.append` l2) ==
(match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2))) (decreases l1) | let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2 | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 40,
"end_line": 146,
"start_col": 0,
"start_line": 130
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: tk -> l1: Prims.list (tk * tv) -> l2: Prims.list (tk * tv)
-> FStar.Pervasives.Lemma
(ensures
CBOR.Spec.Map.list_ghost_assoc k (l1 @ l2) ==
(match CBOR.Spec.Map.list_ghost_assoc k l1 with
| FStar.Pervasives.Native.Some #_ v -> FStar.Pervasives.Native.Some v
| FStar.Pervasives.Native.None #_ -> CBOR.Spec.Map.list_ghost_assoc k l2)) (decreases l1) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.StrongExcludedMiddle.strong_excluded_middle",
"Prims.eq2",
"Prims.bool",
"CBOR.Spec.Map.list_ghost_assoc_append",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"FStar.Pervasives.Native.option",
"CBOR.Spec.Map.list_ghost_assoc",
"FStar.List.Tot.Base.append",
"FStar.Pervasives.Native.Some",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_ghost_assoc_append (#tk #tv: Type) (k: tk) (l1 l2: list (tk & tv))
: Lemma
(ensures
(list_ghost_assoc k (l1 `List.Tot.append` l2) ==
(match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2))) (decreases l1) =
| match l1 with
| [] -> ()
| (k1, _) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2 | false |
Hacl.Impl.Chacha20.Core32.fst | Hacl.Impl.Chacha20.Core32.sum_state | val sum_state:
st:state
-> ost:state ->
Stack unit
(requires fun h -> live h st /\ live h ost /\ eq_or_disjoint st ost)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.sum_state (as_seq h0 st) (as_seq h0 ost)) | val sum_state:
st:state
-> ost:state ->
Stack unit
(requires fun h -> live h st /\ live h ost /\ eq_or_disjoint st ost)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.sum_state (as_seq h0 st) (as_seq h0 ost)) | let sum_state st ost = map2T #MUT #MUT #uint32 #uint32 #uint32 (size 16) st ( +. ) st ost | {
"file_name": "code/chacha20/Hacl.Impl.Chacha20.Core32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 90,
"end_line": 102,
"start_col": 0,
"start_line": 102
} | module Hacl.Impl.Chacha20.Core32
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Sequence
open Lib.Buffer
open Lib.ByteBuffer
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20
let state = lbuffer uint32 16ul
let index = i:size_t{size_v i < 16}
inline_for_extraction
val create_state: unit ->
StackInline state
(requires fun h -> True)
(ensures fun h0 r h1 -> live h1 r /\
as_seq h1 r == Seq.create 16 (u32 0) /\
stack_allocated r h0 h1 (Seq.create 16 (u32 0)))
let create_state () = create (size 16) (u32 0)
inline_for_extraction
val load_state:
st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Lib.ByteSequence.uints_from_bytes_le (as_seq h0 b))
let load_state st b =
uints_from_bytes_le st b
inline_for_extraction
val store_state:
b:lbuffer uint8 64ul
-> st:state ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == Lib.ByteSequence.uints_to_bytes_le (as_seq h0 st))
let store_state st b =
uints_to_bytes_le 16ul st b
inline_for_extraction
val set_counter:
st:state
-> c:size_t ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Seq.upd (as_seq h0 st) 12 (size_to_uint32 c))
let set_counter st c =
st.(size 12) <- size_to_uint32 c
inline_for_extraction
val incr_counter:
st:state ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1)
let incr_counter st =
let c = st.(size 12) in
st.(size 12) <- c +. u32 1
inline_for_extraction
val copy_state:
st:state
-> ost:state ->
Stack unit
(requires fun h -> live h st /\ live h ost /\ disjoint st ost)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == as_seq h0 ost)
let copy_state st ost = copy #MUT #uint32 #(size 16) st ost
inline_for_extraction
val sum_state:
st:state
-> ost:state ->
Stack unit
(requires fun h -> live h st /\ live h ost /\ eq_or_disjoint st ost)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.sum_state (as_seq h0 st) (as_seq h0 ost)) | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20.Core32.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | st: Hacl.Impl.Chacha20.Core32.state -> ost: Hacl.Impl.Chacha20.Core32.state
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Chacha20.Core32.state",
"Lib.Buffer.map2T",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint32",
"Lib.IntTypes.size",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Prims.unit"
] | [] | false | true | false | false | false | let sum_state st ost =
| map2T #MUT #MUT #uint32 #uint32 #uint32 (size 16) st ( +. ) st ost | false |
Hacl.Streaming.Poly1305_256.fsti | Hacl.Streaming.Poly1305_256.alloca | val alloca : Hacl.Streaming.Functor.alloca_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M256)
()
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M256)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | let alloca = F.alloca (poly1305 M256) () (t M256) (poly1305_key.I.s ()) | {
"file_name": "code/streaming/Hacl.Streaming.Poly1305_256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 16,
"start_col": 0,
"start_line": 16
} | module Hacl.Streaming.Poly1305_256
module G = FStar.Ghost
module F = Hacl.Streaming.Functor
module I = Hacl.Streaming.Interface
open Hacl.Impl.Poly1305.Fields
open Hacl.Streaming.Poly1305
#set-options "--fuel 0 --ifuel 0 --z3rlimit 100"
/// Type abbreviation - makes KaRaMeL use pretty names in the generated code
let state_t = F.state_s (poly1305 M256) () (t M256) (poly1305_key.I.s ()) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Streaming.Poly1305.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Poly1305_256.fsti"
} | [
{
"abbrev": false,
"full_module": "Hacl.Streaming.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Interface",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Streaming.Functor.alloca_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M256)
()
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M256)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.alloca",
"Prims.unit",
"Hacl.Streaming.Poly1305.poly1305",
"Hacl.Impl.Poly1305.Fields.M256",
"Hacl.Streaming.Poly1305.t",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"Hacl.Streaming.Poly1305.poly1305_key"
] | [] | false | false | false | false | false | let alloca =
| F.alloca (poly1305 M256) () (t M256) (poly1305_key.I.s ()) | false |
|
Hacl.Streaming.Poly1305_256.fsti | Hacl.Streaming.Poly1305_256.digest | val digest : Hacl.Streaming.Functor.digest_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M256)
()
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M256)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | let digest = F.digest (poly1305 M256) () (t M256) (poly1305_key.I.s ()) | {
"file_name": "code/streaming/Hacl.Streaming.Poly1305_256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 21,
"start_col": 0,
"start_line": 21
} | module Hacl.Streaming.Poly1305_256
module G = FStar.Ghost
module F = Hacl.Streaming.Functor
module I = Hacl.Streaming.Interface
open Hacl.Impl.Poly1305.Fields
open Hacl.Streaming.Poly1305
#set-options "--fuel 0 --ifuel 0 --z3rlimit 100"
/// Type abbreviation - makes KaRaMeL use pretty names in the generated code
let state_t = F.state_s (poly1305 M256) () (t M256) (poly1305_key.I.s ())
noextract
let alloca = F.alloca (poly1305 M256) () (t M256) (poly1305_key.I.s ())
let malloc = F.malloc (poly1305 M256) () (t M256) (poly1305_key.I.s ())
let reset = F.reset (poly1305 M256) (G.hide ()) (t M256) (poly1305_key.I.s ())
[@@ Comment "0 = success, 1 = max length exceeded" ] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Streaming.Poly1305.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Poly1305_256.fsti"
} | [
{
"abbrev": false,
"full_module": "Hacl.Streaming.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Interface",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Streaming.Functor.digest_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M256)
()
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M256)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.digest",
"Prims.unit",
"Hacl.Streaming.Poly1305.poly1305",
"Hacl.Impl.Poly1305.Fields.M256",
"Hacl.Streaming.Poly1305.t",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"Hacl.Streaming.Poly1305.poly1305_key"
] | [] | false | false | false | false | false | let digest =
| F.digest (poly1305 M256) () (t M256) (poly1305_key.I.s ()) | false |
|
Hacl.Streaming.Poly1305_256.fsti | Hacl.Streaming.Poly1305_256.free | val free : Hacl.Streaming.Functor.free_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M256)
(FStar.Ghost.reveal (FStar.Ghost.hide ()))
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M256)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | let free = F.free (poly1305 M256) (G.hide ()) (t M256) (poly1305_key.I.s ()) | {
"file_name": "code/streaming/Hacl.Streaming.Poly1305_256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 76,
"end_line": 22,
"start_col": 0,
"start_line": 22
} | module Hacl.Streaming.Poly1305_256
module G = FStar.Ghost
module F = Hacl.Streaming.Functor
module I = Hacl.Streaming.Interface
open Hacl.Impl.Poly1305.Fields
open Hacl.Streaming.Poly1305
#set-options "--fuel 0 --ifuel 0 --z3rlimit 100"
/// Type abbreviation - makes KaRaMeL use pretty names in the generated code
let state_t = F.state_s (poly1305 M256) () (t M256) (poly1305_key.I.s ())
noextract
let alloca = F.alloca (poly1305 M256) () (t M256) (poly1305_key.I.s ())
let malloc = F.malloc (poly1305 M256) () (t M256) (poly1305_key.I.s ())
let reset = F.reset (poly1305 M256) (G.hide ()) (t M256) (poly1305_key.I.s ())
[@@ Comment "0 = success, 1 = max length exceeded" ]
let update = F.update (poly1305 M256) (G.hide ()) (t M256) (poly1305_key.I.s ()) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Streaming.Poly1305.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Poly1305_256.fsti"
} | [
{
"abbrev": false,
"full_module": "Hacl.Streaming.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Interface",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Streaming.Functor.free_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M256)
(FStar.Ghost.reveal (FStar.Ghost.hide ()))
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M256)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.free",
"Prims.unit",
"Hacl.Streaming.Poly1305.poly1305",
"Hacl.Impl.Poly1305.Fields.M256",
"FStar.Ghost.hide",
"Hacl.Streaming.Poly1305.t",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"Hacl.Streaming.Poly1305.poly1305_key"
] | [] | false | false | false | false | false | let free =
| F.free (poly1305 M256) (G.hide ()) (t M256) (poly1305_key.I.s ()) | false |
|
Hacl.Impl.Chacha20.Core32.fst | Hacl.Impl.Chacha20.Core32.create_state | val create_state: unit ->
StackInline state
(requires fun h -> True)
(ensures fun h0 r h1 -> live h1 r /\
as_seq h1 r == Seq.create 16 (u32 0) /\
stack_allocated r h0 h1 (Seq.create 16 (u32 0))) | val create_state: unit ->
StackInline state
(requires fun h -> True)
(ensures fun h0 r h1 -> live h1 r /\
as_seq h1 r == Seq.create 16 (u32 0) /\
stack_allocated r h0 h1 (Seq.create 16 (u32 0))) | let create_state () = create (size 16) (u32 0) | {
"file_name": "code/chacha20/Hacl.Impl.Chacha20.Core32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 27,
"start_col": 0,
"start_line": 27
} | module Hacl.Impl.Chacha20.Core32
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Sequence
open Lib.Buffer
open Lib.ByteBuffer
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20
let state = lbuffer uint32 16ul
let index = i:size_t{size_v i < 16}
inline_for_extraction
val create_state: unit ->
StackInline state
(requires fun h -> True)
(ensures fun h0 r h1 -> live h1 r /\
as_seq h1 r == Seq.create 16 (u32 0) /\
stack_allocated r h0 h1 (Seq.create 16 (u32 0))) | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20.Core32.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.HyperStack.ST.StackInline Hacl.Impl.Chacha20.Core32.state | FStar.HyperStack.ST.StackInline | [] | [] | [
"Prims.unit",
"Lib.Buffer.create",
"Lib.IntTypes.uint32",
"Lib.IntTypes.size",
"Lib.IntTypes.u32",
"Lib.Buffer.lbuffer",
"Hacl.Impl.Chacha20.Core32.state"
] | [] | false | true | false | false | false | let create_state () =
| create (size 16) (u32 0) | false |
Hacl.Streaming.Poly1305_256.fsti | Hacl.Streaming.Poly1305_256.reset | val reset : Hacl.Streaming.Functor.reset_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M256)
(FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ())))
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M256)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | let reset = F.reset (poly1305 M256) (G.hide ()) (t M256) (poly1305_key.I.s ()) | {
"file_name": "code/streaming/Hacl.Streaming.Poly1305_256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 78,
"end_line": 18,
"start_col": 0,
"start_line": 18
} | module Hacl.Streaming.Poly1305_256
module G = FStar.Ghost
module F = Hacl.Streaming.Functor
module I = Hacl.Streaming.Interface
open Hacl.Impl.Poly1305.Fields
open Hacl.Streaming.Poly1305
#set-options "--fuel 0 --ifuel 0 --z3rlimit 100"
/// Type abbreviation - makes KaRaMeL use pretty names in the generated code
let state_t = F.state_s (poly1305 M256) () (t M256) (poly1305_key.I.s ())
noextract
let alloca = F.alloca (poly1305 M256) () (t M256) (poly1305_key.I.s ()) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Streaming.Poly1305.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Poly1305_256.fsti"
} | [
{
"abbrev": false,
"full_module": "Hacl.Streaming.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Interface",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Streaming.Functor.reset_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M256)
(FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ())))
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M256)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.reset",
"Prims.unit",
"Hacl.Streaming.Poly1305.poly1305",
"Hacl.Impl.Poly1305.Fields.M256",
"FStar.Ghost.hide",
"Hacl.Streaming.Poly1305.t",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"Hacl.Streaming.Poly1305.poly1305_key"
] | [] | false | false | false | false | false | let reset =
| F.reset (poly1305 M256) (G.hide ()) (t M256) (poly1305_key.I.s ()) | false |
|
Hacl.Impl.Chacha20.Core32.fst | Hacl.Impl.Chacha20.Core32.line | val line:
st:state
-> a:index
-> b:index
-> d:index
-> r:rotval U32 ->
Stack unit
(requires fun h -> live h st /\ v a <> v d)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.line (v a) (v b) (v d) r (as_seq h0 st)) | val line:
st:state
-> a:index
-> b:index
-> d:index
-> r:rotval U32 ->
Stack unit
(requires fun h -> live h st /\ v a <> v d)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.line (v a) (v b) (v d) r (as_seq h0 st)) | let line st a b d r =
let sta = st.(a) in
let stb = st.(b) in
let std = st.(d) in
let sta = sta +. stb in
let std = std ^. sta in
let std = rotate_left std r in
st.(a) <- sta;
st.(d) <- std | {
"file_name": "code/chacha20/Hacl.Impl.Chacha20.Core32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 15,
"end_line": 144,
"start_col": 0,
"start_line": 136
} | module Hacl.Impl.Chacha20.Core32
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Sequence
open Lib.Buffer
open Lib.ByteBuffer
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20
let state = lbuffer uint32 16ul
let index = i:size_t{size_v i < 16}
inline_for_extraction
val create_state: unit ->
StackInline state
(requires fun h -> True)
(ensures fun h0 r h1 -> live h1 r /\
as_seq h1 r == Seq.create 16 (u32 0) /\
stack_allocated r h0 h1 (Seq.create 16 (u32 0)))
let create_state () = create (size 16) (u32 0)
inline_for_extraction
val load_state:
st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Lib.ByteSequence.uints_from_bytes_le (as_seq h0 b))
let load_state st b =
uints_from_bytes_le st b
inline_for_extraction
val store_state:
b:lbuffer uint8 64ul
-> st:state ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == Lib.ByteSequence.uints_to_bytes_le (as_seq h0 st))
let store_state st b =
uints_to_bytes_le 16ul st b
inline_for_extraction
val set_counter:
st:state
-> c:size_t ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Seq.upd (as_seq h0 st) 12 (size_to_uint32 c))
let set_counter st c =
st.(size 12) <- size_to_uint32 c
inline_for_extraction
val incr_counter:
st:state ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1)
let incr_counter st =
let c = st.(size 12) in
st.(size 12) <- c +. u32 1
inline_for_extraction
val copy_state:
st:state
-> ost:state ->
Stack unit
(requires fun h -> live h st /\ live h ost /\ disjoint st ost)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == as_seq h0 ost)
let copy_state st ost = copy #MUT #uint32 #(size 16) st ost
inline_for_extraction
val sum_state:
st:state
-> ost:state ->
Stack unit
(requires fun h -> live h st /\ live h ost /\ eq_or_disjoint st ost)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.sum_state (as_seq h0 st) (as_seq h0 ost))
let sum_state st ost = map2T #MUT #MUT #uint32 #uint32 #uint32 (size 16) st ( +. ) st ost
#set-options "--z3rlimit 100"
inline_for_extraction
val xor_block:
o:lbuffer uint8 64ul
-> st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h o /\ live h st /\ live h b)
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == Spec.xor_block (as_seq h0 st) (as_seq h0 b))
let xor_block o st b =
push_frame();
let bl = create_state() in
load_state bl b;
map2T (size 16) bl ( ^. ) bl st;
store_state o bl;
pop_frame()
inline_for_extraction
val line:
st:state
-> a:index
-> b:index
-> d:index
-> r:rotval U32 ->
Stack unit
(requires fun h -> live h st /\ v a <> v d)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.line (v a) (v b) (v d) r (as_seq h0 st)) | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20.Core32.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
st: Hacl.Impl.Chacha20.Core32.state ->
a: Hacl.Impl.Chacha20.Core32.index ->
b: Hacl.Impl.Chacha20.Core32.index ->
d: Hacl.Impl.Chacha20.Core32.index ->
r: Lib.IntTypes.rotval Lib.IntTypes.U32
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Chacha20.Core32.state",
"Hacl.Impl.Chacha20.Core32.index",
"Lib.IntTypes.rotval",
"Lib.IntTypes.U32",
"Lib.Buffer.op_Array_Assignment",
"Lib.IntTypes.uint32",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.rotate_left",
"Lib.IntTypes.op_Hat_Dot",
"Lib.IntTypes.op_Plus_Dot",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT"
] | [] | false | true | false | false | false | let line st a b d r =
| let sta = st.(a) in
let stb = st.(b) in
let std = st.(d) in
let sta = sta +. stb in
let std = std ^. sta in
let std = rotate_left std r in
st.(a) <- sta;
st.(d) <- std | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_sorted_order_elim | val list_sorted_order_elim
(#t: Type)
(order: (t -> t -> bool))
(l0: list t)
(a1: t)
(l1: list t)
(a2: t)
(l2: list t)
: Lemma
(requires
((forall x y z. (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l0 `List.Tot.append` (a1 :: (l1 `List.Tot.append` (a2 :: l2))))))
(ensures (order a1 a2 == true))
(decreases (List.Tot.length l0 + List.Tot.length l1)) | val list_sorted_order_elim
(#t: Type)
(order: (t -> t -> bool))
(l0: list t)
(a1: t)
(l1: list t)
(a2: t)
(l2: list t)
: Lemma
(requires
((forall x y z. (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l0 `List.Tot.append` (a1 :: (l1 `List.Tot.append` (a2 :: l2))))))
(ensures (order a1 a2 == true))
(decreases (List.Tot.length l0 + List.Tot.length l1)) | let rec list_sorted_order_elim
(#t: Type)
(order: t -> t -> bool)
(l0: list t)
(a1: t)
(l1: list t)
(a2: t)
(l2: list t)
: Lemma
(requires (
(forall x y z . (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l0 `List.Tot.append` (a1 :: (l1 `List.Tot.append` (a2 :: l2))))
))
(ensures (order a1 a2 == true))
(decreases (List.Tot.length l0 + List.Tot.length l1))
= match l0 with
| [] ->
begin match l1 with
| [] -> ()
| a1' :: l1' ->
list_sorted_order_elim order [] a1' l1' a2 l2 // and transitivity
end
| a0 :: l0' ->
list_sorted_order_elim order l0' a1 l1 a2 l2 | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 48,
"end_line": 312,
"start_col": 0,
"start_line": 289
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m'
let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2
let rec list_ghost_assoc_mem_intro
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l)
= let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l'
let rec list_ghost_assoc_no_repeats_mem_elim
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l) /\
List.Tot.memP (k, v) l
))
(ensures (list_ghost_assoc k l == Some v))
(decreases l)
= List.Tot.memP_map_intro fst (k, v) l;
let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then
if FStar.StrongExcludedMiddle.strong_excluded_middle (v == v')
then ()
else List.Tot.memP_map_intro fst (k, v) l'
else list_ghost_assoc_no_repeats_mem_elim k v l'
let list_ghost_assoc_no_repeats_mem
(#tk #tv: Type)
(l: list (tk & tv))
(k: tk)
(v: tv)
: Lemma
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l) ==> (list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l)))
= Classical.move_requires (list_ghost_assoc_no_repeats_mem_elim k v) l;
Classical.move_requires (list_ghost_assoc_mem_intro k v) l
let list_ghost_assoc_no_repeats_equiv'
(#tk #tv: Type)
(l1 l2: list (tk & tv))
(k: tk)
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (list_ghost_assoc k l1 == list_ghost_assoc k l2))
= match list_ghost_assoc k l1 with
| None ->
begin match list_ghost_assoc k l2 with
| None -> ()
| Some v ->
list_ghost_assoc_no_repeats_mem l2 k v;
list_ghost_assoc_no_repeats_mem l1 k v
end
| Some v ->
list_ghost_assoc_no_repeats_mem l1 k v;
list_ghost_assoc_no_repeats_mem l2 k v
let list_ghost_assoc_no_repeats_equiv
(#tk #tv: Type)
(l1 l2: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (forall k . list_ghost_assoc k l1 == list_ghost_assoc k l2))
= Classical.forall_intro (Classical.move_requires (list_ghost_assoc_no_repeats_equiv' l1 l2))
[@@noextract_to "krml"] noextract
let rec map_sort_merge
(#t1 #t2: Type)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Tot (bool & list (t1 & t2))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| (k1, v1) :: l1', (k2, v2) :: l2' ->
begin let c = key_compare k1 k2 in
if c = 0
then (false, accu `List.Tot.append` (l1 `List.Tot.append` l2))
else if c < 0
then map_sort_merge key_compare (accu `List.Tot.append` [(k1, v1)]) l1' l2
else
map_sort_merge key_compare (accu `List.Tot.append` [(k2, v2)]) l1 l2'
// TODO in this case:
// 1. prove that the sort is stable, i.e. that the maps are extensionally equal throughout
// 2. extract and swap the whole prefix of l2 less than the head of l1, rather than just the head of l2
end
| [], _ -> (true, accu `List.Tot.append` l2)
| _, [] -> (true, accu `List.Tot.append` l1)
let rec list_sorted_append_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2: list t)
: Lemma
(requires (List.Tot.sorted order (l1 `List.Tot.append` l2)))
(ensures (
List.Tot.sorted order l1 /\
List.Tot.sorted order l2
))
(decreases l1)
= match l1 with
| [] -> ()
| [_] -> ()
| a :: b :: q ->
list_sorted_append_elim order (b :: q) l2
let rec list_sorted_append_chunk_intro
(#t: Type)
(order: t -> t -> bool)
(l1 l2 l3: list t)
: Lemma
(requires (
List.Tot.sorted order (l1 `List.Tot.append` l2) /\
List.Tot.sorted order (l2 `List.Tot.append` l3) /\
Cons? l2
))
(ensures (
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))
))
(decreases l1)
= match l1 with
| [] -> ()
| [a] -> () // because of List.Tot.sorted (l2 `List.Tot.append` l3) and Cons? l2
| a :: l1' -> list_sorted_append_chunk_intro order l1' l2 l3 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
order: (_: t -> _: t -> Prims.bool) ->
l0: Prims.list t ->
a1: t ->
l1: Prims.list t ->
a2: t ->
l2: Prims.list t
-> FStar.Pervasives.Lemma
(requires
(forall (x: t) (y: t) (z: t). order x y /\ order y z ==> order x z) /\
FStar.List.Tot.Properties.sorted order (l0 @ a1 :: (l1 @ a2 :: l2)))
(ensures order a1 a2 == true)
(decreases FStar.List.Tot.Base.length l0 + FStar.List.Tot.Base.length l1) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.bool",
"Prims.list",
"CBOR.Spec.Map.list_sorted_order_elim",
"Prims.Nil",
"Prims.unit",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.b2t",
"FStar.List.Tot.Properties.sorted",
"FStar.List.Tot.Base.append",
"Prims.Cons",
"Prims.squash",
"Prims.eq2",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_sorted_order_elim
(#t: Type)
(order: (t -> t -> bool))
(l0: list t)
(a1: t)
(l1: list t)
(a2: t)
(l2: list t)
: Lemma
(requires
((forall x y z. (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l0 `List.Tot.append` (a1 :: (l1 `List.Tot.append` (a2 :: l2))))))
(ensures (order a1 a2 == true))
(decreases (List.Tot.length l0 + List.Tot.length l1)) =
| match l0 with
| [] ->
(match l1 with
| [] -> ()
| a1' :: l1' -> list_sorted_order_elim order [] a1' l1' a2 l2)
| a0 :: l0' -> list_sorted_order_elim order l0' a1 l1 a2 l2 | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_ghost_assoc_no_repeats_equiv' | val list_ghost_assoc_no_repeats_equiv' (#tk #tv: Type) (l1 l2: list (tk & tv)) (k: tk)
: Lemma
(requires
(List.Tot.no_repeats_p (List.Tot.map fst l1) /\ List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv. List.Tot.memP kv l1 <==> List.Tot.memP kv l2)))
(ensures (list_ghost_assoc k l1 == list_ghost_assoc k l2)) | val list_ghost_assoc_no_repeats_equiv' (#tk #tv: Type) (l1 l2: list (tk & tv)) (k: tk)
: Lemma
(requires
(List.Tot.no_repeats_p (List.Tot.map fst l1) /\ List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv. List.Tot.memP kv l1 <==> List.Tot.memP kv l2)))
(ensures (list_ghost_assoc k l1 == list_ghost_assoc k l2)) | let list_ghost_assoc_no_repeats_equiv'
(#tk #tv: Type)
(l1 l2: list (tk & tv))
(k: tk)
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (list_ghost_assoc k l1 == list_ghost_assoc k l2))
= match list_ghost_assoc k l1 with
| None ->
begin match list_ghost_assoc k l2 with
| None -> ()
| Some v ->
list_ghost_assoc_no_repeats_mem l2 k v;
list_ghost_assoc_no_repeats_mem l1 k v
end
| Some v ->
list_ghost_assoc_no_repeats_mem l1 k v;
list_ghost_assoc_no_repeats_mem l2 k v | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 42,
"end_line": 214,
"start_col": 0,
"start_line": 193
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m'
let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2
let rec list_ghost_assoc_mem_intro
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l)
= let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l'
let rec list_ghost_assoc_no_repeats_mem_elim
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l) /\
List.Tot.memP (k, v) l
))
(ensures (list_ghost_assoc k l == Some v))
(decreases l)
= List.Tot.memP_map_intro fst (k, v) l;
let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then
if FStar.StrongExcludedMiddle.strong_excluded_middle (v == v')
then ()
else List.Tot.memP_map_intro fst (k, v) l'
else list_ghost_assoc_no_repeats_mem_elim k v l'
let list_ghost_assoc_no_repeats_mem
(#tk #tv: Type)
(l: list (tk & tv))
(k: tk)
(v: tv)
: Lemma
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l) ==> (list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l)))
= Classical.move_requires (list_ghost_assoc_no_repeats_mem_elim k v) l;
Classical.move_requires (list_ghost_assoc_mem_intro k v) l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 (tk * tv) -> l2: Prims.list (tk * tv) -> k: tk
-> FStar.Pervasives.Lemma
(requires
FStar.List.Tot.Base.no_repeats_p (FStar.List.Tot.Base.map FStar.Pervasives.Native.fst l1) /\
FStar.List.Tot.Base.no_repeats_p (FStar.List.Tot.Base.map FStar.Pervasives.Native.fst l2) /\
(forall (kv: (tk * tv)). FStar.List.Tot.Base.memP kv l1 <==> FStar.List.Tot.Base.memP kv l2)
) (ensures CBOR.Spec.Map.list_ghost_assoc k l1 == CBOR.Spec.Map.list_ghost_assoc k l2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"CBOR.Spec.Map.list_ghost_assoc",
"CBOR.Spec.Map.list_ghost_assoc_no_repeats_mem",
"Prims.unit",
"Prims.l_and",
"FStar.List.Tot.Base.no_repeats_p",
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.fst",
"Prims.l_Forall",
"Prims.l_iff",
"FStar.List.Tot.Base.memP",
"Prims.squash",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let list_ghost_assoc_no_repeats_equiv' (#tk #tv: Type) (l1 l2: list (tk & tv)) (k: tk)
: Lemma
(requires
(List.Tot.no_repeats_p (List.Tot.map fst l1) /\ List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv. List.Tot.memP kv l1 <==> List.Tot.memP kv l2)))
(ensures (list_ghost_assoc k l1 == list_ghost_assoc k l2)) =
| match list_ghost_assoc k l1 with
| None ->
(match list_ghost_assoc k l2 with
| None -> ()
| Some v ->
list_ghost_assoc_no_repeats_mem l2 k v;
list_ghost_assoc_no_repeats_mem l1 k v)
| Some v ->
list_ghost_assoc_no_repeats_mem l1 k v;
list_ghost_assoc_no_repeats_mem l2 k v | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_ghost_assoc_no_repeats_mem_elim | val list_ghost_assoc_no_repeats_mem_elim (#tk #tv: Type) (k: tk) (v: tv) (l: list (tk & tv))
: Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst l) /\ List.Tot.memP (k, v) l))
(ensures (list_ghost_assoc k l == Some v))
(decreases l) | val list_ghost_assoc_no_repeats_mem_elim (#tk #tv: Type) (k: tk) (v: tv) (l: list (tk & tv))
: Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst l) /\ List.Tot.memP (k, v) l))
(ensures (list_ghost_assoc k l == Some v))
(decreases l) | let rec list_ghost_assoc_no_repeats_mem_elim
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l) /\
List.Tot.memP (k, v) l
))
(ensures (list_ghost_assoc k l == Some v))
(decreases l)
= List.Tot.memP_map_intro fst (k, v) l;
let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then
if FStar.StrongExcludedMiddle.strong_excluded_middle (v == v')
then ()
else List.Tot.memP_map_intro fst (k, v) l'
else list_ghost_assoc_no_repeats_mem_elim k v l' | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 50,
"end_line": 181,
"start_col": 0,
"start_line": 162
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m'
let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2
let rec list_ghost_assoc_mem_intro
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l)
= let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: tk -> v: tv -> l: Prims.list (tk * tv)
-> FStar.Pervasives.Lemma
(requires
FStar.List.Tot.Base.no_repeats_p (FStar.List.Tot.Base.map FStar.Pervasives.Native.fst l) /\
FStar.List.Tot.Base.memP (k, v) l)
(ensures CBOR.Spec.Map.list_ghost_assoc k l == FStar.Pervasives.Native.Some v)
(decreases l) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.StrongExcludedMiddle.strong_excluded_middle",
"Prims.eq2",
"Prims.bool",
"FStar.List.Tot.Properties.memP_map_intro",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"CBOR.Spec.Map.list_ghost_assoc_no_repeats_mem_elim",
"Prims.l_and",
"FStar.List.Tot.Base.no_repeats_p",
"FStar.List.Tot.Base.map",
"FStar.List.Tot.Base.memP",
"Prims.squash",
"FStar.Pervasives.Native.option",
"CBOR.Spec.Map.list_ghost_assoc",
"FStar.Pervasives.Native.Some",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_ghost_assoc_no_repeats_mem_elim (#tk #tv: Type) (k: tk) (v: tv) (l: list (tk & tv))
: Lemma (requires (List.Tot.no_repeats_p (List.Tot.map fst l) /\ List.Tot.memP (k, v) l))
(ensures (list_ghost_assoc k l == Some v))
(decreases l) =
| List.Tot.memP_map_intro fst (k, v) l;
let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then
if FStar.StrongExcludedMiddle.strong_excluded_middle (v == v')
then ()
else List.Tot.memP_map_intro fst (k, v) l'
else list_ghost_assoc_no_repeats_mem_elim k v l' | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_f_exists0 | val compute_gen_elim_f_exists0
(a: Type0)
(body: (a -> gen_elim_i))
(f: (x: a -> GTot (gen_elim_t (body x))))
: Tot (gen_elim_t (GEExists0 body)) | val compute_gen_elim_f_exists0
(a: Type0)
(body: (a -> gen_elim_i))
(f: (x: a -> GTot (gen_elim_t (body x))))
: Tot (gen_elim_t (GEExists0 body)) | let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 141,
"start_col": 0,
"start_line": 130
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type0 ->
body: (_: a -> Steel.ST.GenElim1.Base.gen_elim_i) ->
f: (x: a -> Prims.GTot (Steel.ST.GenElim1.gen_elim_t (body x)))
-> Steel.ST.GenElim1.gen_elim_t (Steel.ST.GenElim1.Base.GEExists0 body) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.gen_elim_t",
"Steel.Memory.inames",
"Steel.ST.GenElim1.Base.compute_gen_elim_a",
"Steel.ST.GenElim1.Base.GEExists0",
"Prims.unit",
"Steel.ST.Util.rewrite",
"Steel.ST.GenElim1.Base.compute_gen_elim_q",
"FStar.Ghost.reveal",
"Steel.ST.GenElim1.Base.coerce_with_trefl",
"Prims.dtuple2",
"Prims.Mkdtuple2",
"FStar.Ghost.hide",
"FStar.Ghost.erased",
"Steel.ST.Util.elim_exists",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.Effect.Common.vprop",
"Steel.ST.GenElim1.rewrite_with_trefl",
"Steel.ST.Util.exists_"
] | [] | false | false | false | false | false | let compute_gen_elim_f_exists0
(a: Type0)
(body: (a -> gen_elim_i))
(f: (x: a -> GTot (gen_elim_t (body x))))
: Tot (gen_elim_t (GEExists0 body)) =
| fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body))
(exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res:compute_gen_elim_a (GEExists0 body) =
coerce_with_trefl (Mkdtuple2 #a
#(fun x -> compute_gen_elim_a (body x))
(Ghost.reveal gres1)
(Ghost.reveal gres2))
in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_ghost_assoc_mem_intro | val list_ghost_assoc_mem_intro (#tk #tv: Type) (k: tk) (v: tv) (l: list (tk & tv))
: Lemma (requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l) | val list_ghost_assoc_mem_intro (#tk #tv: Type) (k: tk) (v: tv) (l: list (tk & tv))
: Lemma (requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l) | let rec list_ghost_assoc_mem_intro
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l)
= let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l' | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 40,
"end_line": 160,
"start_col": 0,
"start_line": 148
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m'
let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: tk -> v: tv -> l: Prims.list (tk * tv)
-> FStar.Pervasives.Lemma
(requires CBOR.Spec.Map.list_ghost_assoc k l == FStar.Pervasives.Native.Some v)
(ensures FStar.List.Tot.Base.memP (k, v) l)
(decreases l) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.StrongExcludedMiddle.strong_excluded_middle",
"Prims.eq2",
"Prims.bool",
"CBOR.Spec.Map.list_ghost_assoc_mem_intro",
"Prims.unit",
"FStar.Pervasives.Native.option",
"CBOR.Spec.Map.list_ghost_assoc",
"FStar.Pervasives.Native.Some",
"Prims.squash",
"FStar.List.Tot.Base.memP",
"FStar.Pervasives.Native.Mktuple2",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_ghost_assoc_mem_intro (#tk #tv: Type) (k: tk) (v: tv) (l: list (tk & tv))
: Lemma (requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l) =
| let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l' | false |
Hacl.Impl.Chacha20.Core32.fst | Hacl.Impl.Chacha20.Core32.set_counter | val set_counter:
st:state
-> c:size_t ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Seq.upd (as_seq h0 st) 12 (size_to_uint32 c)) | val set_counter:
st:state
-> c:size_t ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Seq.upd (as_seq h0 st) 12 (size_to_uint32 c)) | let set_counter st c =
st.(size 12) <- size_to_uint32 c | {
"file_name": "code/chacha20/Hacl.Impl.Chacha20.Core32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 34,
"end_line": 66,
"start_col": 0,
"start_line": 65
} | module Hacl.Impl.Chacha20.Core32
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Sequence
open Lib.Buffer
open Lib.ByteBuffer
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20
let state = lbuffer uint32 16ul
let index = i:size_t{size_v i < 16}
inline_for_extraction
val create_state: unit ->
StackInline state
(requires fun h -> True)
(ensures fun h0 r h1 -> live h1 r /\
as_seq h1 r == Seq.create 16 (u32 0) /\
stack_allocated r h0 h1 (Seq.create 16 (u32 0)))
let create_state () = create (size 16) (u32 0)
inline_for_extraction
val load_state:
st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Lib.ByteSequence.uints_from_bytes_le (as_seq h0 b))
let load_state st b =
uints_from_bytes_le st b
inline_for_extraction
val store_state:
b:lbuffer uint8 64ul
-> st:state ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == Lib.ByteSequence.uints_to_bytes_le (as_seq h0 st))
let store_state st b =
uints_to_bytes_le 16ul st b
inline_for_extraction
val set_counter:
st:state
-> c:size_t ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Seq.upd (as_seq h0 st) 12 (size_to_uint32 c)) | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20.Core32.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | st: Hacl.Impl.Chacha20.Core32.state -> c: Lib.IntTypes.size_t
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Chacha20.Core32.state",
"Lib.IntTypes.size_t",
"Lib.Buffer.op_Array_Assignment",
"Lib.IntTypes.uint32",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.size",
"Lib.IntTypes.size_to_uint32",
"Prims.unit"
] | [] | false | true | false | false | false | let set_counter st c =
| st.(size 12) <- size_to_uint32 c | false |
Hacl.Impl.Chacha20.Core32.fst | Hacl.Impl.Chacha20.Core32.quarter_round | val quarter_round:
st:state
-> a:index
-> b:index
-> c:index
-> d:index ->
Stack unit
(requires fun h -> live h st /\ v a <> v d /\ v c <> v b)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.quarter_round (v a) (v b) (v c) (v d) (as_seq h0 st)) | val quarter_round:
st:state
-> a:index
-> b:index
-> c:index
-> d:index ->
Stack unit
(requires fun h -> live h st /\ v a <> v d /\ v c <> v b)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.quarter_round (v a) (v b) (v c) (v d) (as_seq h0 st)) | let quarter_round st a b c d =
line st a b d (size 16);
line st c d b (size 12);
line st a b d (size 8);
line st c d b (size 7) | {
"file_name": "code/chacha20/Hacl.Impl.Chacha20.Core32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 163,
"start_col": 0,
"start_line": 159
} | module Hacl.Impl.Chacha20.Core32
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Sequence
open Lib.Buffer
open Lib.ByteBuffer
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20
let state = lbuffer uint32 16ul
let index = i:size_t{size_v i < 16}
inline_for_extraction
val create_state: unit ->
StackInline state
(requires fun h -> True)
(ensures fun h0 r h1 -> live h1 r /\
as_seq h1 r == Seq.create 16 (u32 0) /\
stack_allocated r h0 h1 (Seq.create 16 (u32 0)))
let create_state () = create (size 16) (u32 0)
inline_for_extraction
val load_state:
st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Lib.ByteSequence.uints_from_bytes_le (as_seq h0 b))
let load_state st b =
uints_from_bytes_le st b
inline_for_extraction
val store_state:
b:lbuffer uint8 64ul
-> st:state ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == Lib.ByteSequence.uints_to_bytes_le (as_seq h0 st))
let store_state st b =
uints_to_bytes_le 16ul st b
inline_for_extraction
val set_counter:
st:state
-> c:size_t ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Seq.upd (as_seq h0 st) 12 (size_to_uint32 c))
let set_counter st c =
st.(size 12) <- size_to_uint32 c
inline_for_extraction
val incr_counter:
st:state ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1)
let incr_counter st =
let c = st.(size 12) in
st.(size 12) <- c +. u32 1
inline_for_extraction
val copy_state:
st:state
-> ost:state ->
Stack unit
(requires fun h -> live h st /\ live h ost /\ disjoint st ost)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == as_seq h0 ost)
let copy_state st ost = copy #MUT #uint32 #(size 16) st ost
inline_for_extraction
val sum_state:
st:state
-> ost:state ->
Stack unit
(requires fun h -> live h st /\ live h ost /\ eq_or_disjoint st ost)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.sum_state (as_seq h0 st) (as_seq h0 ost))
let sum_state st ost = map2T #MUT #MUT #uint32 #uint32 #uint32 (size 16) st ( +. ) st ost
#set-options "--z3rlimit 100"
inline_for_extraction
val xor_block:
o:lbuffer uint8 64ul
-> st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h o /\ live h st /\ live h b)
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == Spec.xor_block (as_seq h0 st) (as_seq h0 b))
let xor_block o st b =
push_frame();
let bl = create_state() in
load_state bl b;
map2T (size 16) bl ( ^. ) bl st;
store_state o bl;
pop_frame()
inline_for_extraction
val line:
st:state
-> a:index
-> b:index
-> d:index
-> r:rotval U32 ->
Stack unit
(requires fun h -> live h st /\ v a <> v d)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.line (v a) (v b) (v d) r (as_seq h0 st))
let line st a b d r =
let sta = st.(a) in
let stb = st.(b) in
let std = st.(d) in
let sta = sta +. stb in
let std = std ^. sta in
let std = rotate_left std r in
st.(a) <- sta;
st.(d) <- std
val quarter_round:
st:state
-> a:index
-> b:index
-> c:index
-> d:index ->
Stack unit
(requires fun h -> live h st /\ v a <> v d /\ v c <> v b)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.quarter_round (v a) (v b) (v c) (v d) (as_seq h0 st)) | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20.Core32.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
st: Hacl.Impl.Chacha20.Core32.state ->
a: Hacl.Impl.Chacha20.Core32.index ->
b: Hacl.Impl.Chacha20.Core32.index ->
c: Hacl.Impl.Chacha20.Core32.index ->
d: Hacl.Impl.Chacha20.Core32.index
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Chacha20.Core32.state",
"Hacl.Impl.Chacha20.Core32.index",
"Hacl.Impl.Chacha20.Core32.line",
"Lib.IntTypes.size",
"Prims.unit"
] | [] | false | true | false | false | false | let quarter_round st a b c d =
| line st a b d (size 16);
line st c d b (size 12);
line st a b d (size 8);
line st c d b (size 7) | false |
Hacl.Impl.Chacha20.Core32.fst | Hacl.Impl.Chacha20.Core32.store_state | val store_state:
b:lbuffer uint8 64ul
-> st:state ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == Lib.ByteSequence.uints_to_bytes_le (as_seq h0 st)) | val store_state:
b:lbuffer uint8 64ul
-> st:state ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == Lib.ByteSequence.uints_to_bytes_le (as_seq h0 st)) | let store_state st b =
uints_to_bytes_le 16ul st b | {
"file_name": "code/chacha20/Hacl.Impl.Chacha20.Core32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 53,
"start_col": 0,
"start_line": 52
} | module Hacl.Impl.Chacha20.Core32
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Sequence
open Lib.Buffer
open Lib.ByteBuffer
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20
let state = lbuffer uint32 16ul
let index = i:size_t{size_v i < 16}
inline_for_extraction
val create_state: unit ->
StackInline state
(requires fun h -> True)
(ensures fun h0 r h1 -> live h1 r /\
as_seq h1 r == Seq.create 16 (u32 0) /\
stack_allocated r h0 h1 (Seq.create 16 (u32 0)))
let create_state () = create (size 16) (u32 0)
inline_for_extraction
val load_state:
st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Lib.ByteSequence.uints_from_bytes_le (as_seq h0 b))
let load_state st b =
uints_from_bytes_le st b
inline_for_extraction
val store_state:
b:lbuffer uint8 64ul
-> st:state ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == Lib.ByteSequence.uints_to_bytes_le (as_seq h0 st)) | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20.Core32.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul -> st: Hacl.Impl.Chacha20.Core32.state
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Chacha20.Core32.state",
"Lib.ByteBuffer.uints_to_bytes_le",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Prims.unit"
] | [] | false | true | false | false | false | let store_state st b =
| uints_to_bytes_le 16ul st b | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_ghost_assoc_no_repeats_equiv | val list_ghost_assoc_no_repeats_equiv (#tk #tv: Type) (l1 l2: list (tk & tv))
: Lemma
(requires
(List.Tot.no_repeats_p (List.Tot.map fst l1) /\ List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv. List.Tot.memP kv l1 <==> List.Tot.memP kv l2)))
(ensures (forall k. list_ghost_assoc k l1 == list_ghost_assoc k l2)) | val list_ghost_assoc_no_repeats_equiv (#tk #tv: Type) (l1 l2: list (tk & tv))
: Lemma
(requires
(List.Tot.no_repeats_p (List.Tot.map fst l1) /\ List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv. List.Tot.memP kv l1 <==> List.Tot.memP kv l2)))
(ensures (forall k. list_ghost_assoc k l1 == list_ghost_assoc k l2)) | let list_ghost_assoc_no_repeats_equiv
(#tk #tv: Type)
(l1 l2: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (forall k . list_ghost_assoc k l1 == list_ghost_assoc k l2))
= Classical.forall_intro (Classical.move_requires (list_ghost_assoc_no_repeats_equiv' l1 l2)) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 93,
"end_line": 226,
"start_col": 0,
"start_line": 216
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m'
let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2
let rec list_ghost_assoc_mem_intro
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l)
= let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l'
let rec list_ghost_assoc_no_repeats_mem_elim
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l) /\
List.Tot.memP (k, v) l
))
(ensures (list_ghost_assoc k l == Some v))
(decreases l)
= List.Tot.memP_map_intro fst (k, v) l;
let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then
if FStar.StrongExcludedMiddle.strong_excluded_middle (v == v')
then ()
else List.Tot.memP_map_intro fst (k, v) l'
else list_ghost_assoc_no_repeats_mem_elim k v l'
let list_ghost_assoc_no_repeats_mem
(#tk #tv: Type)
(l: list (tk & tv))
(k: tk)
(v: tv)
: Lemma
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l) ==> (list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l)))
= Classical.move_requires (list_ghost_assoc_no_repeats_mem_elim k v) l;
Classical.move_requires (list_ghost_assoc_mem_intro k v) l
let list_ghost_assoc_no_repeats_equiv'
(#tk #tv: Type)
(l1 l2: list (tk & tv))
(k: tk)
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (list_ghost_assoc k l1 == list_ghost_assoc k l2))
= match list_ghost_assoc k l1 with
| None ->
begin match list_ghost_assoc k l2 with
| None -> ()
| Some v ->
list_ghost_assoc_no_repeats_mem l2 k v;
list_ghost_assoc_no_repeats_mem l1 k v
end
| Some v ->
list_ghost_assoc_no_repeats_mem l1 k v;
list_ghost_assoc_no_repeats_mem l2 k v | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 (tk * tv) -> l2: Prims.list (tk * tv)
-> FStar.Pervasives.Lemma
(requires
FStar.List.Tot.Base.no_repeats_p (FStar.List.Tot.Base.map FStar.Pervasives.Native.fst l1) /\
FStar.List.Tot.Base.no_repeats_p (FStar.List.Tot.Base.map FStar.Pervasives.Native.fst l2) /\
(forall (kv: (tk * tv)). FStar.List.Tot.Base.memP kv l1 <==> FStar.List.Tot.Base.memP kv l2)
)
(ensures
forall (k: tk). CBOR.Spec.Map.list_ghost_assoc k l1 == CBOR.Spec.Map.list_ghost_assoc k l2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Classical.forall_intro",
"Prims.l_imp",
"Prims.l_and",
"FStar.List.Tot.Base.no_repeats_p",
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.fst",
"Prims.l_Forall",
"Prims.l_iff",
"FStar.List.Tot.Base.memP",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"CBOR.Spec.Map.list_ghost_assoc",
"FStar.Classical.move_requires",
"CBOR.Spec.Map.list_ghost_assoc_no_repeats_equiv'",
"Prims.unit",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let list_ghost_assoc_no_repeats_equiv (#tk #tv: Type) (l1 l2: list (tk & tv))
: Lemma
(requires
(List.Tot.no_repeats_p (List.Tot.map fst l1) /\ List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv. List.Tot.memP kv l1 <==> List.Tot.memP kv l2)))
(ensures (forall k. list_ghost_assoc k l1 == list_ghost_assoc k l2)) =
| Classical.forall_intro (Classical.move_requires (list_ghost_assoc_no_repeats_equiv' l1 l2)) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_f_star | val compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2)) | val compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2)) | let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 97,
"start_col": 0,
"start_line": 85
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
i1: Steel.ST.GenElim1.Base.gen_elim_i ->
f1: Steel.ST.GenElim1.gen_elim_t i1 ->
i2: Steel.ST.GenElim1.Base.gen_elim_i ->
f2: Steel.ST.GenElim1.gen_elim_t i2
-> Prims.GTot (Steel.ST.GenElim1.gen_elim_t (Steel.ST.GenElim1.Base.GEStar i1 i2)) | Prims.GTot | [
"sometrivial"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.gen_elim_t",
"Steel.Memory.inames",
"Steel.ST.GenElim1.Base.compute_gen_elim_a",
"Steel.ST.GenElim1.Base.GEStar",
"Prims.unit",
"Steel.ST.Util.rewrite",
"Steel.Effect.Common.star",
"Steel.ST.GenElim1.Base.compute_gen_elim_q",
"Steel.ST.GenElim1.Base.coerce_with_trefl",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Steel.ST.GenElim1.Base.compute_gen_elim_p"
] | [] | false | false | false | false | false | let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2)) =
| fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2))
((compute_gen_elim_p i1) `star` (compute_gen_elim_p i2));
let res1 = f1 _ in
let res2 = f2 _ in
let res:compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite ((compute_gen_elim_q i1 res1) `star` (compute_gen_elim_q i2 res2))
(compute_gen_elim_q (GEStar i1 i2) res);
res | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_sorted_append_chunk_elim | val list_sorted_append_chunk_elim (#t: Type) (order: (t -> t -> bool)) (l1 l2 l3: list t)
: Lemma
(requires
((forall x y z. (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))))
(ensures (List.Tot.sorted order (l1 `List.Tot.append` l3)))
(decreases l1) | val list_sorted_append_chunk_elim (#t: Type) (order: (t -> t -> bool)) (l1 l2 l3: list t)
: Lemma
(requires
((forall x y z. (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))))
(ensures (List.Tot.sorted order (l1 `List.Tot.append` l3)))
(decreases l1) | let rec list_sorted_append_chunk_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2 l3: list t)
: Lemma
(requires (
(forall x y z . (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))
))
(ensures (
List.Tot.sorted order (l1 `List.Tot.append` l3)
))
(decreases l1)
= match l1 with
| [] -> list_sorted_append_elim order l2 l3
| [a] ->
begin match l3 with
| [] -> ()
| b :: q ->
list_sorted_append_elim order l2 l3;
list_sorted_order_elim order [] a l2 b q
end
| _ :: l1' -> list_sorted_append_chunk_elim order l1' l2 l3 | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 61,
"end_line": 336,
"start_col": 0,
"start_line": 314
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m'
let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2
let rec list_ghost_assoc_mem_intro
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l)
= let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l'
let rec list_ghost_assoc_no_repeats_mem_elim
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l) /\
List.Tot.memP (k, v) l
))
(ensures (list_ghost_assoc k l == Some v))
(decreases l)
= List.Tot.memP_map_intro fst (k, v) l;
let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then
if FStar.StrongExcludedMiddle.strong_excluded_middle (v == v')
then ()
else List.Tot.memP_map_intro fst (k, v) l'
else list_ghost_assoc_no_repeats_mem_elim k v l'
let list_ghost_assoc_no_repeats_mem
(#tk #tv: Type)
(l: list (tk & tv))
(k: tk)
(v: tv)
: Lemma
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l) ==> (list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l)))
= Classical.move_requires (list_ghost_assoc_no_repeats_mem_elim k v) l;
Classical.move_requires (list_ghost_assoc_mem_intro k v) l
let list_ghost_assoc_no_repeats_equiv'
(#tk #tv: Type)
(l1 l2: list (tk & tv))
(k: tk)
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (list_ghost_assoc k l1 == list_ghost_assoc k l2))
= match list_ghost_assoc k l1 with
| None ->
begin match list_ghost_assoc k l2 with
| None -> ()
| Some v ->
list_ghost_assoc_no_repeats_mem l2 k v;
list_ghost_assoc_no_repeats_mem l1 k v
end
| Some v ->
list_ghost_assoc_no_repeats_mem l1 k v;
list_ghost_assoc_no_repeats_mem l2 k v
let list_ghost_assoc_no_repeats_equiv
(#tk #tv: Type)
(l1 l2: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (forall k . list_ghost_assoc k l1 == list_ghost_assoc k l2))
= Classical.forall_intro (Classical.move_requires (list_ghost_assoc_no_repeats_equiv' l1 l2))
[@@noextract_to "krml"] noextract
let rec map_sort_merge
(#t1 #t2: Type)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Tot (bool & list (t1 & t2))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| (k1, v1) :: l1', (k2, v2) :: l2' ->
begin let c = key_compare k1 k2 in
if c = 0
then (false, accu `List.Tot.append` (l1 `List.Tot.append` l2))
else if c < 0
then map_sort_merge key_compare (accu `List.Tot.append` [(k1, v1)]) l1' l2
else
map_sort_merge key_compare (accu `List.Tot.append` [(k2, v2)]) l1 l2'
// TODO in this case:
// 1. prove that the sort is stable, i.e. that the maps are extensionally equal throughout
// 2. extract and swap the whole prefix of l2 less than the head of l1, rather than just the head of l2
end
| [], _ -> (true, accu `List.Tot.append` l2)
| _, [] -> (true, accu `List.Tot.append` l1)
let rec list_sorted_append_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2: list t)
: Lemma
(requires (List.Tot.sorted order (l1 `List.Tot.append` l2)))
(ensures (
List.Tot.sorted order l1 /\
List.Tot.sorted order l2
))
(decreases l1)
= match l1 with
| [] -> ()
| [_] -> ()
| a :: b :: q ->
list_sorted_append_elim order (b :: q) l2
let rec list_sorted_append_chunk_intro
(#t: Type)
(order: t -> t -> bool)
(l1 l2 l3: list t)
: Lemma
(requires (
List.Tot.sorted order (l1 `List.Tot.append` l2) /\
List.Tot.sorted order (l2 `List.Tot.append` l3) /\
Cons? l2
))
(ensures (
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))
))
(decreases l1)
= match l1 with
| [] -> ()
| [a] -> () // because of List.Tot.sorted (l2 `List.Tot.append` l3) and Cons? l2
| a :: l1' -> list_sorted_append_chunk_intro order l1' l2 l3
let rec list_sorted_order_elim
(#t: Type)
(order: t -> t -> bool)
(l0: list t)
(a1: t)
(l1: list t)
(a2: t)
(l2: list t)
: Lemma
(requires (
(forall x y z . (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l0 `List.Tot.append` (a1 :: (l1 `List.Tot.append` (a2 :: l2))))
))
(ensures (order a1 a2 == true))
(decreases (List.Tot.length l0 + List.Tot.length l1))
= match l0 with
| [] ->
begin match l1 with
| [] -> ()
| a1' :: l1' ->
list_sorted_order_elim order [] a1' l1' a2 l2 // and transitivity
end
| a0 :: l0' ->
list_sorted_order_elim order l0' a1 l1 a2 l2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | order: (_: t -> _: t -> Prims.bool) -> l1: Prims.list t -> l2: Prims.list t -> l3: Prims.list t
-> FStar.Pervasives.Lemma
(requires
(forall (x: t) (y: t) (z: t). order x y /\ order y z ==> order x z) /\
FStar.List.Tot.Properties.sorted order (l1 @ l2 @ l3))
(ensures FStar.List.Tot.Properties.sorted order (l1 @ l3))
(decreases l1) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.bool",
"Prims.list",
"CBOR.Spec.Map.list_sorted_append_elim",
"CBOR.Spec.Map.list_sorted_order_elim",
"Prims.Nil",
"Prims.unit",
"CBOR.Spec.Map.list_sorted_append_chunk_elim",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.b2t",
"FStar.List.Tot.Properties.sorted",
"FStar.List.Tot.Base.append",
"Prims.squash",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_sorted_append_chunk_elim (#t: Type) (order: (t -> t -> bool)) (l1 l2 l3: list t)
: Lemma
(requires
((forall x y z. (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))))
(ensures (List.Tot.sorted order (l1 `List.Tot.append` l3)))
(decreases l1) =
| match l1 with
| [] -> list_sorted_append_elim order l2 l3
| [a] ->
(match l3 with
| [] -> ()
| b :: q ->
list_sorted_append_elim order l2 l3;
list_sorted_order_elim order [] a l2 b q)
| _ :: l1' -> list_sorted_append_chunk_elim order l1' l2 l3 | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_ghost_assoc_no_repeats_mem | val list_ghost_assoc_no_repeats_mem (#tk #tv: Type) (l: list (tk & tv)) (k: tk) (v: tv)
: Lemma
(ensures
(List.Tot.no_repeats_p (List.Tot.map fst l) ==>
(list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l))) | val list_ghost_assoc_no_repeats_mem (#tk #tv: Type) (l: list (tk & tv)) (k: tk) (v: tv)
: Lemma
(ensures
(List.Tot.no_repeats_p (List.Tot.map fst l) ==>
(list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l))) | let list_ghost_assoc_no_repeats_mem
(#tk #tv: Type)
(l: list (tk & tv))
(k: tk)
(v: tv)
: Lemma
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l) ==> (list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l)))
= Classical.move_requires (list_ghost_assoc_no_repeats_mem_elim k v) l;
Classical.move_requires (list_ghost_assoc_mem_intro k v) l | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 60,
"end_line": 191,
"start_col": 0,
"start_line": 183
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m'
let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2
let rec list_ghost_assoc_mem_intro
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l)
= let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l'
let rec list_ghost_assoc_no_repeats_mem_elim
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l) /\
List.Tot.memP (k, v) l
))
(ensures (list_ghost_assoc k l == Some v))
(decreases l)
= List.Tot.memP_map_intro fst (k, v) l;
let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then
if FStar.StrongExcludedMiddle.strong_excluded_middle (v == v')
then ()
else List.Tot.memP_map_intro fst (k, v) l'
else list_ghost_assoc_no_repeats_mem_elim k v l' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 (tk * tv) -> k: tk -> v: tv
-> FStar.Pervasives.Lemma
(ensures
FStar.List.Tot.Base.no_repeats_p (FStar.List.Tot.Base.map FStar.Pervasives.Native.fst l) ==>
(CBOR.Spec.Map.list_ghost_assoc k l == FStar.Pervasives.Native.Some v <==>
FStar.List.Tot.Base.memP (k, v) l)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Classical.move_requires",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"CBOR.Spec.Map.list_ghost_assoc",
"FStar.Pervasives.Native.Some",
"FStar.List.Tot.Base.memP",
"FStar.Pervasives.Native.Mktuple2",
"CBOR.Spec.Map.list_ghost_assoc_mem_intro",
"Prims.unit",
"Prims.l_and",
"FStar.List.Tot.Base.no_repeats_p",
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.fst",
"CBOR.Spec.Map.list_ghost_assoc_no_repeats_mem_elim",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"Prims.l_iff",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let list_ghost_assoc_no_repeats_mem (#tk #tv: Type) (l: list (tk & tv)) (k: tk) (v: tv)
: Lemma
(ensures
(List.Tot.no_repeats_p (List.Tot.map fst l) ==>
(list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l))) =
| Classical.move_requires (list_ghost_assoc_no_repeats_mem_elim k v) l;
Classical.move_requires (list_ghost_assoc_mem_intro k v) l | false |
Hacl.Streaming.Poly1305_256.fsti | Hacl.Streaming.Poly1305_256.update | val update : Hacl.Streaming.Functor.update_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M256)
(FStar.Ghost.reveal (FStar.Ghost.hide ()))
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M256)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | let update = F.update (poly1305 M256) (G.hide ()) (t M256) (poly1305_key.I.s ()) | {
"file_name": "code/streaming/Hacl.Streaming.Poly1305_256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 80,
"end_line": 20,
"start_col": 0,
"start_line": 20
} | module Hacl.Streaming.Poly1305_256
module G = FStar.Ghost
module F = Hacl.Streaming.Functor
module I = Hacl.Streaming.Interface
open Hacl.Impl.Poly1305.Fields
open Hacl.Streaming.Poly1305
#set-options "--fuel 0 --ifuel 0 --z3rlimit 100"
/// Type abbreviation - makes KaRaMeL use pretty names in the generated code
let state_t = F.state_s (poly1305 M256) () (t M256) (poly1305_key.I.s ())
noextract
let alloca = F.alloca (poly1305 M256) () (t M256) (poly1305_key.I.s ())
let malloc = F.malloc (poly1305 M256) () (t M256) (poly1305_key.I.s ())
let reset = F.reset (poly1305 M256) (G.hide ()) (t M256) (poly1305_key.I.s ()) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Streaming.Poly1305.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Poly1305_256.fsti"
} | [
{
"abbrev": false,
"full_module": "Hacl.Streaming.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Interface",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Streaming.Functor.update_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M256)
(FStar.Ghost.reveal (FStar.Ghost.hide ()))
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M256)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.update",
"Prims.unit",
"Hacl.Streaming.Poly1305.poly1305",
"Hacl.Impl.Poly1305.Fields.M256",
"FStar.Ghost.hide",
"Hacl.Streaming.Poly1305.t",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"Hacl.Streaming.Poly1305.poly1305_key"
] | [] | false | false | false | false | false | let update =
| F.update (poly1305 M256) (G.hide ()) (t M256) (poly1305_key.I.s ()) | false |
|
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_splitAt_append | val list_splitAt_append (#t: Type) (n: nat) (l: list t)
: Lemma
(ensures
(let l1, l2 = List.Tot.splitAt n l in
l == l1 `List.Tot.append` l2)) [SMTPat (List.Tot.splitAt n l)] | val list_splitAt_append (#t: Type) (n: nat) (l: list t)
: Lemma
(ensures
(let l1, l2 = List.Tot.splitAt n l in
l == l1 `List.Tot.append` l2)) [SMTPat (List.Tot.splitAt n l)] | let rec list_splitAt_append
(#t: Type)
(n: nat)
(l: list t)
: Lemma
(ensures (let (l1, l2) = List.Tot.splitAt n l in
l == l1 `List.Tot.append` l2
))
[SMTPat (List.Tot.splitAt n l)]
= match l with
| [] -> ()
| a :: q ->
if n = 0 then () else list_splitAt_append (n - 1) q | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 55,
"end_line": 433,
"start_col": 0,
"start_line": 421
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m'
let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2
let rec list_ghost_assoc_mem_intro
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l)
= let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l'
let rec list_ghost_assoc_no_repeats_mem_elim
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l) /\
List.Tot.memP (k, v) l
))
(ensures (list_ghost_assoc k l == Some v))
(decreases l)
= List.Tot.memP_map_intro fst (k, v) l;
let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then
if FStar.StrongExcludedMiddle.strong_excluded_middle (v == v')
then ()
else List.Tot.memP_map_intro fst (k, v) l'
else list_ghost_assoc_no_repeats_mem_elim k v l'
let list_ghost_assoc_no_repeats_mem
(#tk #tv: Type)
(l: list (tk & tv))
(k: tk)
(v: tv)
: Lemma
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l) ==> (list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l)))
= Classical.move_requires (list_ghost_assoc_no_repeats_mem_elim k v) l;
Classical.move_requires (list_ghost_assoc_mem_intro k v) l
let list_ghost_assoc_no_repeats_equiv'
(#tk #tv: Type)
(l1 l2: list (tk & tv))
(k: tk)
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (list_ghost_assoc k l1 == list_ghost_assoc k l2))
= match list_ghost_assoc k l1 with
| None ->
begin match list_ghost_assoc k l2 with
| None -> ()
| Some v ->
list_ghost_assoc_no_repeats_mem l2 k v;
list_ghost_assoc_no_repeats_mem l1 k v
end
| Some v ->
list_ghost_assoc_no_repeats_mem l1 k v;
list_ghost_assoc_no_repeats_mem l2 k v
let list_ghost_assoc_no_repeats_equiv
(#tk #tv: Type)
(l1 l2: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (forall k . list_ghost_assoc k l1 == list_ghost_assoc k l2))
= Classical.forall_intro (Classical.move_requires (list_ghost_assoc_no_repeats_equiv' l1 l2))
[@@noextract_to "krml"] noextract
let rec map_sort_merge
(#t1 #t2: Type)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Tot (bool & list (t1 & t2))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| (k1, v1) :: l1', (k2, v2) :: l2' ->
begin let c = key_compare k1 k2 in
if c = 0
then (false, accu `List.Tot.append` (l1 `List.Tot.append` l2))
else if c < 0
then map_sort_merge key_compare (accu `List.Tot.append` [(k1, v1)]) l1' l2
else
map_sort_merge key_compare (accu `List.Tot.append` [(k2, v2)]) l1 l2'
// TODO in this case:
// 1. prove that the sort is stable, i.e. that the maps are extensionally equal throughout
// 2. extract and swap the whole prefix of l2 less than the head of l1, rather than just the head of l2
end
| [], _ -> (true, accu `List.Tot.append` l2)
| _, [] -> (true, accu `List.Tot.append` l1)
let rec list_sorted_append_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2: list t)
: Lemma
(requires (List.Tot.sorted order (l1 `List.Tot.append` l2)))
(ensures (
List.Tot.sorted order l1 /\
List.Tot.sorted order l2
))
(decreases l1)
= match l1 with
| [] -> ()
| [_] -> ()
| a :: b :: q ->
list_sorted_append_elim order (b :: q) l2
let rec list_sorted_append_chunk_intro
(#t: Type)
(order: t -> t -> bool)
(l1 l2 l3: list t)
: Lemma
(requires (
List.Tot.sorted order (l1 `List.Tot.append` l2) /\
List.Tot.sorted order (l2 `List.Tot.append` l3) /\
Cons? l2
))
(ensures (
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))
))
(decreases l1)
= match l1 with
| [] -> ()
| [a] -> () // because of List.Tot.sorted (l2 `List.Tot.append` l3) and Cons? l2
| a :: l1' -> list_sorted_append_chunk_intro order l1' l2 l3
let rec list_sorted_order_elim
(#t: Type)
(order: t -> t -> bool)
(l0: list t)
(a1: t)
(l1: list t)
(a2: t)
(l2: list t)
: Lemma
(requires (
(forall x y z . (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l0 `List.Tot.append` (a1 :: (l1 `List.Tot.append` (a2 :: l2))))
))
(ensures (order a1 a2 == true))
(decreases (List.Tot.length l0 + List.Tot.length l1))
= match l0 with
| [] ->
begin match l1 with
| [] -> ()
| a1' :: l1' ->
list_sorted_order_elim order [] a1' l1' a2 l2 // and transitivity
end
| a0 :: l0' ->
list_sorted_order_elim order l0' a1 l1 a2 l2
let rec list_sorted_append_chunk_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2 l3: list t)
: Lemma
(requires (
(forall x y z . (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))
))
(ensures (
List.Tot.sorted order (l1 `List.Tot.append` l3)
))
(decreases l1)
= match l1 with
| [] -> list_sorted_append_elim order l2 l3
| [a] ->
begin match l3 with
| [] -> ()
| b :: q ->
list_sorted_append_elim order l2 l3;
list_sorted_order_elim order [] a l2 b q
end
| _ :: l1' -> list_sorted_append_chunk_elim order l1' l2 l3
let rec map_sort_merge_correct
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Lemma
(requires (
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z) /\
(forall x y . key_order x y == (key_compare x y < 0)) /\
(forall x y . key_compare x y == 0 <==> x == y) /\
(forall x y . (key_compare x y < 0 <==> key_compare y x > 0)) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l1) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l2)
))
(ensures (
let (sorted, res) = map_sort_merge key_compare accu l1 l2 in
(forall x . List.Tot.memP x res <==> List.Tot.memP x (accu `List.Tot.append` (l1 `List.Tot.append` l2))) /\
(List.Tot.no_repeats_p (List.Tot.map fst res) <==> List.Tot.no_repeats_p (List.Tot.map fst (accu `List.Tot.append` (l1 `List.Tot.append` l2)))) /\
(if sorted
then List.Tot.sorted (map_entry_order key_order _) res
else ~ (List.Tot.no_repeats_p (List.Tot.map fst res))
)
))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| [], _ -> ()
| _, [] -> List.Tot.append_l_nil l1
| (k1, v1) :: l1', (k2, v2) :: l2' ->
List.Tot.map_append fst l1 l2;
List.Tot.map_append fst accu (l1 `List.Tot.append` l2);
let c = key_compare k1 k2 in
if c = 0
then
List.Tot.no_repeats_p_false_intro (List.Tot.map fst accu) [k1] (List.Tot.map fst l1') (List.Tot.map fst l2')
else if c < 0
then begin
let accu' = accu `List.Tot.append` [(k1, v1)] in
List.Tot.append_assoc accu l1 l2;
List.Tot.append_assoc accu [(k1, v1)] l1';
List.Tot.append_assoc accu' l1' l2;
List.Tot.append_assoc accu [(k1, v1)] l2;
list_sorted_append_elim (map_entry_order key_order _) accu' l1';
list_sorted_append_elim (map_entry_order key_order _) accu l2;
list_sorted_append_chunk_intro (map_entry_order key_order _) accu [(k1, v1)] l2;
map_sort_merge_correct key_order key_compare accu' l1' l2
end
else begin
let accu' = accu `List.Tot.append` [(k2, v2)] in
List.Tot.append_memP_forall l1 l2;
List.Tot.append_memP_forall accu (l1 `List.Tot.append` l2);
List.Tot.append_memP_forall accu [(k2, v2)];
List.Tot.append_memP_forall l1 l2';
List.Tot.append_memP_forall accu' (l1 `List.Tot.append` l2');
List.Tot.no_repeats_p_append_permut (List.Tot.map fst accu) [k2] (List.Tot.map fst l1) [] (List.Tot.map fst l2');
List.Tot.append_assoc (List.Tot.map fst accu) [k2] (List.Tot.map fst l1 `List.Tot.append` List.Tot.map fst l2');
List.Tot.map_append fst accu [(k2, v2)];
List.Tot.map_append fst l1 l2';
List.Tot.map_append fst accu' (l1 `List.Tot.append` l2');
List.Tot.append_assoc accu [(k2, v2)] l2';
list_sorted_append_elim (map_entry_order key_order _) accu' l2';
list_sorted_append_elim (map_entry_order key_order _) accu l1;
list_sorted_append_chunk_intro (map_entry_order key_order _) accu [(k2, v2)] l1;
List.Tot.append_assoc accu [(k2, v2)] l1;
map_sort_merge_correct key_order key_compare accu' l1 l2'
end
let rec list_splitAt_length
(#t: Type)
(n: nat)
(l: list t)
: Lemma
(requires (List.Tot.length l >= n))
(ensures (
let (l1, l2) = List.Tot.splitAt n l in
List.Tot.length l1 == n /\
List.Tot.length l1 + List.Tot.length l2 == List.Tot.length l
))
[SMTPat (List.Tot.splitAt n l)]
= if n = 0 then () else list_splitAt_length (n - 1) (List.Tot.tl l) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | n: Prims.nat -> l: Prims.list t
-> FStar.Pervasives.Lemma
(ensures
(let _ = FStar.List.Tot.Base.splitAt n l in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ l1 l2 = _ in
l == l1 @ l2)
<:
Type0)) [SMTPat (FStar.List.Tot.Base.splitAt n l)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.list",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"CBOR.Spec.Map.list_splitAt_append",
"Prims.op_Subtraction",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.List.Tot.Base.append",
"FStar.Pervasives.Native.tuple2",
"FStar.List.Tot.Base.splitAt",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [
"recursion"
] | false | false | true | false | false | let rec list_splitAt_append (#t: Type) (n: nat) (l: list t)
: Lemma
(ensures
(let l1, l2 = List.Tot.splitAt n l in
l == l1 `List.Tot.append` l2)) [SMTPat (List.Tot.splitAt n l)] =
| match l with
| [] -> ()
| a :: q -> if n = 0 then () else list_splitAt_append (n - 1) q | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_sorted_append_elim | val list_sorted_append_elim (#t: Type) (order: (t -> t -> bool)) (l1 l2: list t)
: Lemma (requires (List.Tot.sorted order (l1 `List.Tot.append` l2)))
(ensures (List.Tot.sorted order l1 /\ List.Tot.sorted order l2))
(decreases l1) | val list_sorted_append_elim (#t: Type) (order: (t -> t -> bool)) (l1 l2: list t)
: Lemma (requires (List.Tot.sorted order (l1 `List.Tot.append` l2)))
(ensures (List.Tot.sorted order l1 /\ List.Tot.sorted order l2))
(decreases l1) | let rec list_sorted_append_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2: list t)
: Lemma
(requires (List.Tot.sorted order (l1 `List.Tot.append` l2)))
(ensures (
List.Tot.sorted order l1 /\
List.Tot.sorted order l2
))
(decreases l1)
= match l1 with
| [] -> ()
| [_] -> ()
| a :: b :: q ->
list_sorted_append_elim order (b :: q) l2 | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 45,
"end_line": 268,
"start_col": 0,
"start_line": 253
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m'
let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2
let rec list_ghost_assoc_mem_intro
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l)
= let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l'
let rec list_ghost_assoc_no_repeats_mem_elim
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l) /\
List.Tot.memP (k, v) l
))
(ensures (list_ghost_assoc k l == Some v))
(decreases l)
= List.Tot.memP_map_intro fst (k, v) l;
let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then
if FStar.StrongExcludedMiddle.strong_excluded_middle (v == v')
then ()
else List.Tot.memP_map_intro fst (k, v) l'
else list_ghost_assoc_no_repeats_mem_elim k v l'
let list_ghost_assoc_no_repeats_mem
(#tk #tv: Type)
(l: list (tk & tv))
(k: tk)
(v: tv)
: Lemma
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l) ==> (list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l)))
= Classical.move_requires (list_ghost_assoc_no_repeats_mem_elim k v) l;
Classical.move_requires (list_ghost_assoc_mem_intro k v) l
let list_ghost_assoc_no_repeats_equiv'
(#tk #tv: Type)
(l1 l2: list (tk & tv))
(k: tk)
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (list_ghost_assoc k l1 == list_ghost_assoc k l2))
= match list_ghost_assoc k l1 with
| None ->
begin match list_ghost_assoc k l2 with
| None -> ()
| Some v ->
list_ghost_assoc_no_repeats_mem l2 k v;
list_ghost_assoc_no_repeats_mem l1 k v
end
| Some v ->
list_ghost_assoc_no_repeats_mem l1 k v;
list_ghost_assoc_no_repeats_mem l2 k v
let list_ghost_assoc_no_repeats_equiv
(#tk #tv: Type)
(l1 l2: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (forall k . list_ghost_assoc k l1 == list_ghost_assoc k l2))
= Classical.forall_intro (Classical.move_requires (list_ghost_assoc_no_repeats_equiv' l1 l2))
[@@noextract_to "krml"] noextract
let rec map_sort_merge
(#t1 #t2: Type)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Tot (bool & list (t1 & t2))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| (k1, v1) :: l1', (k2, v2) :: l2' ->
begin let c = key_compare k1 k2 in
if c = 0
then (false, accu `List.Tot.append` (l1 `List.Tot.append` l2))
else if c < 0
then map_sort_merge key_compare (accu `List.Tot.append` [(k1, v1)]) l1' l2
else
map_sort_merge key_compare (accu `List.Tot.append` [(k2, v2)]) l1 l2'
// TODO in this case:
// 1. prove that the sort is stable, i.e. that the maps are extensionally equal throughout
// 2. extract and swap the whole prefix of l2 less than the head of l1, rather than just the head of l2
end
| [], _ -> (true, accu `List.Tot.append` l2)
| _, [] -> (true, accu `List.Tot.append` l1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | order: (_: t -> _: t -> Prims.bool) -> l1: Prims.list t -> l2: Prims.list t
-> FStar.Pervasives.Lemma (requires FStar.List.Tot.Properties.sorted order (l1 @ l2))
(ensures
FStar.List.Tot.Properties.sorted order l1 /\ FStar.List.Tot.Properties.sorted order l2)
(decreases l1) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.bool",
"Prims.list",
"CBOR.Spec.Map.list_sorted_append_elim",
"Prims.Cons",
"Prims.unit",
"Prims.b2t",
"FStar.List.Tot.Properties.sorted",
"FStar.List.Tot.Base.append",
"Prims.squash",
"Prims.l_and",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_sorted_append_elim (#t: Type) (order: (t -> t -> bool)) (l1 l2: list t)
: Lemma (requires (List.Tot.sorted order (l1 `List.Tot.append` l2)))
(ensures (List.Tot.sorted order l1 /\ List.Tot.sorted order l2))
(decreases l1) =
| match l1 with
| [] -> ()
| [_] -> ()
| a :: b :: q -> list_sorted_append_elim order (b :: q) l2 | false |
Hacl.Streaming.Poly1305_256.fsti | Hacl.Streaming.Poly1305_256.state_t | val state_t : Type0 | let state_t = F.state_s (poly1305 M256) () (t M256) (poly1305_key.I.s ()) | {
"file_name": "code/streaming/Hacl.Streaming.Poly1305_256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 73,
"end_line": 13,
"start_col": 0,
"start_line": 13
} | module Hacl.Streaming.Poly1305_256
module G = FStar.Ghost
module F = Hacl.Streaming.Functor
module I = Hacl.Streaming.Interface
open Hacl.Impl.Poly1305.Fields
open Hacl.Streaming.Poly1305
#set-options "--fuel 0 --ifuel 0 --z3rlimit 100" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Streaming.Poly1305.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Poly1305_256.fsti"
} | [
{
"abbrev": false,
"full_module": "Hacl.Streaming.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Interface",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.state_s",
"Prims.unit",
"Hacl.Streaming.Poly1305.poly1305",
"Hacl.Impl.Poly1305.Fields.M256",
"Hacl.Streaming.Poly1305.t",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"Hacl.Streaming.Poly1305.poly1305_key"
] | [] | false | false | false | true | true | let state_t =
| F.state_s (poly1305 M256) () (t M256) (poly1305_key.I.s ()) | false |
|
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_sorted_append_chunk_intro | val list_sorted_append_chunk_intro (#t: Type) (order: (t -> t -> bool)) (l1 l2 l3: list t)
: Lemma
(requires
(List.Tot.sorted order (l1 `List.Tot.append` l2) /\
List.Tot.sorted order (l2 `List.Tot.append` l3) /\ Cons? l2))
(ensures (List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))))
(decreases l1) | val list_sorted_append_chunk_intro (#t: Type) (order: (t -> t -> bool)) (l1 l2 l3: list t)
: Lemma
(requires
(List.Tot.sorted order (l1 `List.Tot.append` l2) /\
List.Tot.sorted order (l2 `List.Tot.append` l3) /\ Cons? l2))
(ensures (List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))))
(decreases l1) | let rec list_sorted_append_chunk_intro
(#t: Type)
(order: t -> t -> bool)
(l1 l2 l3: list t)
: Lemma
(requires (
List.Tot.sorted order (l1 `List.Tot.append` l2) /\
List.Tot.sorted order (l2 `List.Tot.append` l3) /\
Cons? l2
))
(ensures (
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))
))
(decreases l1)
= match l1 with
| [] -> ()
| [a] -> () // because of List.Tot.sorted (l2 `List.Tot.append` l3) and Cons? l2
| a :: l1' -> list_sorted_append_chunk_intro order l1' l2 l3 | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 62,
"end_line": 287,
"start_col": 0,
"start_line": 270
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m'
let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2
let rec list_ghost_assoc_mem_intro
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l)
= let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l'
let rec list_ghost_assoc_no_repeats_mem_elim
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l) /\
List.Tot.memP (k, v) l
))
(ensures (list_ghost_assoc k l == Some v))
(decreases l)
= List.Tot.memP_map_intro fst (k, v) l;
let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then
if FStar.StrongExcludedMiddle.strong_excluded_middle (v == v')
then ()
else List.Tot.memP_map_intro fst (k, v) l'
else list_ghost_assoc_no_repeats_mem_elim k v l'
let list_ghost_assoc_no_repeats_mem
(#tk #tv: Type)
(l: list (tk & tv))
(k: tk)
(v: tv)
: Lemma
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l) ==> (list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l)))
= Classical.move_requires (list_ghost_assoc_no_repeats_mem_elim k v) l;
Classical.move_requires (list_ghost_assoc_mem_intro k v) l
let list_ghost_assoc_no_repeats_equiv'
(#tk #tv: Type)
(l1 l2: list (tk & tv))
(k: tk)
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (list_ghost_assoc k l1 == list_ghost_assoc k l2))
= match list_ghost_assoc k l1 with
| None ->
begin match list_ghost_assoc k l2 with
| None -> ()
| Some v ->
list_ghost_assoc_no_repeats_mem l2 k v;
list_ghost_assoc_no_repeats_mem l1 k v
end
| Some v ->
list_ghost_assoc_no_repeats_mem l1 k v;
list_ghost_assoc_no_repeats_mem l2 k v
let list_ghost_assoc_no_repeats_equiv
(#tk #tv: Type)
(l1 l2: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (forall k . list_ghost_assoc k l1 == list_ghost_assoc k l2))
= Classical.forall_intro (Classical.move_requires (list_ghost_assoc_no_repeats_equiv' l1 l2))
[@@noextract_to "krml"] noextract
let rec map_sort_merge
(#t1 #t2: Type)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Tot (bool & list (t1 & t2))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| (k1, v1) :: l1', (k2, v2) :: l2' ->
begin let c = key_compare k1 k2 in
if c = 0
then (false, accu `List.Tot.append` (l1 `List.Tot.append` l2))
else if c < 0
then map_sort_merge key_compare (accu `List.Tot.append` [(k1, v1)]) l1' l2
else
map_sort_merge key_compare (accu `List.Tot.append` [(k2, v2)]) l1 l2'
// TODO in this case:
// 1. prove that the sort is stable, i.e. that the maps are extensionally equal throughout
// 2. extract and swap the whole prefix of l2 less than the head of l1, rather than just the head of l2
end
| [], _ -> (true, accu `List.Tot.append` l2)
| _, [] -> (true, accu `List.Tot.append` l1)
let rec list_sorted_append_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2: list t)
: Lemma
(requires (List.Tot.sorted order (l1 `List.Tot.append` l2)))
(ensures (
List.Tot.sorted order l1 /\
List.Tot.sorted order l2
))
(decreases l1)
= match l1 with
| [] -> ()
| [_] -> ()
| a :: b :: q ->
list_sorted_append_elim order (b :: q) l2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | order: (_: t -> _: t -> Prims.bool) -> l1: Prims.list t -> l2: Prims.list t -> l3: Prims.list t
-> FStar.Pervasives.Lemma
(requires
FStar.List.Tot.Properties.sorted order (l1 @ l2) /\
FStar.List.Tot.Properties.sorted order (l2 @ l3) /\ Cons? l2)
(ensures FStar.List.Tot.Properties.sorted order (l1 @ l2 @ l3))
(decreases l1) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.bool",
"Prims.list",
"CBOR.Spec.Map.list_sorted_append_chunk_intro",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"FStar.List.Tot.Properties.sorted",
"FStar.List.Tot.Base.append",
"Prims.uu___is_Cons",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_sorted_append_chunk_intro (#t: Type) (order: (t -> t -> bool)) (l1 l2 l3: list t)
: Lemma
(requires
(List.Tot.sorted order (l1 `List.Tot.append` l2) /\
List.Tot.sorted order (l2 `List.Tot.append` l3) /\ Cons? l2))
(ensures (List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))))
(decreases l1) =
| match l1 with
| [] -> ()
| [a] -> ()
| a :: l1' -> list_sorted_append_chunk_intro order l1' l2 l3 | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.map_sort | val map_sort (#t1 #t2: Type) (key_compare: (t1 -> t1 -> int)) (l: list (t1 & t2))
: Tot (bool & list (t1 & t2)) (decreases (List.Tot.length l)) | val map_sort (#t1 #t2: Type) (key_compare: (t1 -> t1 -> int)) (l: list (t1 & t2))
: Tot (bool & list (t1 & t2)) (decreases (List.Tot.length l)) | let rec map_sort
(#t1 #t2: Type)
(key_compare: t1 -> t1 -> int)
(l: list (t1 & t2))
: Tot (bool & list (t1 & t2))
(decreases (List.Tot.length l))
= let len = List.Tot.length l in
if len < 2
then (true, l)
else
let (l1, l2) = List.Tot.splitAt (len / 2) l in
let (res, l1') = map_sort key_compare l1 in
if not res
then (false, l1' `List.Tot.append` l2)
else
let (res, l2') = map_sort key_compare l2 in
if not res
then (false, l1' `List.Tot.append` l2')
else map_sort_merge key_compare [] l1' l2' | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 48,
"end_line": 454,
"start_col": 0,
"start_line": 436
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m'
let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2
let rec list_ghost_assoc_mem_intro
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l)
= let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l'
let rec list_ghost_assoc_no_repeats_mem_elim
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l) /\
List.Tot.memP (k, v) l
))
(ensures (list_ghost_assoc k l == Some v))
(decreases l)
= List.Tot.memP_map_intro fst (k, v) l;
let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then
if FStar.StrongExcludedMiddle.strong_excluded_middle (v == v')
then ()
else List.Tot.memP_map_intro fst (k, v) l'
else list_ghost_assoc_no_repeats_mem_elim k v l'
let list_ghost_assoc_no_repeats_mem
(#tk #tv: Type)
(l: list (tk & tv))
(k: tk)
(v: tv)
: Lemma
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l) ==> (list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l)))
= Classical.move_requires (list_ghost_assoc_no_repeats_mem_elim k v) l;
Classical.move_requires (list_ghost_assoc_mem_intro k v) l
let list_ghost_assoc_no_repeats_equiv'
(#tk #tv: Type)
(l1 l2: list (tk & tv))
(k: tk)
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (list_ghost_assoc k l1 == list_ghost_assoc k l2))
= match list_ghost_assoc k l1 with
| None ->
begin match list_ghost_assoc k l2 with
| None -> ()
| Some v ->
list_ghost_assoc_no_repeats_mem l2 k v;
list_ghost_assoc_no_repeats_mem l1 k v
end
| Some v ->
list_ghost_assoc_no_repeats_mem l1 k v;
list_ghost_assoc_no_repeats_mem l2 k v
let list_ghost_assoc_no_repeats_equiv
(#tk #tv: Type)
(l1 l2: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (forall k . list_ghost_assoc k l1 == list_ghost_assoc k l2))
= Classical.forall_intro (Classical.move_requires (list_ghost_assoc_no_repeats_equiv' l1 l2))
[@@noextract_to "krml"] noextract
let rec map_sort_merge
(#t1 #t2: Type)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Tot (bool & list (t1 & t2))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| (k1, v1) :: l1', (k2, v2) :: l2' ->
begin let c = key_compare k1 k2 in
if c = 0
then (false, accu `List.Tot.append` (l1 `List.Tot.append` l2))
else if c < 0
then map_sort_merge key_compare (accu `List.Tot.append` [(k1, v1)]) l1' l2
else
map_sort_merge key_compare (accu `List.Tot.append` [(k2, v2)]) l1 l2'
// TODO in this case:
// 1. prove that the sort is stable, i.e. that the maps are extensionally equal throughout
// 2. extract and swap the whole prefix of l2 less than the head of l1, rather than just the head of l2
end
| [], _ -> (true, accu `List.Tot.append` l2)
| _, [] -> (true, accu `List.Tot.append` l1)
let rec list_sorted_append_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2: list t)
: Lemma
(requires (List.Tot.sorted order (l1 `List.Tot.append` l2)))
(ensures (
List.Tot.sorted order l1 /\
List.Tot.sorted order l2
))
(decreases l1)
= match l1 with
| [] -> ()
| [_] -> ()
| a :: b :: q ->
list_sorted_append_elim order (b :: q) l2
let rec list_sorted_append_chunk_intro
(#t: Type)
(order: t -> t -> bool)
(l1 l2 l3: list t)
: Lemma
(requires (
List.Tot.sorted order (l1 `List.Tot.append` l2) /\
List.Tot.sorted order (l2 `List.Tot.append` l3) /\
Cons? l2
))
(ensures (
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))
))
(decreases l1)
= match l1 with
| [] -> ()
| [a] -> () // because of List.Tot.sorted (l2 `List.Tot.append` l3) and Cons? l2
| a :: l1' -> list_sorted_append_chunk_intro order l1' l2 l3
let rec list_sorted_order_elim
(#t: Type)
(order: t -> t -> bool)
(l0: list t)
(a1: t)
(l1: list t)
(a2: t)
(l2: list t)
: Lemma
(requires (
(forall x y z . (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l0 `List.Tot.append` (a1 :: (l1 `List.Tot.append` (a2 :: l2))))
))
(ensures (order a1 a2 == true))
(decreases (List.Tot.length l0 + List.Tot.length l1))
= match l0 with
| [] ->
begin match l1 with
| [] -> ()
| a1' :: l1' ->
list_sorted_order_elim order [] a1' l1' a2 l2 // and transitivity
end
| a0 :: l0' ->
list_sorted_order_elim order l0' a1 l1 a2 l2
let rec list_sorted_append_chunk_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2 l3: list t)
: Lemma
(requires (
(forall x y z . (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))
))
(ensures (
List.Tot.sorted order (l1 `List.Tot.append` l3)
))
(decreases l1)
= match l1 with
| [] -> list_sorted_append_elim order l2 l3
| [a] ->
begin match l3 with
| [] -> ()
| b :: q ->
list_sorted_append_elim order l2 l3;
list_sorted_order_elim order [] a l2 b q
end
| _ :: l1' -> list_sorted_append_chunk_elim order l1' l2 l3
let rec map_sort_merge_correct
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Lemma
(requires (
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z) /\
(forall x y . key_order x y == (key_compare x y < 0)) /\
(forall x y . key_compare x y == 0 <==> x == y) /\
(forall x y . (key_compare x y < 0 <==> key_compare y x > 0)) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l1) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l2)
))
(ensures (
let (sorted, res) = map_sort_merge key_compare accu l1 l2 in
(forall x . List.Tot.memP x res <==> List.Tot.memP x (accu `List.Tot.append` (l1 `List.Tot.append` l2))) /\
(List.Tot.no_repeats_p (List.Tot.map fst res) <==> List.Tot.no_repeats_p (List.Tot.map fst (accu `List.Tot.append` (l1 `List.Tot.append` l2)))) /\
(if sorted
then List.Tot.sorted (map_entry_order key_order _) res
else ~ (List.Tot.no_repeats_p (List.Tot.map fst res))
)
))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| [], _ -> ()
| _, [] -> List.Tot.append_l_nil l1
| (k1, v1) :: l1', (k2, v2) :: l2' ->
List.Tot.map_append fst l1 l2;
List.Tot.map_append fst accu (l1 `List.Tot.append` l2);
let c = key_compare k1 k2 in
if c = 0
then
List.Tot.no_repeats_p_false_intro (List.Tot.map fst accu) [k1] (List.Tot.map fst l1') (List.Tot.map fst l2')
else if c < 0
then begin
let accu' = accu `List.Tot.append` [(k1, v1)] in
List.Tot.append_assoc accu l1 l2;
List.Tot.append_assoc accu [(k1, v1)] l1';
List.Tot.append_assoc accu' l1' l2;
List.Tot.append_assoc accu [(k1, v1)] l2;
list_sorted_append_elim (map_entry_order key_order _) accu' l1';
list_sorted_append_elim (map_entry_order key_order _) accu l2;
list_sorted_append_chunk_intro (map_entry_order key_order _) accu [(k1, v1)] l2;
map_sort_merge_correct key_order key_compare accu' l1' l2
end
else begin
let accu' = accu `List.Tot.append` [(k2, v2)] in
List.Tot.append_memP_forall l1 l2;
List.Tot.append_memP_forall accu (l1 `List.Tot.append` l2);
List.Tot.append_memP_forall accu [(k2, v2)];
List.Tot.append_memP_forall l1 l2';
List.Tot.append_memP_forall accu' (l1 `List.Tot.append` l2');
List.Tot.no_repeats_p_append_permut (List.Tot.map fst accu) [k2] (List.Tot.map fst l1) [] (List.Tot.map fst l2');
List.Tot.append_assoc (List.Tot.map fst accu) [k2] (List.Tot.map fst l1 `List.Tot.append` List.Tot.map fst l2');
List.Tot.map_append fst accu [(k2, v2)];
List.Tot.map_append fst l1 l2';
List.Tot.map_append fst accu' (l1 `List.Tot.append` l2');
List.Tot.append_assoc accu [(k2, v2)] l2';
list_sorted_append_elim (map_entry_order key_order _) accu' l2';
list_sorted_append_elim (map_entry_order key_order _) accu l1;
list_sorted_append_chunk_intro (map_entry_order key_order _) accu [(k2, v2)] l1;
List.Tot.append_assoc accu [(k2, v2)] l1;
map_sort_merge_correct key_order key_compare accu' l1 l2'
end
let rec list_splitAt_length
(#t: Type)
(n: nat)
(l: list t)
: Lemma
(requires (List.Tot.length l >= n))
(ensures (
let (l1, l2) = List.Tot.splitAt n l in
List.Tot.length l1 == n /\
List.Tot.length l1 + List.Tot.length l2 == List.Tot.length l
))
[SMTPat (List.Tot.splitAt n l)]
= if n = 0 then () else list_splitAt_length (n - 1) (List.Tot.tl l)
let rec list_splitAt_append
(#t: Type)
(n: nat)
(l: list t)
: Lemma
(ensures (let (l1, l2) = List.Tot.splitAt n l in
l == l1 `List.Tot.append` l2
))
[SMTPat (List.Tot.splitAt n l)]
= match l with
| [] -> ()
| a :: q ->
if n = 0 then () else list_splitAt_append (n - 1) q | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | key_compare: (_: t1 -> _: t1 -> Prims.int) -> l: Prims.list (t1 * t2)
-> Prims.Tot (Prims.bool * Prims.list (t1 * t2)) | Prims.Tot | [
"total",
""
] | [] | [
"Prims.int",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.op_LessThan",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"Prims.op_Negation",
"FStar.List.Tot.Base.append",
"CBOR.Spec.Map.map_sort_merge",
"Prims.Nil",
"CBOR.Spec.Map.map_sort",
"FStar.List.Tot.Base.splitAt",
"Prims.op_Division",
"Prims.nat",
"FStar.List.Tot.Base.length"
] | [
"recursion"
] | false | false | false | true | false | let rec map_sort (#t1 #t2: Type) (key_compare: (t1 -> t1 -> int)) (l: list (t1 & t2))
: Tot (bool & list (t1 & t2)) (decreases (List.Tot.length l)) =
| let len = List.Tot.length l in
if len < 2
then (true, l)
else
let l1, l2 = List.Tot.splitAt (len / 2) l in
let res, l1' = map_sort key_compare l1 in
if not res
then (false, l1' `List.Tot.append` l2)
else
let res, l2' = map_sort key_compare l2 in
if not res then (false, l1' `List.Tot.append` l2') else map_sort_merge key_compare [] l1' l2' | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_splitAt_length | val list_splitAt_length (#t: Type) (n: nat) (l: list t)
: Lemma (requires (List.Tot.length l >= n))
(ensures
(let l1, l2 = List.Tot.splitAt n l in
List.Tot.length l1 == n /\ List.Tot.length l1 + List.Tot.length l2 == List.Tot.length l))
[SMTPat (List.Tot.splitAt n l)] | val list_splitAt_length (#t: Type) (n: nat) (l: list t)
: Lemma (requires (List.Tot.length l >= n))
(ensures
(let l1, l2 = List.Tot.splitAt n l in
List.Tot.length l1 == n /\ List.Tot.length l1 + List.Tot.length l2 == List.Tot.length l))
[SMTPat (List.Tot.splitAt n l)] | let rec list_splitAt_length
(#t: Type)
(n: nat)
(l: list t)
: Lemma
(requires (List.Tot.length l >= n))
(ensures (
let (l1, l2) = List.Tot.splitAt n l in
List.Tot.length l1 == n /\
List.Tot.length l1 + List.Tot.length l2 == List.Tot.length l
))
[SMTPat (List.Tot.splitAt n l)]
= if n = 0 then () else list_splitAt_length (n - 1) (List.Tot.tl l) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 67,
"end_line": 419,
"start_col": 0,
"start_line": 407
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m'
let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2
let rec list_ghost_assoc_mem_intro
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l)
= let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l'
let rec list_ghost_assoc_no_repeats_mem_elim
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l) /\
List.Tot.memP (k, v) l
))
(ensures (list_ghost_assoc k l == Some v))
(decreases l)
= List.Tot.memP_map_intro fst (k, v) l;
let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then
if FStar.StrongExcludedMiddle.strong_excluded_middle (v == v')
then ()
else List.Tot.memP_map_intro fst (k, v) l'
else list_ghost_assoc_no_repeats_mem_elim k v l'
let list_ghost_assoc_no_repeats_mem
(#tk #tv: Type)
(l: list (tk & tv))
(k: tk)
(v: tv)
: Lemma
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l) ==> (list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l)))
= Classical.move_requires (list_ghost_assoc_no_repeats_mem_elim k v) l;
Classical.move_requires (list_ghost_assoc_mem_intro k v) l
let list_ghost_assoc_no_repeats_equiv'
(#tk #tv: Type)
(l1 l2: list (tk & tv))
(k: tk)
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (list_ghost_assoc k l1 == list_ghost_assoc k l2))
= match list_ghost_assoc k l1 with
| None ->
begin match list_ghost_assoc k l2 with
| None -> ()
| Some v ->
list_ghost_assoc_no_repeats_mem l2 k v;
list_ghost_assoc_no_repeats_mem l1 k v
end
| Some v ->
list_ghost_assoc_no_repeats_mem l1 k v;
list_ghost_assoc_no_repeats_mem l2 k v
let list_ghost_assoc_no_repeats_equiv
(#tk #tv: Type)
(l1 l2: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (forall k . list_ghost_assoc k l1 == list_ghost_assoc k l2))
= Classical.forall_intro (Classical.move_requires (list_ghost_assoc_no_repeats_equiv' l1 l2))
[@@noextract_to "krml"] noextract
let rec map_sort_merge
(#t1 #t2: Type)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Tot (bool & list (t1 & t2))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| (k1, v1) :: l1', (k2, v2) :: l2' ->
begin let c = key_compare k1 k2 in
if c = 0
then (false, accu `List.Tot.append` (l1 `List.Tot.append` l2))
else if c < 0
then map_sort_merge key_compare (accu `List.Tot.append` [(k1, v1)]) l1' l2
else
map_sort_merge key_compare (accu `List.Tot.append` [(k2, v2)]) l1 l2'
// TODO in this case:
// 1. prove that the sort is stable, i.e. that the maps are extensionally equal throughout
// 2. extract and swap the whole prefix of l2 less than the head of l1, rather than just the head of l2
end
| [], _ -> (true, accu `List.Tot.append` l2)
| _, [] -> (true, accu `List.Tot.append` l1)
let rec list_sorted_append_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2: list t)
: Lemma
(requires (List.Tot.sorted order (l1 `List.Tot.append` l2)))
(ensures (
List.Tot.sorted order l1 /\
List.Tot.sorted order l2
))
(decreases l1)
= match l1 with
| [] -> ()
| [_] -> ()
| a :: b :: q ->
list_sorted_append_elim order (b :: q) l2
let rec list_sorted_append_chunk_intro
(#t: Type)
(order: t -> t -> bool)
(l1 l2 l3: list t)
: Lemma
(requires (
List.Tot.sorted order (l1 `List.Tot.append` l2) /\
List.Tot.sorted order (l2 `List.Tot.append` l3) /\
Cons? l2
))
(ensures (
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))
))
(decreases l1)
= match l1 with
| [] -> ()
| [a] -> () // because of List.Tot.sorted (l2 `List.Tot.append` l3) and Cons? l2
| a :: l1' -> list_sorted_append_chunk_intro order l1' l2 l3
let rec list_sorted_order_elim
(#t: Type)
(order: t -> t -> bool)
(l0: list t)
(a1: t)
(l1: list t)
(a2: t)
(l2: list t)
: Lemma
(requires (
(forall x y z . (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l0 `List.Tot.append` (a1 :: (l1 `List.Tot.append` (a2 :: l2))))
))
(ensures (order a1 a2 == true))
(decreases (List.Tot.length l0 + List.Tot.length l1))
= match l0 with
| [] ->
begin match l1 with
| [] -> ()
| a1' :: l1' ->
list_sorted_order_elim order [] a1' l1' a2 l2 // and transitivity
end
| a0 :: l0' ->
list_sorted_order_elim order l0' a1 l1 a2 l2
let rec list_sorted_append_chunk_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2 l3: list t)
: Lemma
(requires (
(forall x y z . (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))
))
(ensures (
List.Tot.sorted order (l1 `List.Tot.append` l3)
))
(decreases l1)
= match l1 with
| [] -> list_sorted_append_elim order l2 l3
| [a] ->
begin match l3 with
| [] -> ()
| b :: q ->
list_sorted_append_elim order l2 l3;
list_sorted_order_elim order [] a l2 b q
end
| _ :: l1' -> list_sorted_append_chunk_elim order l1' l2 l3
let rec map_sort_merge_correct
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Lemma
(requires (
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z) /\
(forall x y . key_order x y == (key_compare x y < 0)) /\
(forall x y . key_compare x y == 0 <==> x == y) /\
(forall x y . (key_compare x y < 0 <==> key_compare y x > 0)) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l1) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l2)
))
(ensures (
let (sorted, res) = map_sort_merge key_compare accu l1 l2 in
(forall x . List.Tot.memP x res <==> List.Tot.memP x (accu `List.Tot.append` (l1 `List.Tot.append` l2))) /\
(List.Tot.no_repeats_p (List.Tot.map fst res) <==> List.Tot.no_repeats_p (List.Tot.map fst (accu `List.Tot.append` (l1 `List.Tot.append` l2)))) /\
(if sorted
then List.Tot.sorted (map_entry_order key_order _) res
else ~ (List.Tot.no_repeats_p (List.Tot.map fst res))
)
))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| [], _ -> ()
| _, [] -> List.Tot.append_l_nil l1
| (k1, v1) :: l1', (k2, v2) :: l2' ->
List.Tot.map_append fst l1 l2;
List.Tot.map_append fst accu (l1 `List.Tot.append` l2);
let c = key_compare k1 k2 in
if c = 0
then
List.Tot.no_repeats_p_false_intro (List.Tot.map fst accu) [k1] (List.Tot.map fst l1') (List.Tot.map fst l2')
else if c < 0
then begin
let accu' = accu `List.Tot.append` [(k1, v1)] in
List.Tot.append_assoc accu l1 l2;
List.Tot.append_assoc accu [(k1, v1)] l1';
List.Tot.append_assoc accu' l1' l2;
List.Tot.append_assoc accu [(k1, v1)] l2;
list_sorted_append_elim (map_entry_order key_order _) accu' l1';
list_sorted_append_elim (map_entry_order key_order _) accu l2;
list_sorted_append_chunk_intro (map_entry_order key_order _) accu [(k1, v1)] l2;
map_sort_merge_correct key_order key_compare accu' l1' l2
end
else begin
let accu' = accu `List.Tot.append` [(k2, v2)] in
List.Tot.append_memP_forall l1 l2;
List.Tot.append_memP_forall accu (l1 `List.Tot.append` l2);
List.Tot.append_memP_forall accu [(k2, v2)];
List.Tot.append_memP_forall l1 l2';
List.Tot.append_memP_forall accu' (l1 `List.Tot.append` l2');
List.Tot.no_repeats_p_append_permut (List.Tot.map fst accu) [k2] (List.Tot.map fst l1) [] (List.Tot.map fst l2');
List.Tot.append_assoc (List.Tot.map fst accu) [k2] (List.Tot.map fst l1 `List.Tot.append` List.Tot.map fst l2');
List.Tot.map_append fst accu [(k2, v2)];
List.Tot.map_append fst l1 l2';
List.Tot.map_append fst accu' (l1 `List.Tot.append` l2');
List.Tot.append_assoc accu [(k2, v2)] l2';
list_sorted_append_elim (map_entry_order key_order _) accu' l2';
list_sorted_append_elim (map_entry_order key_order _) accu l1;
list_sorted_append_chunk_intro (map_entry_order key_order _) accu [(k2, v2)] l1;
List.Tot.append_assoc accu [(k2, v2)] l1;
map_sort_merge_correct key_order key_compare accu' l1 l2'
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | n: Prims.nat -> l: Prims.list t
-> FStar.Pervasives.Lemma (requires FStar.List.Tot.Base.length l >= n)
(ensures
(let _ = FStar.List.Tot.Base.splitAt n l in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ l1 l2 = _ in
FStar.List.Tot.Base.length l1 == n /\
FStar.List.Tot.Base.length l1 + FStar.List.Tot.Base.length l2 ==
FStar.List.Tot.Base.length l)
<:
Type0))
[SMTPat (FStar.List.Tot.Base.splitAt n l)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.list",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"CBOR.Spec.Map.list_splitAt_length",
"Prims.op_Subtraction",
"FStar.List.Tot.Base.tl",
"Prims.unit",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.List.Tot.Base.length",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"Prims.op_Addition",
"FStar.Pervasives.Native.tuple2",
"FStar.List.Tot.Base.splitAt",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [
"recursion"
] | false | false | true | false | false | let rec list_splitAt_length (#t: Type) (n: nat) (l: list t)
: Lemma (requires (List.Tot.length l >= n))
(ensures
(let l1, l2 = List.Tot.splitAt n l in
List.Tot.length l1 == n /\ List.Tot.length l1 + List.Tot.length l2 == List.Tot.length l))
[SMTPat (List.Tot.splitAt n l)] =
| if n = 0 then () else list_splitAt_length (n - 1) (List.Tot.tl l) | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.list_memP_map_forall | val list_memP_map_forall (#t1 #t2: Type) (f: (t1 -> t2)) (l: list t1)
: Lemma
(forall y. List.Tot.memP y (List.Tot.map f l) <==> (exists x. List.Tot.memP x l /\ y == f x)) | val list_memP_map_forall (#t1 #t2: Type) (f: (t1 -> t2)) (l: list t1)
: Lemma
(forall y. List.Tot.memP y (List.Tot.map f l) <==> (exists x. List.Tot.memP x l /\ y == f x)) | let list_memP_map_forall
(#t1 #t2: Type)
(f: t1 -> t2)
(l: list t1)
: Lemma
(forall y . List.Tot.memP y (List.Tot.map f l) <==> (exists x . List.Tot.memP x l /\ y == f x))
= Classical.forall_intro (fun y -> List.Tot.memP_map_elim f y l);
Classical.forall_intro (fun x -> List.Tot.memP_map_intro f x l) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 65,
"end_line": 463,
"start_col": 0,
"start_line": 456
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m'
let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2
let rec list_ghost_assoc_mem_intro
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l)
= let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l'
let rec list_ghost_assoc_no_repeats_mem_elim
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l) /\
List.Tot.memP (k, v) l
))
(ensures (list_ghost_assoc k l == Some v))
(decreases l)
= List.Tot.memP_map_intro fst (k, v) l;
let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then
if FStar.StrongExcludedMiddle.strong_excluded_middle (v == v')
then ()
else List.Tot.memP_map_intro fst (k, v) l'
else list_ghost_assoc_no_repeats_mem_elim k v l'
let list_ghost_assoc_no_repeats_mem
(#tk #tv: Type)
(l: list (tk & tv))
(k: tk)
(v: tv)
: Lemma
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l) ==> (list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l)))
= Classical.move_requires (list_ghost_assoc_no_repeats_mem_elim k v) l;
Classical.move_requires (list_ghost_assoc_mem_intro k v) l
let list_ghost_assoc_no_repeats_equiv'
(#tk #tv: Type)
(l1 l2: list (tk & tv))
(k: tk)
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (list_ghost_assoc k l1 == list_ghost_assoc k l2))
= match list_ghost_assoc k l1 with
| None ->
begin match list_ghost_assoc k l2 with
| None -> ()
| Some v ->
list_ghost_assoc_no_repeats_mem l2 k v;
list_ghost_assoc_no_repeats_mem l1 k v
end
| Some v ->
list_ghost_assoc_no_repeats_mem l1 k v;
list_ghost_assoc_no_repeats_mem l2 k v
let list_ghost_assoc_no_repeats_equiv
(#tk #tv: Type)
(l1 l2: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (forall k . list_ghost_assoc k l1 == list_ghost_assoc k l2))
= Classical.forall_intro (Classical.move_requires (list_ghost_assoc_no_repeats_equiv' l1 l2))
[@@noextract_to "krml"] noextract
let rec map_sort_merge
(#t1 #t2: Type)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Tot (bool & list (t1 & t2))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| (k1, v1) :: l1', (k2, v2) :: l2' ->
begin let c = key_compare k1 k2 in
if c = 0
then (false, accu `List.Tot.append` (l1 `List.Tot.append` l2))
else if c < 0
then map_sort_merge key_compare (accu `List.Tot.append` [(k1, v1)]) l1' l2
else
map_sort_merge key_compare (accu `List.Tot.append` [(k2, v2)]) l1 l2'
// TODO in this case:
// 1. prove that the sort is stable, i.e. that the maps are extensionally equal throughout
// 2. extract and swap the whole prefix of l2 less than the head of l1, rather than just the head of l2
end
| [], _ -> (true, accu `List.Tot.append` l2)
| _, [] -> (true, accu `List.Tot.append` l1)
let rec list_sorted_append_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2: list t)
: Lemma
(requires (List.Tot.sorted order (l1 `List.Tot.append` l2)))
(ensures (
List.Tot.sorted order l1 /\
List.Tot.sorted order l2
))
(decreases l1)
= match l1 with
| [] -> ()
| [_] -> ()
| a :: b :: q ->
list_sorted_append_elim order (b :: q) l2
let rec list_sorted_append_chunk_intro
(#t: Type)
(order: t -> t -> bool)
(l1 l2 l3: list t)
: Lemma
(requires (
List.Tot.sorted order (l1 `List.Tot.append` l2) /\
List.Tot.sorted order (l2 `List.Tot.append` l3) /\
Cons? l2
))
(ensures (
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))
))
(decreases l1)
= match l1 with
| [] -> ()
| [a] -> () // because of List.Tot.sorted (l2 `List.Tot.append` l3) and Cons? l2
| a :: l1' -> list_sorted_append_chunk_intro order l1' l2 l3
let rec list_sorted_order_elim
(#t: Type)
(order: t -> t -> bool)
(l0: list t)
(a1: t)
(l1: list t)
(a2: t)
(l2: list t)
: Lemma
(requires (
(forall x y z . (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l0 `List.Tot.append` (a1 :: (l1 `List.Tot.append` (a2 :: l2))))
))
(ensures (order a1 a2 == true))
(decreases (List.Tot.length l0 + List.Tot.length l1))
= match l0 with
| [] ->
begin match l1 with
| [] -> ()
| a1' :: l1' ->
list_sorted_order_elim order [] a1' l1' a2 l2 // and transitivity
end
| a0 :: l0' ->
list_sorted_order_elim order l0' a1 l1 a2 l2
let rec list_sorted_append_chunk_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2 l3: list t)
: Lemma
(requires (
(forall x y z . (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))
))
(ensures (
List.Tot.sorted order (l1 `List.Tot.append` l3)
))
(decreases l1)
= match l1 with
| [] -> list_sorted_append_elim order l2 l3
| [a] ->
begin match l3 with
| [] -> ()
| b :: q ->
list_sorted_append_elim order l2 l3;
list_sorted_order_elim order [] a l2 b q
end
| _ :: l1' -> list_sorted_append_chunk_elim order l1' l2 l3
let rec map_sort_merge_correct
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Lemma
(requires (
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z) /\
(forall x y . key_order x y == (key_compare x y < 0)) /\
(forall x y . key_compare x y == 0 <==> x == y) /\
(forall x y . (key_compare x y < 0 <==> key_compare y x > 0)) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l1) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l2)
))
(ensures (
let (sorted, res) = map_sort_merge key_compare accu l1 l2 in
(forall x . List.Tot.memP x res <==> List.Tot.memP x (accu `List.Tot.append` (l1 `List.Tot.append` l2))) /\
(List.Tot.no_repeats_p (List.Tot.map fst res) <==> List.Tot.no_repeats_p (List.Tot.map fst (accu `List.Tot.append` (l1 `List.Tot.append` l2)))) /\
(if sorted
then List.Tot.sorted (map_entry_order key_order _) res
else ~ (List.Tot.no_repeats_p (List.Tot.map fst res))
)
))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| [], _ -> ()
| _, [] -> List.Tot.append_l_nil l1
| (k1, v1) :: l1', (k2, v2) :: l2' ->
List.Tot.map_append fst l1 l2;
List.Tot.map_append fst accu (l1 `List.Tot.append` l2);
let c = key_compare k1 k2 in
if c = 0
then
List.Tot.no_repeats_p_false_intro (List.Tot.map fst accu) [k1] (List.Tot.map fst l1') (List.Tot.map fst l2')
else if c < 0
then begin
let accu' = accu `List.Tot.append` [(k1, v1)] in
List.Tot.append_assoc accu l1 l2;
List.Tot.append_assoc accu [(k1, v1)] l1';
List.Tot.append_assoc accu' l1' l2;
List.Tot.append_assoc accu [(k1, v1)] l2;
list_sorted_append_elim (map_entry_order key_order _) accu' l1';
list_sorted_append_elim (map_entry_order key_order _) accu l2;
list_sorted_append_chunk_intro (map_entry_order key_order _) accu [(k1, v1)] l2;
map_sort_merge_correct key_order key_compare accu' l1' l2
end
else begin
let accu' = accu `List.Tot.append` [(k2, v2)] in
List.Tot.append_memP_forall l1 l2;
List.Tot.append_memP_forall accu (l1 `List.Tot.append` l2);
List.Tot.append_memP_forall accu [(k2, v2)];
List.Tot.append_memP_forall l1 l2';
List.Tot.append_memP_forall accu' (l1 `List.Tot.append` l2');
List.Tot.no_repeats_p_append_permut (List.Tot.map fst accu) [k2] (List.Tot.map fst l1) [] (List.Tot.map fst l2');
List.Tot.append_assoc (List.Tot.map fst accu) [k2] (List.Tot.map fst l1 `List.Tot.append` List.Tot.map fst l2');
List.Tot.map_append fst accu [(k2, v2)];
List.Tot.map_append fst l1 l2';
List.Tot.map_append fst accu' (l1 `List.Tot.append` l2');
List.Tot.append_assoc accu [(k2, v2)] l2';
list_sorted_append_elim (map_entry_order key_order _) accu' l2';
list_sorted_append_elim (map_entry_order key_order _) accu l1;
list_sorted_append_chunk_intro (map_entry_order key_order _) accu [(k2, v2)] l1;
List.Tot.append_assoc accu [(k2, v2)] l1;
map_sort_merge_correct key_order key_compare accu' l1 l2'
end
let rec list_splitAt_length
(#t: Type)
(n: nat)
(l: list t)
: Lemma
(requires (List.Tot.length l >= n))
(ensures (
let (l1, l2) = List.Tot.splitAt n l in
List.Tot.length l1 == n /\
List.Tot.length l1 + List.Tot.length l2 == List.Tot.length l
))
[SMTPat (List.Tot.splitAt n l)]
= if n = 0 then () else list_splitAt_length (n - 1) (List.Tot.tl l)
let rec list_splitAt_append
(#t: Type)
(n: nat)
(l: list t)
: Lemma
(ensures (let (l1, l2) = List.Tot.splitAt n l in
l == l1 `List.Tot.append` l2
))
[SMTPat (List.Tot.splitAt n l)]
= match l with
| [] -> ()
| a :: q ->
if n = 0 then () else list_splitAt_append (n - 1) q
[@@noextract_to "krml"] noextract
let rec map_sort
(#t1 #t2: Type)
(key_compare: t1 -> t1 -> int)
(l: list (t1 & t2))
: Tot (bool & list (t1 & t2))
(decreases (List.Tot.length l))
= let len = List.Tot.length l in
if len < 2
then (true, l)
else
let (l1, l2) = List.Tot.splitAt (len / 2) l in
let (res, l1') = map_sort key_compare l1 in
if not res
then (false, l1' `List.Tot.append` l2)
else
let (res, l2') = map_sort key_compare l2 in
if not res
then (false, l1' `List.Tot.append` l2')
else map_sort_merge key_compare [] l1' l2' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: (_: t1 -> t2) -> l: Prims.list t1
-> FStar.Pervasives.Lemma
(ensures
forall (y: t2).
FStar.List.Tot.Base.memP y (FStar.List.Tot.Base.map f l) <==>
(exists (x: t1). FStar.List.Tot.Base.memP x l /\ y == f x)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"FStar.Classical.forall_intro",
"Prims.l_imp",
"FStar.List.Tot.Base.memP",
"FStar.List.Tot.Base.map",
"FStar.List.Tot.Properties.memP_map_intro",
"Prims.unit",
"Prims.l_Exists",
"Prims.l_and",
"Prims.eq2",
"FStar.List.Tot.Properties.memP_map_elim",
"Prims.l_True",
"Prims.squash",
"Prims.l_Forall",
"Prims.l_iff",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let list_memP_map_forall (#t1 #t2: Type) (f: (t1 -> t2)) (l: list t1)
: Lemma
(forall y. List.Tot.memP y (List.Tot.map f l) <==> (exists x. List.Tot.memP x l /\ y == f x)) =
| Classical.forall_intro (fun y -> List.Tot.memP_map_elim f y l);
Classical.forall_intro (fun x -> List.Tot.memP_map_intro f x l) | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.map_sort_merge | val map_sort_merge (#t1 #t2: Type) (key_compare: (t1 -> t1 -> int)) (accu l1 l2: list (t1 & t2))
: Tot (bool & list (t1 & t2)) (decreases (List.Tot.length l1 + List.Tot.length l2)) | val map_sort_merge (#t1 #t2: Type) (key_compare: (t1 -> t1 -> int)) (accu l1 l2: list (t1 & t2))
: Tot (bool & list (t1 & t2)) (decreases (List.Tot.length l1 + List.Tot.length l2)) | let rec map_sort_merge
(#t1 #t2: Type)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Tot (bool & list (t1 & t2))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| (k1, v1) :: l1', (k2, v2) :: l2' ->
begin let c = key_compare k1 k2 in
if c = 0
then (false, accu `List.Tot.append` (l1 `List.Tot.append` l2))
else if c < 0
then map_sort_merge key_compare (accu `List.Tot.append` [(k1, v1)]) l1' l2
else
map_sort_merge key_compare (accu `List.Tot.append` [(k2, v2)]) l1 l2'
// TODO in this case:
// 1. prove that the sort is stable, i.e. that the maps are extensionally equal throughout
// 2. extract and swap the whole prefix of l2 less than the head of l1, rather than just the head of l2
end
| [], _ -> (true, accu `List.Tot.append` l2)
| _, [] -> (true, accu `List.Tot.append` l1) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 46,
"end_line": 251,
"start_col": 0,
"start_line": 229
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m'
let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2
let rec list_ghost_assoc_mem_intro
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l)
= let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l'
let rec list_ghost_assoc_no_repeats_mem_elim
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l) /\
List.Tot.memP (k, v) l
))
(ensures (list_ghost_assoc k l == Some v))
(decreases l)
= List.Tot.memP_map_intro fst (k, v) l;
let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then
if FStar.StrongExcludedMiddle.strong_excluded_middle (v == v')
then ()
else List.Tot.memP_map_intro fst (k, v) l'
else list_ghost_assoc_no_repeats_mem_elim k v l'
let list_ghost_assoc_no_repeats_mem
(#tk #tv: Type)
(l: list (tk & tv))
(k: tk)
(v: tv)
: Lemma
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l) ==> (list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l)))
= Classical.move_requires (list_ghost_assoc_no_repeats_mem_elim k v) l;
Classical.move_requires (list_ghost_assoc_mem_intro k v) l
let list_ghost_assoc_no_repeats_equiv'
(#tk #tv: Type)
(l1 l2: list (tk & tv))
(k: tk)
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (list_ghost_assoc k l1 == list_ghost_assoc k l2))
= match list_ghost_assoc k l1 with
| None ->
begin match list_ghost_assoc k l2 with
| None -> ()
| Some v ->
list_ghost_assoc_no_repeats_mem l2 k v;
list_ghost_assoc_no_repeats_mem l1 k v
end
| Some v ->
list_ghost_assoc_no_repeats_mem l1 k v;
list_ghost_assoc_no_repeats_mem l2 k v
let list_ghost_assoc_no_repeats_equiv
(#tk #tv: Type)
(l1 l2: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (forall k . list_ghost_assoc k l1 == list_ghost_assoc k l2))
= Classical.forall_intro (Classical.move_requires (list_ghost_assoc_no_repeats_equiv' l1 l2)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
key_compare: (_: t1 -> _: t1 -> Prims.int) ->
accu: Prims.list (t1 * t2) ->
l1: Prims.list (t1 * t2) ->
l2: Prims.list (t1 * t2)
-> Prims.Tot (Prims.bool * Prims.list (t1 * t2)) | Prims.Tot | [
"total",
""
] | [] | [
"Prims.int",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Prims.op_Equality",
"Prims.bool",
"FStar.List.Tot.Base.append",
"Prims.op_LessThan",
"CBOR.Spec.Map.map_sort_merge",
"Prims.Cons",
"Prims.Nil"
] | [
"recursion"
] | false | false | false | true | false | let rec map_sort_merge (#t1 #t2: Type) (key_compare: (t1 -> t1 -> int)) (accu l1 l2: list (t1 & t2))
: Tot (bool & list (t1 & t2)) (decreases (List.Tot.length l1 + List.Tot.length l2)) =
| match l1, l2 with
| (k1, v1) :: l1', (k2, v2) :: l2' ->
let c = key_compare k1 k2 in
if c = 0
then (false, accu `List.Tot.append` (l1 `List.Tot.append` l2))
else
if c < 0
then map_sort_merge key_compare (accu `List.Tot.append` [(k1, v1)]) l1' l2
else map_sort_merge key_compare (accu `List.Tot.append` [(k2, v2)]) l1 l2'
| [], _ -> (true, accu `List.Tot.append` l2)
| _, [] -> (true, accu `List.Tot.append` l1) | false |
Hacl.Spec.Bignum.ModInvLimb.fst | Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_inv_step_odd | val mod_inv_limb_inv_step_odd:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ v ub0 % 2 = 1 /\
pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = (v ub0 + v beta) / 2 % pow2 (bits t) in
let vb = (v vb0 / 2 + v alpha) % pow2 (bits t) in
pow2 (bits t - i + 1) == 2 * (ub * 2 * v alpha - vb * v beta))) | val mod_inv_limb_inv_step_odd:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ v ub0 % 2 = 1 /\
pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = (v ub0 + v beta) / 2 % pow2 (bits t) in
let vb = (v vb0 / 2 + v alpha) % pow2 (bits t) in
pow2 (bits t - i + 1) == 2 * (ub * 2 * v alpha - vb * v beta))) | let mod_inv_limb_inv_step_odd #t n0 i ub0 vb0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = (v ub0 + v beta) / 2 % pow2 pbits in
let vb = (v vb0 / 2 + v alpha) % pow2 pbits in
calc (==) {
2 * (ub * 2 * v alpha - vb * v beta);
(==) { Math.Lemmas.small_mod ((v ub0 + v beta) / 2) (pow2 pbits) }
2 * ((v ub0 + v beta) / 2 * 2 * v alpha - vb * v beta);
(==) { Math.Lemmas.small_mod (v vb0 / 2 + v alpha) (pow2 pbits) }
2 * ((v ub0 + v beta) / 2 * 2 * v alpha - (v vb0 / 2 + v alpha) * v beta);
(==) { Math.Lemmas.distributivity_sub_right 2 ((v ub0 + v beta) / 2 * 2 * v alpha) ((v vb0 / 2 + v alpha) * v beta) }
2 * (v ub0 + v beta) / 2 * 2 * v alpha - 2 * (v vb0 / 2 + v alpha) * v beta;
(==) { Math.Lemmas.div_exact_r (v ub0 + v beta) 2 }
(v ub0 + v beta) * 2 * v alpha - 2 * (v vb0 / 2 + v alpha) * v beta;
(==) { Math.Lemmas.paren_mul_right 2 (v vb0 / 2 + v alpha) (v beta) }
(v ub0 + v beta) * 2 * v alpha - 2 * ((v vb0 / 2 + v alpha) * v beta);
(==) { Math.Lemmas.distributivity_add_left (v vb0 / 2) (v alpha) (v beta) }
(v ub0 + v beta) * 2 * v alpha - 2 * (v vb0 / 2 * v beta + v alpha * v beta);
(==) { Math.Lemmas.distributivity_add_right 2 (v vb0 / 2 * v beta) (v alpha * v beta);
Math.Lemmas.paren_mul_right 2 (v vb0 / 2) (v beta);
Math.Lemmas.paren_mul_right 2 (v alpha) (v beta) }
(v ub0 + v beta) * 2 * v alpha - (2 * (v vb0 / 2) * v beta + 2 * v alpha * v beta);
(==) { mod_inv_limb_inv_vb_is_even n0 i ub0 vb0; Math.Lemmas.div_exact_r (v vb0) 2 }
(v ub0 + v beta) * 2 * v alpha - (v vb0 * v beta + 2 * v alpha * v beta);
(==) { Math.Lemmas.distributivity_add_left (v ub0) (v beta) (2 * v alpha) }
v ub0 * 2 * v alpha + v beta * 2 * v alpha - (v vb0 * v beta + 2 * v alpha * v beta);
(==) { Math.Lemmas.paren_mul_right (v beta) 2 (v alpha); Math.Lemmas.swap_mul (v beta) (2 * v alpha) }
v ub0 * 2 * v alpha + 2 * v alpha * v beta - v vb0 * v beta - 2 * v alpha * v beta;
(==) { }
v ub0 * 2 * v alpha - v vb0 * v beta;
(==) { assert (pow2 (pbits - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta) }
pow2 (pbits - i + 1);
};
assert (2 * (ub * 2 * v alpha - vb * v beta) == pow2 (pbits - i + 1)) | {
"file_name": "code/bignum/Hacl.Spec.Bignum.ModInvLimb.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 71,
"end_line": 181,
"start_col": 0,
"start_line": 146
} | module Hacl.Spec.Bignum.ModInvLimb
open FStar.Mul
open Lib.IntTypes
open Lib.LoopCombinators
open Hacl.Spec.Bignum.Definitions
module M = Hacl.Spec.Montgomery.Lemmas
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(**
the modular inverse function was taken from
https://github.com/google/boringssl/blob/master/crypto/fipsmodule/bn/montgomery_inv.c *)
val mod_inv_limb_f:
#t:limb_t
-> alpha:limb t
-> beta:limb t
-> i:nat{i < bits t}
-> tuple2 (limb t) (limb t) ->
tuple2 (limb t) (limb t)
let mod_inv_limb_f #t alpha beta i (ub, vb) =
let u_is_odd = uint #t 0 -. (ub &. uint #t 1) in
let beta_if_u_is_odd = beta &. u_is_odd in
let u = ((ub ^. beta_if_u_is_odd) >>. 1ul) +. (ub &. beta_if_u_is_odd) in
let alpha_if_u_is_odd = alpha &. u_is_odd in
let v = (vb >>. 1ul) +. alpha_if_u_is_odd in
(u, v)
let mod_inv_limb_t (t:limb_t) (i:nat{i <= bits t}) = tuple2 (limb t) (limb t)
let mod_inv_limb #t n0 =
let alpha = uint #t 1 <<. size (bits t - 1) in
let beta = n0 in
let (u, v) = repeat_gen (bits t) (mod_inv_limb_t t) (mod_inv_limb_f alpha beta) (uint #t 1, uint #t 0) in
v
// Replace with `a >> 1 + b >> 1 + a & b & 1`?
val add_div_2_nooverflow: #t:limb_t -> a:limb t -> b:limb t ->
Lemma (v (((a ^. b) >>. 1ul) +. (a &. b)) == (v a + v b) / 2 % pow2 (bits t))
let add_div_2_nooverflow #t a b = admit()
val x_if_u_is_odd: #t:limb_t -> x:limb t -> u:limb t ->
Lemma (let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
v (x &. u_is_odd) == (if v u % 2 = 0 then 0 else v x))
let x_if_u_is_odd #t x u =
let u_is_odd = uint #t 0 -. (u &. uint #t 1) in
logand_mask u (uint #t 1) 1;
assert (v (u &. uint #t 1) == v u % 2);
assert (v u_is_odd == (- v u % 2) % pow2 (bits t));
assert (v u_is_odd == (if v u % 2 = 0 then 0 else pow2 (bits t) - 1));
if v u % 2 = 0 then
logand_zeros x
else
logand_ones x
val mod_inv_limb_inv_vb_is_even:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures v vb0 % 2 = 0)
private
let aux_mod_2_neg (n:nat) : Lemma (n % 2 == (-n) % 2) =
()
let mod_inv_limb_inv_vb_is_even #t n0 i ub0 vb0 =
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
Math.Lemmas.pow2_multiplication_modulo_lemma_1 1 1 (bits t - i + 1);
assert (pow2 (bits t - i + 1) % 2 == 0);
calc (==) {
pow2 (bits t - i + 1) % 2;
(==) { }
(v ub0 * 2 * v alpha - v vb0 * v beta) % 2;
(==) { Math.Lemmas.lemma_mod_plus_distr_l (v ub0 * 2 * v alpha) (- v vb0 * v beta) 2 }
(- v vb0 * v beta) % 2;
(==) { Math.Lemmas.lemma_mod_mul_distr_r (- v vb0) (v beta) 2 }
(- v vb0) % 2;
(==) { aux_mod_2_neg (v vb0) } // flaky without the lemma call
v vb0 % 2;
}
val mod_inv_limb_inv_step_even:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ v ub0 % 2 = 0 /\
pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = v ub0 / 2 % pow2 (bits t) in
let vb = v vb0 / 2 % pow2 (bits t) in
pow2 (bits t - i + 1) == 2 * (ub * 2 * v alpha - vb * v beta)))
let mod_inv_limb_inv_step_even #t n0 i ub0 vb0 =
let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = v ub0 / 2 % pow2 pbits in
let vb = v vb0 / 2 % pow2 pbits in
Math.Lemmas.small_mod (v ub0 / 2) (pow2 pbits);
Math.Lemmas.small_mod (v vb0 / 2) (pow2 pbits);
assert (ub * 2 * v alpha - vb * v beta == v ub0 / 2 * 2 * v alpha - v vb0 / 2 * v beta);
calc (==) {
2 * (ub * 2 * v alpha - vb * v beta);
(==) { }
2 * (v ub0 / 2 * 2 * v alpha - v vb0 / 2 * v beta);
(==) { Math.Lemmas.distributivity_sub_right 2 (v ub0 / 2 * 2 * v alpha) (v vb0 / 2 * v beta) }
2 * v ub0 / 2 * 2 * v alpha - 2 * (v vb0 / 2) * v beta;
(==) { Math.Lemmas.div_exact_r (v ub0) 2 }
v ub0 * 2 * v alpha - 2 * (v vb0 / 2) * v beta;
(==) { mod_inv_limb_inv_vb_is_even n0 i ub0 vb0; Math.Lemmas.div_exact_r (v vb0) 2 }
v ub0 * 2 * v alpha - v vb0 * v beta;
(==) {assert (pow2 (pbits - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta) }
pow2 (pbits - i + 1);
};
assert (2 * (ub * 2 * v alpha - vb * v beta) == pow2 (pbits - i + 1))
#push-options "--z3rlimit 150"
val mod_inv_limb_inv_step_odd:
#t:limb_t -> n0:limb t
-> i:pos{i <= bits t} -> ub0:limb t -> vb0:limb t -> Lemma
(requires
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
v n0 % 2 = 1 /\ v ub0 % 2 = 1 /\
pow2 (bits t - i + 1) == v ub0 * 2 * v alpha - v vb0 * v beta))
(ensures
(let alpha = uint #t #SEC 1 <<. size (bits t - 1) in let beta = n0 in
let ub = (v ub0 + v beta) / 2 % pow2 (bits t) in
let vb = (v vb0 / 2 + v alpha) % pow2 (bits t) in
pow2 (bits t - i + 1) == 2 * (ub * 2 * v alpha - vb * v beta))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Spec.Bignum.ModInvLimb.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.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": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
n0: Hacl.Spec.Bignum.Definitions.limb t ->
i: Prims.pos{i <= Lib.IntTypes.bits t} ->
ub0: Hacl.Spec.Bignum.Definitions.limb t ->
vb0: Hacl.Spec.Bignum.Definitions.limb t
-> FStar.Pervasives.Lemma
(requires
(let alpha = Lib.IntTypes.uint 1 <<. Lib.IntTypes.size (Lib.IntTypes.bits t - 1) in
let beta = n0 in
Lib.IntTypes.v n0 % 2 = 1 /\ Lib.IntTypes.v ub0 % 2 = 1 /\
Prims.pow2 (Lib.IntTypes.bits t - i + 1) ==
(Lib.IntTypes.v ub0 * 2) * Lib.IntTypes.v alpha - Lib.IntTypes.v vb0 * Lib.IntTypes.v beta
))
(ensures
(let alpha = Lib.IntTypes.uint 1 <<. Lib.IntTypes.size (Lib.IntTypes.bits t - 1) in
let beta = n0 in
let ub =
(Lib.IntTypes.v ub0 + Lib.IntTypes.v beta) / 2 % Prims.pow2 (Lib.IntTypes.bits t)
in
let vb =
(Lib.IntTypes.v vb0 / 2 + Lib.IntTypes.v alpha) % Prims.pow2 (Lib.IntTypes.bits t)
in
Prims.pow2 (Lib.IntTypes.bits t - i + 1) ==
2 * ((ub * 2) * Lib.IntTypes.v alpha - vb * Lib.IntTypes.v beta))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.bits",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.op_Subtraction",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Prims.op_Addition",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Prims.op_Division",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.small_mod",
"Prims.squash",
"FStar.Math.Lemmas.distributivity_sub_right",
"FStar.Math.Lemmas.div_exact_r",
"FStar.Math.Lemmas.paren_mul_right",
"FStar.Math.Lemmas.distributivity_add_left",
"FStar.Math.Lemmas.distributivity_add_right",
"Hacl.Spec.Bignum.ModInvLimb.mod_inv_limb_inv_vb_is_even",
"FStar.Math.Lemmas.swap_mul",
"Prims.op_Modulus",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.uint",
"Lib.IntTypes.size"
] | [] | false | false | true | false | false | let mod_inv_limb_inv_step_odd #t n0 i ub0 vb0 =
| let pbits = bits t in
let alpha = uint #t #SEC 1 <<. size (bits t - 1) in
let beta = n0 in
let ub = (v ub0 + v beta) / 2 % pow2 pbits in
let vb = (v vb0 / 2 + v alpha) % pow2 pbits in
calc ( == ) {
2 * ((ub * 2) * v alpha - vb * v beta);
( == ) { Math.Lemmas.small_mod ((v ub0 + v beta) / 2) (pow2 pbits) }
2 * ((((v ub0 + v beta) / 2) * 2) * v alpha - vb * v beta);
( == ) { Math.Lemmas.small_mod (v vb0 / 2 + v alpha) (pow2 pbits) }
2 * ((((v ub0 + v beta) / 2) * 2) * v alpha - (v vb0 / 2 + v alpha) * v beta);
( == ) { Math.Lemmas.distributivity_sub_right 2
((((v ub0 + v beta) / 2) * 2) * v alpha)
((v vb0 / 2 + v alpha) * v beta) }
((2 * (v ub0 + v beta) / 2) * 2) * v alpha - (2 * (v vb0 / 2 + v alpha)) * v beta;
( == ) { Math.Lemmas.div_exact_r (v ub0 + v beta) 2 }
((v ub0 + v beta) * 2) * v alpha - (2 * (v vb0 / 2 + v alpha)) * v beta;
( == ) { Math.Lemmas.paren_mul_right 2 (v vb0 / 2 + v alpha) (v beta) }
((v ub0 + v beta) * 2) * v alpha - 2 * ((v vb0 / 2 + v alpha) * v beta);
( == ) { Math.Lemmas.distributivity_add_left (v vb0 / 2) (v alpha) (v beta) }
((v ub0 + v beta) * 2) * v alpha - 2 * ((v vb0 / 2) * v beta + v alpha * v beta);
( == ) { (Math.Lemmas.distributivity_add_right 2 ((v vb0 / 2) * v beta) (v alpha * v beta);
Math.Lemmas.paren_mul_right 2 (v vb0 / 2) (v beta);
Math.Lemmas.paren_mul_right 2 (v alpha) (v beta)) }
((v ub0 + v beta) * 2) * v alpha - ((2 * (v vb0 / 2)) * v beta + (2 * v alpha) * v beta);
( == ) { (mod_inv_limb_inv_vb_is_even n0 i ub0 vb0;
Math.Lemmas.div_exact_r (v vb0) 2) }
((v ub0 + v beta) * 2) * v alpha - (v vb0 * v beta + (2 * v alpha) * v beta);
( == ) { Math.Lemmas.distributivity_add_left (v ub0) (v beta) (2 * v alpha) }
(v ub0 * 2) * v alpha + (v beta * 2) * v alpha - (v vb0 * v beta + (2 * v alpha) * v beta);
( == ) { (Math.Lemmas.paren_mul_right (v beta) 2 (v alpha);
Math.Lemmas.swap_mul (v beta) (2 * v alpha)) }
(v ub0 * 2) * v alpha + (2 * v alpha) * v beta - v vb0 * v beta - (2 * v alpha) * v beta;
( == ) { () }
(v ub0 * 2) * v alpha - v vb0 * v beta;
( == ) { assert (pow2 (pbits - i + 1) == (v ub0 * 2) * v alpha - v vb0 * v beta) }
pow2 (pbits - i + 1);
};
assert (2 * ((ub * 2) * v alpha - vb * v beta) == pow2 (pbits - i + 1)) | false |
Hacl.Impl.Chacha20.Core32.fst | Hacl.Impl.Chacha20.Core32.xor_block | val xor_block:
o:lbuffer uint8 64ul
-> st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h o /\ live h st /\ live h b)
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == Spec.xor_block (as_seq h0 st) (as_seq h0 b)) | val xor_block:
o:lbuffer uint8 64ul
-> st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h o /\ live h st /\ live h b)
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == Spec.xor_block (as_seq h0 st) (as_seq h0 b)) | let xor_block o st b =
push_frame();
let bl = create_state() in
load_state bl b;
map2T (size 16) bl ( ^. ) bl st;
store_state o bl;
pop_frame() | {
"file_name": "code/chacha20/Hacl.Impl.Chacha20.Core32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 121,
"start_col": 0,
"start_line": 115
} | module Hacl.Impl.Chacha20.Core32
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Sequence
open Lib.Buffer
open Lib.ByteBuffer
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20
let state = lbuffer uint32 16ul
let index = i:size_t{size_v i < 16}
inline_for_extraction
val create_state: unit ->
StackInline state
(requires fun h -> True)
(ensures fun h0 r h1 -> live h1 r /\
as_seq h1 r == Seq.create 16 (u32 0) /\
stack_allocated r h0 h1 (Seq.create 16 (u32 0)))
let create_state () = create (size 16) (u32 0)
inline_for_extraction
val load_state:
st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Lib.ByteSequence.uints_from_bytes_le (as_seq h0 b))
let load_state st b =
uints_from_bytes_le st b
inline_for_extraction
val store_state:
b:lbuffer uint8 64ul
-> st:state ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == Lib.ByteSequence.uints_to_bytes_le (as_seq h0 st))
let store_state st b =
uints_to_bytes_le 16ul st b
inline_for_extraction
val set_counter:
st:state
-> c:size_t ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Seq.upd (as_seq h0 st) 12 (size_to_uint32 c))
let set_counter st c =
st.(size 12) <- size_to_uint32 c
inline_for_extraction
val incr_counter:
st:state ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1)
let incr_counter st =
let c = st.(size 12) in
st.(size 12) <- c +. u32 1
inline_for_extraction
val copy_state:
st:state
-> ost:state ->
Stack unit
(requires fun h -> live h st /\ live h ost /\ disjoint st ost)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == as_seq h0 ost)
let copy_state st ost = copy #MUT #uint32 #(size 16) st ost
inline_for_extraction
val sum_state:
st:state
-> ost:state ->
Stack unit
(requires fun h -> live h st /\ live h ost /\ eq_or_disjoint st ost)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.sum_state (as_seq h0 st) (as_seq h0 ost))
let sum_state st ost = map2T #MUT #MUT #uint32 #uint32 #uint32 (size 16) st ( +. ) st ost
#set-options "--z3rlimit 100"
inline_for_extraction
val xor_block:
o:lbuffer uint8 64ul
-> st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h o /\ live h st /\ live h b)
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == Spec.xor_block (as_seq h0 st) (as_seq h0 b)) | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20.Core32.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
o: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul ->
st: Hacl.Impl.Chacha20.Core32.state ->
b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Chacha20.Core32.state",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Impl.Chacha20.Core32.store_state",
"Lib.Buffer.map2T",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint32",
"Lib.IntTypes.size",
"Lib.IntTypes.op_Hat_Dot",
"Lib.IntTypes.U32",
"Lib.IntTypes.SEC",
"Hacl.Impl.Chacha20.Core32.load_state",
"Hacl.Impl.Chacha20.Core32.create_state",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let xor_block o st b =
| push_frame ();
let bl = create_state () in
load_state bl b;
map2T (size 16) bl ( ^. ) bl st;
store_state o bl;
pop_frame () | false |
Vale.AES.PPC64LE.AES256.fsti | Vale.AES.PPC64LE.AES256.va_wp_AES256EncryptBlock_6way | val va_wp_AES256EncryptBlock_6way
(in1 in2 in3 in4 in5 in6: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_AES256EncryptBlock_6way
(in1 in2 in3 in4 in5 in6: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_AES256EncryptBlock_6way (in1:quad32) (in2:quad32) (in3:quad32) (in4:quad32) (in5:quad32)
(in6:quad32) (key:(seq nat32)) (round_keys:(seq quad32)) (keys_buffer:buffer128) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_256 key /\ FStar.Seq.Base.length
#quad32 round_keys == 15 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key
/\ va_get_vec 0 va_s0 == in1 /\ va_get_vec 1 va_s0 == in2 /\ va_get_vec 2 va_s0 == in3 /\
va_get_vec 3 va_s0 == in4 /\ va_get_vec 4 va_s0 == in5 /\ va_get_vec 5 va_s0 == in6 /\
va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer
(va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_s0) (va_get_reg 4 va_s0) keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat)
. i < 15 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read
keys_buffer i (va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i) /\
(forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32)
(va_x_v4:quad32) (va_x_v5:quad32) (va_x_v6:quad32) . let va_sM = va_upd_vec 6 va_x_v6
(va_upd_vec 5 va_x_v5 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2
(va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0))))))) in va_get_ok
va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in1 /\ va_get_vec
1 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in2 /\ va_get_vec 2 va_sM ==
Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in3 /\ va_get_vec 3 va_sM ==
Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in4 /\ va_get_vec 4 va_sM ==
Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in5 /\ va_get_vec 5 va_sM ==
Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in6 ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.AES.PPC64LE.AES256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 76,
"end_line": 212,
"start_col": 0,
"start_line": 191
} | module Vale.AES.PPC64LE.AES256
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.Arch.Types
open Vale.AES.AES256_helpers_BE
#reset-options "--z3rlimit 20"
//-- KeyExpansion256Stdcall
val va_code_KeyExpansion256Stdcall : va_dummy:unit -> Tot va_code
val va_codegen_success_KeyExpansion256Stdcall : va_dummy:unit -> Tot va_pbool
val va_lemma_KeyExpansion256Stdcall : va_b0:va_code -> va_s0:va_state -> input_key_b:buffer128 ->
output_key_expansion_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_KeyExpansion256Stdcall ()) va_s0 /\ va_get_ok va_s0 /\
(let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_s0) (va_get_reg 4 va_s0) input_key_b 2 (va_get_mem_layout va_s0) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0)
output_key_expansion_b 15 (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 /\
(let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_sM) (va_get_reg 4 va_sM) input_key_b 2 (va_get_mem_layout va_sM) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM)
output_key_expansion_b 15 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers_BE.make_AES256_key
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0
(va_get_mem_heaplet 0 va_s0))) (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0))) in
Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(reverse_bytes_quad32
(buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}j <= 14 ==>
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b
j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key) j)) /\ va_state_eq va_sM (va_update_vec
5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1
va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_mem_heaplet 1 va_sM
(va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))
[@ va_qattr]
let va_wp_KeyExpansion256Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128)
(va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_s0) (va_get_reg 4 va_s0) input_key_b 2 (va_get_mem_layout va_s0) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0)
output_key_expansion_b 15 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap)
(va_x_heap1:vale_heap) (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32)
(va_x_v3:quad32) (va_x_v4:quad32) (va_x_v5:quad32) . let va_sM = va_upd_vec 5 va_x_v5
(va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem
va_x_mem va_s0)))))))) in va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers_BE.make_AES256_key
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0
(va_get_mem_heaplet 0 va_s0))) (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0))) in
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM)
input_key_b 2 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 15 (va_get_mem_layout
va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b
(va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) .
{:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1
va_sM)))}j <= 14 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index
#Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key) j)) ==> va_k
va_sM (())))
val va_wpProof_KeyExpansion256Stdcall : input_key_b:buffer128 -> output_key_expansion_b:buffer128
-> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_KeyExpansion256Stdcall input_key_b output_key_expansion_b
va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion256Stdcall ())
([va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0;
va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_KeyExpansion256Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128) :
(va_quickCode unit (va_code_KeyExpansion256Stdcall ())) =
(va_QProc (va_code_KeyExpansion256Stdcall ()) ([va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3;
va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem])
(va_wp_KeyExpansion256Stdcall input_key_b output_key_expansion_b)
(va_wpProof_KeyExpansion256Stdcall input_key_b output_key_expansion_b))
//--
//-- AES256EncryptBlock
val va_code_AES256EncryptBlock : va_dummy:unit -> Tot va_code
val va_codegen_success_AES256EncryptBlock : va_dummy:unit -> Tot va_pbool
val va_lemma_AES256EncryptBlock : va_b0:va_code -> va_s0:va_state -> input:quad32 -> key:(seq
nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AES256EncryptBlock ()) va_s0 /\ va_get_ok va_s0 /\
Vale.AES.AES_BE_s.is_aes_key_word AES_256 key /\ FStar.Seq.Base.length #quad32 round_keys == 15
/\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key /\ va_get_vec 0 va_s0 ==
input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128
keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128
(va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 15 (va_get_mem_layout va_s0)
Secret /\ (forall (i:nat) . i < 15 ==> Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) ==
FStar.Seq.Base.index #quad32 round_keys i)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key input /\ va_state_eq va_sM
(va_update_vec 2 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_ok va_sM
va_s0))))))
[@ va_qattr]
let va_wp_AES256EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_256 key /\ FStar.Seq.Base.length
#quad32 round_keys == 15 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key
/\ va_get_vec 0 va_s0 == input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr
#Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0)
keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 15 ==>
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i
(va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i) /\ (forall
(va_x_r10:nat64) (va_x_v0:quad32) (va_x_v2:quad32) . let va_sM = va_upd_vec 2 va_x_v2
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0)) in va_get_ok va_sM /\ va_get_vec 0 va_sM
== Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key input ==> va_k va_sM (())))
val va_wpProof_AES256EncryptBlock : input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) ->
keys_buffer:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_AES256EncryptBlock input key round_keys keys_buffer va_s0
va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AES256EncryptBlock ()) ([va_Mod_vec 2;
va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_AES256EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) : (va_quickCode unit (va_code_AES256EncryptBlock ())) =
(va_QProc (va_code_AES256EncryptBlock ()) ([va_Mod_vec 2; va_Mod_vec 0; va_Mod_reg 10])
(va_wp_AES256EncryptBlock input key round_keys keys_buffer) (va_wpProof_AES256EncryptBlock
input key round_keys keys_buffer))
//--
//-- AES256EncryptBlock_6way
val va_code_AES256EncryptBlock_6way : va_dummy:unit -> Tot va_code
val va_codegen_success_AES256EncryptBlock_6way : va_dummy:unit -> Tot va_pbool
val va_lemma_AES256EncryptBlock_6way : va_b0:va_code -> va_s0:va_state -> in1:quad32 -> in2:quad32
-> in3:quad32 -> in4:quad32 -> in5:quad32 -> in6:quad32 -> key:(seq nat32) -> round_keys:(seq
quad32) -> keys_buffer:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AES256EncryptBlock_6way ()) va_s0 /\ va_get_ok va_s0
/\ Vale.AES.AES_BE_s.is_aes_key_word AES_256 key /\ FStar.Seq.Base.length #quad32 round_keys ==
15 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key /\ va_get_vec 0 va_s0
== in1 /\ va_get_vec 1 va_s0 == in2 /\ va_get_vec 2 va_s0 == in3 /\ va_get_vec 3 va_s0 == in4
/\ va_get_vec 4 va_s0 == in5 /\ va_get_vec 5 va_s0 == in6 /\ va_get_reg 4 va_s0 ==
Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0
va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0)
keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 15 ==>
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i
(va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in1 /\ va_get_vec 1 va_sM
== Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in2 /\ va_get_vec 2 va_sM ==
Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in3 /\ va_get_vec 3 va_sM ==
Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in4 /\ va_get_vec 4 va_sM ==
Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in5 /\ va_get_vec 5 va_sM ==
Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in6 /\ va_state_eq va_sM (va_update_vec 6 va_sM
(va_update_vec 5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM
(va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_ok va_sM
va_s0))))))))))) | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"Vale.AES.AES256_helpers_BE.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.AES256.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
in1: Vale.PPC64LE.Memory.quad32 ->
in2: Vale.PPC64LE.Memory.quad32 ->
in3: Vale.PPC64LE.Memory.quad32 ->
in4: Vale.PPC64LE.Memory.quad32 ->
in5: Vale.PPC64LE.Memory.quad32 ->
in6: Vale.PPC64LE.Memory.quad32 ->
key: FStar.Seq.Base.seq Vale.PPC64LE.Memory.nat32 ->
round_keys: FStar.Seq.Base.seq Vale.PPC64LE.Memory.quad32 ->
keys_buffer: Vale.PPC64LE.Memory.buffer128 ->
va_s0: Vale.PPC64LE.Decls.va_state ->
va_k: (_: Vale.PPC64LE.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.PPC64LE.Memory.quad32",
"FStar.Seq.Base.seq",
"Vale.PPC64LE.Memory.nat32",
"Vale.PPC64LE.Memory.buffer128",
"Vale.PPC64LE.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.PPC64LE.Decls.va_get_ok",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Vale.AES.AES_common_s.AES_256",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Vale.AES.AES_BE_s.key_to_round_keys_word",
"Vale.Def.Types_s.quad32",
"Vale.PPC64LE.Decls.va_get_vec",
"Vale.PPC64LE.Decls.va_get_reg",
"Vale.PPC64LE.Memory.buffer_addr",
"Vale.PPC64LE.Memory.vuint128",
"Vale.PPC64LE.Decls.va_get_mem_heaplet",
"Vale.PPC64LE.Decls.validSrcAddrs128",
"Vale.PPC64LE.Decls.va_get_mem_layout",
"Vale.Arch.HeapTypes_s.Secret",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.op_LessThan",
"Vale.Def.Types_s.reverse_bytes_quad32",
"Vale.PPC64LE.Decls.buffer128_read",
"FStar.Seq.Base.index",
"Vale.PPC64LE.Memory.nat64",
"Vale.AES.AES_BE_s.aes_encrypt_word",
"Vale.PPC64LE.Machine_s.state",
"Vale.PPC64LE.Decls.va_upd_vec",
"Vale.PPC64LE.Decls.va_upd_reg"
] | [] | false | false | false | true | true | let va_wp_AES256EncryptBlock_6way
(in1 in2 in3 in4 in5 in6: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_256 key /\
FStar.Seq.Base.length #quad32 round_keys == 15 /\
round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key /\ va_get_vec 0 va_s0 == in1 /\
va_get_vec 1 va_s0 == in2 /\ va_get_vec 2 va_s0 == in3 /\ va_get_vec 3 va_s0 == in4 /\
va_get_vec 4 va_s0 == in5 /\ va_get_vec 5 va_s0 == in6 /\
va_get_reg 4 va_s0 ==
Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128
keys_buffer
(va_get_mem_heaplet 0 va_s0) /\
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg 4 va_s0)
keys_buffer
15
(va_get_mem_layout va_s0)
Secret /\
(forall (i: nat).
i < 15 ==>
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer
i
(va_get_mem_heaplet 0 va_s0)) ==
FStar.Seq.Base.index #quad32 round_keys i) /\
(forall (va_x_r10: nat64)
(va_x_v0: quad32)
(va_x_v1: quad32)
(va_x_v2: quad32)
(va_x_v3: quad32)
(va_x_v4: quad32)
(va_x_v5: quad32)
(va_x_v6: quad32).
let va_sM =
va_upd_vec 6
va_x_v6
(va_upd_vec 5
va_x_v5
(va_upd_vec 4
va_x_v4
(va_upd_vec 3
va_x_v3
(va_upd_vec 2
va_x_v2
(va_upd_vec 1
va_x_v1
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0)))))))
in
va_get_ok va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in1 /\
va_get_vec 1 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in2 /\
va_get_vec 2 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in3 /\
va_get_vec 3 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in4 /\
va_get_vec 4 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in5 /\
va_get_vec 5 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in6 ==>
va_k va_sM (()))) | false |
Vale.AES.PPC64LE.AES256.fsti | Vale.AES.PPC64LE.AES256.va_wp_KeyExpansion256Stdcall | val va_wp_KeyExpansion256Stdcall
(input_key_b output_key_expansion_b: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_KeyExpansion256Stdcall
(input_key_b output_key_expansion_b: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_KeyExpansion256Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128)
(va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_s0) (va_get_reg 4 va_s0) input_key_b 2 (va_get_mem_layout va_s0) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0)
output_key_expansion_b 15 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap)
(va_x_heap1:vale_heap) (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32)
(va_x_v3:quad32) (va_x_v4:quad32) (va_x_v5:quad32) . let va_sM = va_upd_vec 5 va_x_v5
(va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem
va_x_mem va_s0)))))))) in va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers_BE.make_AES256_key
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0
(va_get_mem_heaplet 0 va_s0))) (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0))) in
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM)
input_key_b 2 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 15 (va_get_mem_layout
va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b
(va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) .
{:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1
va_sM)))}j <= 14 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index
#Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key) j)) ==> va_k
va_sM (()))) | {
"file_name": "obj/Vale.AES.PPC64LE.AES256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 91,
"start_col": 0,
"start_line": 59
} | module Vale.AES.PPC64LE.AES256
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.Arch.Types
open Vale.AES.AES256_helpers_BE
#reset-options "--z3rlimit 20"
//-- KeyExpansion256Stdcall
val va_code_KeyExpansion256Stdcall : va_dummy:unit -> Tot va_code
val va_codegen_success_KeyExpansion256Stdcall : va_dummy:unit -> Tot va_pbool
val va_lemma_KeyExpansion256Stdcall : va_b0:va_code -> va_s0:va_state -> input_key_b:buffer128 ->
output_key_expansion_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_KeyExpansion256Stdcall ()) va_s0 /\ va_get_ok va_s0 /\
(let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_s0) (va_get_reg 4 va_s0) input_key_b 2 (va_get_mem_layout va_s0) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0)
output_key_expansion_b 15 (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 /\
(let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_sM) (va_get_reg 4 va_sM) input_key_b 2 (va_get_mem_layout va_sM) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM)
output_key_expansion_b 15 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers_BE.make_AES256_key
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0
(va_get_mem_heaplet 0 va_s0))) (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0))) in
Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(reverse_bytes_quad32
(buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}j <= 14 ==>
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b
j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key) j)) /\ va_state_eq va_sM (va_update_vec
5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1
va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_mem_heaplet 1 va_sM
(va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))))) | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"Vale.AES.AES256_helpers_BE.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.AES256.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
input_key_b: Vale.PPC64LE.Memory.buffer128 ->
output_key_expansion_b: Vale.PPC64LE.Memory.buffer128 ->
va_s0: Vale.PPC64LE.Decls.va_state ->
va_k: (_: Vale.PPC64LE.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.PPC64LE.Memory.buffer128",
"Vale.PPC64LE.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.PPC64LE.Decls.va_get_ok",
"Vale.PPC64LE.Decls.validSrcAddrs128",
"Vale.PPC64LE.Decls.va_get_mem_heaplet",
"Vale.PPC64LE.Decls.va_get_reg",
"Vale.PPC64LE.Decls.va_get_mem_layout",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.PPC64LE.Decls.validDstAddrs128",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat32",
"Vale.AES.AES256_helpers_BE.make_AES256_key",
"Vale.Def.Types_s.reverse_bytes_quad32",
"Vale.PPC64LE.Decls.buffer128_read",
"Prims.l_Forall",
"Vale.PPC64LE.InsBasic.vale_heap",
"Vale.PPC64LE.Memory.nat64",
"Vale.PPC64LE.Memory.quad32",
"Prims.l_imp",
"Vale.PPC64LE.Decls.modifies_buffer128",
"Prims.nat",
"Prims.op_LessThanOrEqual",
"Prims.eq2",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.index",
"Vale.AES.AES_BE_s.key_to_round_keys_word",
"Vale.AES.AES_common_s.AES_256",
"Vale.PPC64LE.Machine_s.state",
"Vale.PPC64LE.Decls.va_upd_vec",
"Vale.PPC64LE.Decls.va_upd_reg",
"Vale.PPC64LE.Decls.va_upd_mem_heaplet",
"Vale.PPC64LE.Decls.va_upd_mem"
] | [] | false | false | false | true | true | let va_wp_KeyExpansion256Stdcall
(input_key_b output_key_expansion_b: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\
(let key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read
input_key_b
0
(va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b
1
(va_get_mem_heaplet 0 va_s0)))
in
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg 4 va_s0)
input_key_b
2
(va_get_mem_layout va_s0)
Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0)
(va_get_reg 3 va_s0)
output_key_expansion_b
15
(va_get_mem_layout va_s0)
Secret) /\
(forall (va_x_mem: vale_heap)
(va_x_heap1: vale_heap)
(va_x_r10: nat64)
(va_x_v0: quad32)
(va_x_v1: quad32)
(va_x_v2: quad32)
(va_x_v3: quad32)
(va_x_v4: quad32)
(va_x_v5: quad32).
let va_sM =
va_upd_vec 5
va_x_v5
(va_upd_vec 4
va_x_v4
(va_upd_vec 3
va_x_v3
(va_upd_vec 2
va_x_v2
(va_upd_vec 1
va_x_v1
(va_upd_vec 0
va_x_v0
(va_upd_reg 10
va_x_r10
(va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem va_x_mem va_s0)))))))
)
in
va_get_ok va_sM /\
(let key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read
input_key_b
0
(va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b
1
(va_get_mem_heaplet 0 va_s0)))
in
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM)
(va_get_reg 4 va_sM)
input_key_b
2
(va_get_mem_layout va_sM)
Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM)
(va_get_reg 3 va_sM)
output_key_expansion_b
15
(va_get_mem_layout va_sM)
Secret) /\
(let key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read
input_key_b
0
(va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b
1
(va_get_mem_heaplet 0 va_s0)))
in
Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b
(va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\
(forall (j: nat).
{:pattern
(reverse_bytes_quad32 (buffer128_read output_key_expansion_b
j
(va_get_mem_heaplet 1 va_sM)))}
j <= 14 ==>
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b
j
(va_get_mem_heaplet 1 va_sM)) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key)
j)) ==>
va_k va_sM (()))) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.tele_star_vprop_correct_ret | val tele_star_vprop_correct_ret (v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot
(vprop_rewrite (((tele_p (TRet v' p')) `star` v) `star` (pure p))
(tele_p (tele_star_vprop (TRet v' p') v p))) | val tele_star_vprop_correct_ret (v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot
(vprop_rewrite (((tele_p (TRet v' p')) `star` v) `star` (pure p))
(tele_p (tele_star_vprop (TRet v' p') v p))) | let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 60,
"end_line": 222,
"start_col": 0,
"start_line": 214
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | v': Steel.Effect.Common.vprop -> p': Prims.prop -> v: Steel.Effect.Common.vprop -> p: Prims.prop
-> Steel.ST.GenElim1.vprop_rewrite (Steel.Effect.Common.star (Steel.Effect.Common.star (Steel.ST.GenElim1.tele_p
(Steel.ST.GenElim1.Base.TRet v' p'))
v)
(Steel.ST.Util.pure p))
(Steel.ST.GenElim1.tele_p (Steel.ST.GenElim1.Base.tele_star_vprop (Steel.ST.GenElim1.Base.TRet
v' p')
v
p)) | Prims.Tot | [
"total"
] | [] | [
"Steel.Effect.Common.vprop",
"Prims.prop",
"Steel.Memory.inames",
"Steel.ST.Util.rewrite",
"Steel.Effect.Common.star",
"Steel.ST.Util.pure",
"Prims.l_and",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.GenElim1.Base.tele_star_vprop",
"Steel.ST.GenElim1.Base.TRet",
"Prims.unit",
"Steel.ST.Util.intro_pure",
"Steel.ST.Util.elim_pure",
"Steel.ST.GenElim1.vprop_rewrite"
] | [] | false | false | false | false | false | let tele_star_vprop_correct_ret (v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot
(vprop_rewrite (((tele_p (TRet v' p')) `star` v) `star` (pure p))
(tele_p (tele_star_vprop (TRet v' p') v p))) =
| fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` (pure p'));
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` (pure (p /\ p'))) (tele_p _) | false |
Vale.AES.PPC64LE.AES256.fsti | Vale.AES.PPC64LE.AES256.va_wp_AES256EncryptBlock | val va_wp_AES256EncryptBlock
(input: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_AES256EncryptBlock
(input: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_AES256EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_256 key /\ FStar.Seq.Base.length
#quad32 round_keys == 15 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key
/\ va_get_vec 0 va_s0 == input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr
#Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0)
keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 15 ==>
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i
(va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i) /\ (forall
(va_x_r10:nat64) (va_x_v0:quad32) (va_x_v2:quad32) . let va_sM = va_upd_vec 2 va_x_v2
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0)) in va_get_ok va_sM /\ va_get_vec 0 va_sM
== Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key input ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.AES.PPC64LE.AES256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 81,
"end_line": 144,
"start_col": 0,
"start_line": 132
} | module Vale.AES.PPC64LE.AES256
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.Arch.Types
open Vale.AES.AES256_helpers_BE
#reset-options "--z3rlimit 20"
//-- KeyExpansion256Stdcall
val va_code_KeyExpansion256Stdcall : va_dummy:unit -> Tot va_code
val va_codegen_success_KeyExpansion256Stdcall : va_dummy:unit -> Tot va_pbool
val va_lemma_KeyExpansion256Stdcall : va_b0:va_code -> va_s0:va_state -> input_key_b:buffer128 ->
output_key_expansion_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_KeyExpansion256Stdcall ()) va_s0 /\ va_get_ok va_s0 /\
(let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_s0) (va_get_reg 4 va_s0) input_key_b 2 (va_get_mem_layout va_s0) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0)
output_key_expansion_b 15 (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 /\
(let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_sM) (va_get_reg 4 va_sM) input_key_b 2 (va_get_mem_layout va_sM) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM)
output_key_expansion_b 15 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers_BE.make_AES256_key
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0
(va_get_mem_heaplet 0 va_s0))) (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0))) in
Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(reverse_bytes_quad32
(buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}j <= 14 ==>
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b
j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key) j)) /\ va_state_eq va_sM (va_update_vec
5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1
va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_mem_heaplet 1 va_sM
(va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))
[@ va_qattr]
let va_wp_KeyExpansion256Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128)
(va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_s0) (va_get_reg 4 va_s0) input_key_b 2 (va_get_mem_layout va_s0) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0)
output_key_expansion_b 15 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap)
(va_x_heap1:vale_heap) (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32)
(va_x_v3:quad32) (va_x_v4:quad32) (va_x_v5:quad32) . let va_sM = va_upd_vec 5 va_x_v5
(va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem
va_x_mem va_s0)))))))) in va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers_BE.make_AES256_key
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0
(va_get_mem_heaplet 0 va_s0))) (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0))) in
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM)
input_key_b 2 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 15 (va_get_mem_layout
va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b
(va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) .
{:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1
va_sM)))}j <= 14 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index
#Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key) j)) ==> va_k
va_sM (())))
val va_wpProof_KeyExpansion256Stdcall : input_key_b:buffer128 -> output_key_expansion_b:buffer128
-> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_KeyExpansion256Stdcall input_key_b output_key_expansion_b
va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion256Stdcall ())
([va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0;
va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_KeyExpansion256Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128) :
(va_quickCode unit (va_code_KeyExpansion256Stdcall ())) =
(va_QProc (va_code_KeyExpansion256Stdcall ()) ([va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3;
va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem])
(va_wp_KeyExpansion256Stdcall input_key_b output_key_expansion_b)
(va_wpProof_KeyExpansion256Stdcall input_key_b output_key_expansion_b))
//--
//-- AES256EncryptBlock
val va_code_AES256EncryptBlock : va_dummy:unit -> Tot va_code
val va_codegen_success_AES256EncryptBlock : va_dummy:unit -> Tot va_pbool
val va_lemma_AES256EncryptBlock : va_b0:va_code -> va_s0:va_state -> input:quad32 -> key:(seq
nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AES256EncryptBlock ()) va_s0 /\ va_get_ok va_s0 /\
Vale.AES.AES_BE_s.is_aes_key_word AES_256 key /\ FStar.Seq.Base.length #quad32 round_keys == 15
/\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key /\ va_get_vec 0 va_s0 ==
input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128
keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128
(va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 15 (va_get_mem_layout va_s0)
Secret /\ (forall (i:nat) . i < 15 ==> Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) ==
FStar.Seq.Base.index #quad32 round_keys i)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key input /\ va_state_eq va_sM
(va_update_vec 2 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_ok va_sM
va_s0)))))) | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"Vale.AES.AES256_helpers_BE.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.AES256.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
input: Vale.PPC64LE.Memory.quad32 ->
key: FStar.Seq.Base.seq Vale.PPC64LE.Memory.nat32 ->
round_keys: FStar.Seq.Base.seq Vale.PPC64LE.Memory.quad32 ->
keys_buffer: Vale.PPC64LE.Memory.buffer128 ->
va_s0: Vale.PPC64LE.Decls.va_state ->
va_k: (_: Vale.PPC64LE.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Vale.PPC64LE.Memory.quad32",
"FStar.Seq.Base.seq",
"Vale.PPC64LE.Memory.nat32",
"Vale.PPC64LE.Memory.buffer128",
"Vale.PPC64LE.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.PPC64LE.Decls.va_get_ok",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Vale.AES.AES_common_s.AES_256",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Vale.AES.AES_BE_s.key_to_round_keys_word",
"Vale.Def.Types_s.quad32",
"Vale.PPC64LE.Decls.va_get_vec",
"Vale.PPC64LE.Decls.va_get_reg",
"Vale.PPC64LE.Memory.buffer_addr",
"Vale.PPC64LE.Memory.vuint128",
"Vale.PPC64LE.Decls.va_get_mem_heaplet",
"Vale.PPC64LE.Decls.validSrcAddrs128",
"Vale.PPC64LE.Decls.va_get_mem_layout",
"Vale.Arch.HeapTypes_s.Secret",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.op_LessThan",
"Vale.Def.Types_s.reverse_bytes_quad32",
"Vale.PPC64LE.Decls.buffer128_read",
"FStar.Seq.Base.index",
"Vale.PPC64LE.Memory.nat64",
"Vale.AES.AES_BE_s.aes_encrypt_word",
"Vale.PPC64LE.Machine_s.state",
"Vale.PPC64LE.Decls.va_upd_vec",
"Vale.PPC64LE.Decls.va_upd_reg"
] | [] | false | false | false | true | true | let va_wp_AES256EncryptBlock
(input: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_256 key /\
FStar.Seq.Base.length #quad32 round_keys == 15 /\
round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key /\ va_get_vec 0 va_s0 == input /\
va_get_reg 4 va_s0 ==
Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128
keys_buffer
(va_get_mem_heaplet 0 va_s0) /\
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg 4 va_s0)
keys_buffer
15
(va_get_mem_layout va_s0)
Secret /\
(forall (i: nat).
i < 15 ==>
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer
i
(va_get_mem_heaplet 0 va_s0)) ==
FStar.Seq.Base.index #quad32 round_keys i) /\
(forall (va_x_r10: nat64) (va_x_v0: quad32) (va_x_v2: quad32).
let va_sM = va_upd_vec 2 va_x_v2 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0)) in
va_get_ok va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key input ==>
va_k va_sM (()))) | false |
Vale.AES.PPC64LE.AES256.fsti | Vale.AES.PPC64LE.AES256.va_quick_KeyExpansion256Stdcall | val va_quick_KeyExpansion256Stdcall (input_key_b output_key_expansion_b: buffer128)
: (va_quickCode unit (va_code_KeyExpansion256Stdcall ())) | val va_quick_KeyExpansion256Stdcall (input_key_b output_key_expansion_b: buffer128)
: (va_quickCode unit (va_code_KeyExpansion256Stdcall ())) | let va_quick_KeyExpansion256Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128) :
(va_quickCode unit (va_code_KeyExpansion256Stdcall ())) =
(va_QProc (va_code_KeyExpansion256Stdcall ()) ([va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3;
va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem])
(va_wp_KeyExpansion256Stdcall input_key_b output_key_expansion_b)
(va_wpProof_KeyExpansion256Stdcall input_key_b output_key_expansion_b)) | {
"file_name": "obj/Vale.AES.PPC64LE.AES256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 75,
"end_line": 107,
"start_col": 0,
"start_line": 102
} | module Vale.AES.PPC64LE.AES256
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.Arch.Types
open Vale.AES.AES256_helpers_BE
#reset-options "--z3rlimit 20"
//-- KeyExpansion256Stdcall
val va_code_KeyExpansion256Stdcall : va_dummy:unit -> Tot va_code
val va_codegen_success_KeyExpansion256Stdcall : va_dummy:unit -> Tot va_pbool
val va_lemma_KeyExpansion256Stdcall : va_b0:va_code -> va_s0:va_state -> input_key_b:buffer128 ->
output_key_expansion_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_KeyExpansion256Stdcall ()) va_s0 /\ va_get_ok va_s0 /\
(let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_s0) (va_get_reg 4 va_s0) input_key_b 2 (va_get_mem_layout va_s0) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0)
output_key_expansion_b 15 (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 /\
(let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_sM) (va_get_reg 4 va_sM) input_key_b 2 (va_get_mem_layout va_sM) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM)
output_key_expansion_b 15 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers_BE.make_AES256_key
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0
(va_get_mem_heaplet 0 va_s0))) (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0))) in
Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(reverse_bytes_quad32
(buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}j <= 14 ==>
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b
j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key) j)) /\ va_state_eq va_sM (va_update_vec
5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1
va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_mem_heaplet 1 va_sM
(va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))
[@ va_qattr]
let va_wp_KeyExpansion256Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128)
(va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_s0) (va_get_reg 4 va_s0) input_key_b 2 (va_get_mem_layout va_s0) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0)
output_key_expansion_b 15 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap)
(va_x_heap1:vale_heap) (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32)
(va_x_v3:quad32) (va_x_v4:quad32) (va_x_v5:quad32) . let va_sM = va_upd_vec 5 va_x_v5
(va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem
va_x_mem va_s0)))))))) in va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers_BE.make_AES256_key
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0
(va_get_mem_heaplet 0 va_s0))) (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0))) in
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM)
input_key_b 2 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 15 (va_get_mem_layout
va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b
(va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) .
{:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1
va_sM)))}j <= 14 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index
#Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key) j)) ==> va_k
va_sM (())))
val va_wpProof_KeyExpansion256Stdcall : input_key_b:buffer128 -> output_key_expansion_b:buffer128
-> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_KeyExpansion256Stdcall input_key_b output_key_expansion_b
va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion256Stdcall ())
([va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0;
va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g)))) | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"Vale.AES.AES256_helpers_BE.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.AES256.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | input_key_b: Vale.PPC64LE.Memory.buffer128 -> output_key_expansion_b: Vale.PPC64LE.Memory.buffer128
-> Vale.PPC64LE.QuickCode.va_quickCode Prims.unit
(Vale.AES.PPC64LE.AES256.va_code_KeyExpansion256Stdcall ()) | Prims.Tot | [
"total"
] | [] | [
"Vale.PPC64LE.Memory.buffer128",
"Vale.PPC64LE.QuickCode.va_QProc",
"Prims.unit",
"Vale.AES.PPC64LE.AES256.va_code_KeyExpansion256Stdcall",
"Prims.Cons",
"Vale.PPC64LE.QuickCode.mod_t",
"Vale.PPC64LE.QuickCode.va_Mod_vec",
"Vale.PPC64LE.QuickCode.va_Mod_reg",
"Vale.PPC64LE.QuickCode.va_Mod_mem_heaplet",
"Vale.PPC64LE.QuickCode.va_Mod_mem",
"Prims.Nil",
"Vale.AES.PPC64LE.AES256.va_wp_KeyExpansion256Stdcall",
"Vale.AES.PPC64LE.AES256.va_wpProof_KeyExpansion256Stdcall",
"Vale.PPC64LE.QuickCode.va_quickCode"
] | [] | false | false | false | false | false | let va_quick_KeyExpansion256Stdcall (input_key_b output_key_expansion_b: buffer128)
: (va_quickCode unit (va_code_KeyExpansion256Stdcall ())) =
| (va_QProc (va_code_KeyExpansion256Stdcall ())
([
va_Mod_vec 5;
va_Mod_vec 4;
va_Mod_vec 3;
va_Mod_vec 2;
va_Mod_vec 1;
va_Mod_vec 0;
va_Mod_reg 10;
va_Mod_mem_heaplet 1;
va_Mod_mem
])
(va_wp_KeyExpansion256Stdcall input_key_b output_key_expansion_b)
(va_wpProof_KeyExpansion256Stdcall input_key_b output_key_expansion_b)) | false |
Vale.AES.PPC64LE.AES256.fsti | Vale.AES.PPC64LE.AES256.va_quick_AES256EncryptBlock | val va_quick_AES256EncryptBlock
(input: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
: (va_quickCode unit (va_code_AES256EncryptBlock ())) | val va_quick_AES256EncryptBlock
(input: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
: (va_quickCode unit (va_code_AES256EncryptBlock ())) | let va_quick_AES256EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) : (va_quickCode unit (va_code_AES256EncryptBlock ())) =
(va_QProc (va_code_AES256EncryptBlock ()) ([va_Mod_vec 2; va_Mod_vec 0; va_Mod_reg 10])
(va_wp_AES256EncryptBlock input key round_keys keys_buffer) (va_wpProof_AES256EncryptBlock
input key round_keys keys_buffer)) | {
"file_name": "obj/Vale.AES.PPC64LE.AES256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 158,
"start_col": 0,
"start_line": 154
} | module Vale.AES.PPC64LE.AES256
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.Arch.Types
open Vale.AES.AES256_helpers_BE
#reset-options "--z3rlimit 20"
//-- KeyExpansion256Stdcall
val va_code_KeyExpansion256Stdcall : va_dummy:unit -> Tot va_code
val va_codegen_success_KeyExpansion256Stdcall : va_dummy:unit -> Tot va_pbool
val va_lemma_KeyExpansion256Stdcall : va_b0:va_code -> va_s0:va_state -> input_key_b:buffer128 ->
output_key_expansion_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_KeyExpansion256Stdcall ()) va_s0 /\ va_get_ok va_s0 /\
(let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_s0) (va_get_reg 4 va_s0) input_key_b 2 (va_get_mem_layout va_s0) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0)
output_key_expansion_b 15 (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 /\
(let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_sM) (va_get_reg 4 va_sM) input_key_b 2 (va_get_mem_layout va_sM) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM)
output_key_expansion_b 15 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers_BE.make_AES256_key
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0
(va_get_mem_heaplet 0 va_s0))) (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0))) in
Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(reverse_bytes_quad32
(buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}j <= 14 ==>
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b
j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key) j)) /\ va_state_eq va_sM (va_update_vec
5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1
va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_mem_heaplet 1 va_sM
(va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))
[@ va_qattr]
let va_wp_KeyExpansion256Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128)
(va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_s0) (va_get_reg 4 va_s0) input_key_b 2 (va_get_mem_layout va_s0) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0)
output_key_expansion_b 15 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap)
(va_x_heap1:vale_heap) (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32)
(va_x_v3:quad32) (va_x_v4:quad32) (va_x_v5:quad32) . let va_sM = va_upd_vec 5 va_x_v5
(va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem
va_x_mem va_s0)))))))) in va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers_BE.make_AES256_key
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0
(va_get_mem_heaplet 0 va_s0))) (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0))) in
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM)
input_key_b 2 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 15 (va_get_mem_layout
va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b
(va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) .
{:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1
va_sM)))}j <= 14 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index
#Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key) j)) ==> va_k
va_sM (())))
val va_wpProof_KeyExpansion256Stdcall : input_key_b:buffer128 -> output_key_expansion_b:buffer128
-> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_KeyExpansion256Stdcall input_key_b output_key_expansion_b
va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion256Stdcall ())
([va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0;
va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_KeyExpansion256Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128) :
(va_quickCode unit (va_code_KeyExpansion256Stdcall ())) =
(va_QProc (va_code_KeyExpansion256Stdcall ()) ([va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3;
va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem])
(va_wp_KeyExpansion256Stdcall input_key_b output_key_expansion_b)
(va_wpProof_KeyExpansion256Stdcall input_key_b output_key_expansion_b))
//--
//-- AES256EncryptBlock
val va_code_AES256EncryptBlock : va_dummy:unit -> Tot va_code
val va_codegen_success_AES256EncryptBlock : va_dummy:unit -> Tot va_pbool
val va_lemma_AES256EncryptBlock : va_b0:va_code -> va_s0:va_state -> input:quad32 -> key:(seq
nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AES256EncryptBlock ()) va_s0 /\ va_get_ok va_s0 /\
Vale.AES.AES_BE_s.is_aes_key_word AES_256 key /\ FStar.Seq.Base.length #quad32 round_keys == 15
/\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key /\ va_get_vec 0 va_s0 ==
input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128
keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128
(va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 15 (va_get_mem_layout va_s0)
Secret /\ (forall (i:nat) . i < 15 ==> Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) ==
FStar.Seq.Base.index #quad32 round_keys i)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key input /\ va_state_eq va_sM
(va_update_vec 2 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_ok va_sM
va_s0))))))
[@ va_qattr]
let va_wp_AES256EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_256 key /\ FStar.Seq.Base.length
#quad32 round_keys == 15 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key
/\ va_get_vec 0 va_s0 == input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr
#Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0)
keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 15 ==>
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i
(va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i) /\ (forall
(va_x_r10:nat64) (va_x_v0:quad32) (va_x_v2:quad32) . let va_sM = va_upd_vec 2 va_x_v2
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0)) in va_get_ok va_sM /\ va_get_vec 0 va_sM
== Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key input ==> va_k va_sM (())))
val va_wpProof_AES256EncryptBlock : input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) ->
keys_buffer:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_AES256EncryptBlock input key round_keys keys_buffer va_s0
va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AES256EncryptBlock ()) ([va_Mod_vec 2;
va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g)))) | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"Vale.AES.AES256_helpers_BE.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.AES256.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
input: Vale.PPC64LE.Memory.quad32 ->
key: FStar.Seq.Base.seq Vale.PPC64LE.Memory.nat32 ->
round_keys: FStar.Seq.Base.seq Vale.PPC64LE.Memory.quad32 ->
keys_buffer: Vale.PPC64LE.Memory.buffer128
-> Vale.PPC64LE.QuickCode.va_quickCode Prims.unit
(Vale.AES.PPC64LE.AES256.va_code_AES256EncryptBlock ()) | Prims.Tot | [
"total"
] | [] | [
"Vale.PPC64LE.Memory.quad32",
"FStar.Seq.Base.seq",
"Vale.PPC64LE.Memory.nat32",
"Vale.PPC64LE.Memory.buffer128",
"Vale.PPC64LE.QuickCode.va_QProc",
"Prims.unit",
"Vale.AES.PPC64LE.AES256.va_code_AES256EncryptBlock",
"Prims.Cons",
"Vale.PPC64LE.QuickCode.mod_t",
"Vale.PPC64LE.QuickCode.va_Mod_vec",
"Vale.PPC64LE.QuickCode.va_Mod_reg",
"Prims.Nil",
"Vale.AES.PPC64LE.AES256.va_wp_AES256EncryptBlock",
"Vale.AES.PPC64LE.AES256.va_wpProof_AES256EncryptBlock",
"Vale.PPC64LE.QuickCode.va_quickCode"
] | [] | false | false | false | false | false | let va_quick_AES256EncryptBlock
(input: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
: (va_quickCode unit (va_code_AES256EncryptBlock ())) =
| (va_QProc (va_code_AES256EncryptBlock ())
([va_Mod_vec 2; va_Mod_vec 0; va_Mod_reg 10])
(va_wp_AES256EncryptBlock input key round_keys keys_buffer)
(va_wpProof_AES256EncryptBlock input key round_keys keys_buffer)) | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.map_sort_merge_correct | val map_sort_merge_correct
(#t1 #t2: Type)
(key_order: (t1 -> t1 -> bool))
(key_compare: (t1 -> t1 -> int))
(accu l1 l2: list (t1 & t2))
: Lemma
(requires
((forall x. key_order x x == false) /\
(forall x y z. (key_order x y /\ key_order y z) ==> key_order x z) /\
(forall x y. key_order x y == (key_compare x y < 0)) /\
(forall x y. key_compare x y == 0 <==> x == y) /\
(forall x y. (key_compare x y < 0 <==> key_compare y x > 0)) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l1) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l2)))
(ensures
(let sorted, res = map_sort_merge key_compare accu l1 l2 in
(forall x.
List.Tot.memP x res <==>
List.Tot.memP x (accu `List.Tot.append` (l1 `List.Tot.append` l2))) /\
(List.Tot.no_repeats_p (List.Tot.map fst res) <==>
List.Tot.no_repeats_p (List.Tot.map fst
(accu `List.Tot.append` (l1 `List.Tot.append` l2)))) /\
(if sorted
then List.Tot.sorted (map_entry_order key_order _) res
else ~(List.Tot.no_repeats_p (List.Tot.map fst res)))))
(decreases (List.Tot.length l1 + List.Tot.length l2)) | val map_sort_merge_correct
(#t1 #t2: Type)
(key_order: (t1 -> t1 -> bool))
(key_compare: (t1 -> t1 -> int))
(accu l1 l2: list (t1 & t2))
: Lemma
(requires
((forall x. key_order x x == false) /\
(forall x y z. (key_order x y /\ key_order y z) ==> key_order x z) /\
(forall x y. key_order x y == (key_compare x y < 0)) /\
(forall x y. key_compare x y == 0 <==> x == y) /\
(forall x y. (key_compare x y < 0 <==> key_compare y x > 0)) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l1) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l2)))
(ensures
(let sorted, res = map_sort_merge key_compare accu l1 l2 in
(forall x.
List.Tot.memP x res <==>
List.Tot.memP x (accu `List.Tot.append` (l1 `List.Tot.append` l2))) /\
(List.Tot.no_repeats_p (List.Tot.map fst res) <==>
List.Tot.no_repeats_p (List.Tot.map fst
(accu `List.Tot.append` (l1 `List.Tot.append` l2)))) /\
(if sorted
then List.Tot.sorted (map_entry_order key_order _) res
else ~(List.Tot.no_repeats_p (List.Tot.map fst res)))))
(decreases (List.Tot.length l1 + List.Tot.length l2)) | let rec map_sort_merge_correct
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Lemma
(requires (
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z) /\
(forall x y . key_order x y == (key_compare x y < 0)) /\
(forall x y . key_compare x y == 0 <==> x == y) /\
(forall x y . (key_compare x y < 0 <==> key_compare y x > 0)) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l1) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l2)
))
(ensures (
let (sorted, res) = map_sort_merge key_compare accu l1 l2 in
(forall x . List.Tot.memP x res <==> List.Tot.memP x (accu `List.Tot.append` (l1 `List.Tot.append` l2))) /\
(List.Tot.no_repeats_p (List.Tot.map fst res) <==> List.Tot.no_repeats_p (List.Tot.map fst (accu `List.Tot.append` (l1 `List.Tot.append` l2)))) /\
(if sorted
then List.Tot.sorted (map_entry_order key_order _) res
else ~ (List.Tot.no_repeats_p (List.Tot.map fst res))
)
))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| [], _ -> ()
| _, [] -> List.Tot.append_l_nil l1
| (k1, v1) :: l1', (k2, v2) :: l2' ->
List.Tot.map_append fst l1 l2;
List.Tot.map_append fst accu (l1 `List.Tot.append` l2);
let c = key_compare k1 k2 in
if c = 0
then
List.Tot.no_repeats_p_false_intro (List.Tot.map fst accu) [k1] (List.Tot.map fst l1') (List.Tot.map fst l2')
else if c < 0
then begin
let accu' = accu `List.Tot.append` [(k1, v1)] in
List.Tot.append_assoc accu l1 l2;
List.Tot.append_assoc accu [(k1, v1)] l1';
List.Tot.append_assoc accu' l1' l2;
List.Tot.append_assoc accu [(k1, v1)] l2;
list_sorted_append_elim (map_entry_order key_order _) accu' l1';
list_sorted_append_elim (map_entry_order key_order _) accu l2;
list_sorted_append_chunk_intro (map_entry_order key_order _) accu [(k1, v1)] l2;
map_sort_merge_correct key_order key_compare accu' l1' l2
end
else begin
let accu' = accu `List.Tot.append` [(k2, v2)] in
List.Tot.append_memP_forall l1 l2;
List.Tot.append_memP_forall accu (l1 `List.Tot.append` l2);
List.Tot.append_memP_forall accu [(k2, v2)];
List.Tot.append_memP_forall l1 l2';
List.Tot.append_memP_forall accu' (l1 `List.Tot.append` l2');
List.Tot.no_repeats_p_append_permut (List.Tot.map fst accu) [k2] (List.Tot.map fst l1) [] (List.Tot.map fst l2');
List.Tot.append_assoc (List.Tot.map fst accu) [k2] (List.Tot.map fst l1 `List.Tot.append` List.Tot.map fst l2');
List.Tot.map_append fst accu [(k2, v2)];
List.Tot.map_append fst l1 l2';
List.Tot.map_append fst accu' (l1 `List.Tot.append` l2');
List.Tot.append_assoc accu [(k2, v2)] l2';
list_sorted_append_elim (map_entry_order key_order _) accu' l2';
list_sorted_append_elim (map_entry_order key_order _) accu l1;
list_sorted_append_chunk_intro (map_entry_order key_order _) accu [(k2, v2)] l1;
List.Tot.append_assoc accu [(k2, v2)] l1;
map_sort_merge_correct key_order key_compare accu' l1 l2'
end | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 7,
"end_line": 405,
"start_col": 0,
"start_line": 338
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m'
let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2
let rec list_ghost_assoc_mem_intro
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l)
= let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l'
let rec list_ghost_assoc_no_repeats_mem_elim
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l) /\
List.Tot.memP (k, v) l
))
(ensures (list_ghost_assoc k l == Some v))
(decreases l)
= List.Tot.memP_map_intro fst (k, v) l;
let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then
if FStar.StrongExcludedMiddle.strong_excluded_middle (v == v')
then ()
else List.Tot.memP_map_intro fst (k, v) l'
else list_ghost_assoc_no_repeats_mem_elim k v l'
let list_ghost_assoc_no_repeats_mem
(#tk #tv: Type)
(l: list (tk & tv))
(k: tk)
(v: tv)
: Lemma
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l) ==> (list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l)))
= Classical.move_requires (list_ghost_assoc_no_repeats_mem_elim k v) l;
Classical.move_requires (list_ghost_assoc_mem_intro k v) l
let list_ghost_assoc_no_repeats_equiv'
(#tk #tv: Type)
(l1 l2: list (tk & tv))
(k: tk)
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (list_ghost_assoc k l1 == list_ghost_assoc k l2))
= match list_ghost_assoc k l1 with
| None ->
begin match list_ghost_assoc k l2 with
| None -> ()
| Some v ->
list_ghost_assoc_no_repeats_mem l2 k v;
list_ghost_assoc_no_repeats_mem l1 k v
end
| Some v ->
list_ghost_assoc_no_repeats_mem l1 k v;
list_ghost_assoc_no_repeats_mem l2 k v
let list_ghost_assoc_no_repeats_equiv
(#tk #tv: Type)
(l1 l2: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (forall k . list_ghost_assoc k l1 == list_ghost_assoc k l2))
= Classical.forall_intro (Classical.move_requires (list_ghost_assoc_no_repeats_equiv' l1 l2))
[@@noextract_to "krml"] noextract
let rec map_sort_merge
(#t1 #t2: Type)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Tot (bool & list (t1 & t2))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| (k1, v1) :: l1', (k2, v2) :: l2' ->
begin let c = key_compare k1 k2 in
if c = 0
then (false, accu `List.Tot.append` (l1 `List.Tot.append` l2))
else if c < 0
then map_sort_merge key_compare (accu `List.Tot.append` [(k1, v1)]) l1' l2
else
map_sort_merge key_compare (accu `List.Tot.append` [(k2, v2)]) l1 l2'
// TODO in this case:
// 1. prove that the sort is stable, i.e. that the maps are extensionally equal throughout
// 2. extract and swap the whole prefix of l2 less than the head of l1, rather than just the head of l2
end
| [], _ -> (true, accu `List.Tot.append` l2)
| _, [] -> (true, accu `List.Tot.append` l1)
let rec list_sorted_append_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2: list t)
: Lemma
(requires (List.Tot.sorted order (l1 `List.Tot.append` l2)))
(ensures (
List.Tot.sorted order l1 /\
List.Tot.sorted order l2
))
(decreases l1)
= match l1 with
| [] -> ()
| [_] -> ()
| a :: b :: q ->
list_sorted_append_elim order (b :: q) l2
let rec list_sorted_append_chunk_intro
(#t: Type)
(order: t -> t -> bool)
(l1 l2 l3: list t)
: Lemma
(requires (
List.Tot.sorted order (l1 `List.Tot.append` l2) /\
List.Tot.sorted order (l2 `List.Tot.append` l3) /\
Cons? l2
))
(ensures (
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))
))
(decreases l1)
= match l1 with
| [] -> ()
| [a] -> () // because of List.Tot.sorted (l2 `List.Tot.append` l3) and Cons? l2
| a :: l1' -> list_sorted_append_chunk_intro order l1' l2 l3
let rec list_sorted_order_elim
(#t: Type)
(order: t -> t -> bool)
(l0: list t)
(a1: t)
(l1: list t)
(a2: t)
(l2: list t)
: Lemma
(requires (
(forall x y z . (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l0 `List.Tot.append` (a1 :: (l1 `List.Tot.append` (a2 :: l2))))
))
(ensures (order a1 a2 == true))
(decreases (List.Tot.length l0 + List.Tot.length l1))
= match l0 with
| [] ->
begin match l1 with
| [] -> ()
| a1' :: l1' ->
list_sorted_order_elim order [] a1' l1' a2 l2 // and transitivity
end
| a0 :: l0' ->
list_sorted_order_elim order l0' a1 l1 a2 l2
let rec list_sorted_append_chunk_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2 l3: list t)
: Lemma
(requires (
(forall x y z . (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))
))
(ensures (
List.Tot.sorted order (l1 `List.Tot.append` l3)
))
(decreases l1)
= match l1 with
| [] -> list_sorted_append_elim order l2 l3
| [a] ->
begin match l3 with
| [] -> ()
| b :: q ->
list_sorted_append_elim order l2 l3;
list_sorted_order_elim order [] a l2 b q
end
| _ :: l1' -> list_sorted_append_chunk_elim order l1' l2 l3 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
key_order: (_: t1 -> _: t1 -> Prims.bool) ->
key_compare: (_: t1 -> _: t1 -> Prims.int) ->
accu: Prims.list (t1 * t2) ->
l1: Prims.list (t1 * t2) ->
l2: Prims.list (t1 * t2)
-> FStar.Pervasives.Lemma
(requires
(forall (x: t1). key_order x x == false) /\
(forall (x: t1) (y: t1) (z: t1). key_order x y /\ key_order y z ==> key_order x z) /\
(forall (x: t1) (y: t1). key_order x y == (key_compare x y < 0)) /\
(forall (x: t1) (y: t1). key_compare x y == 0 <==> x == y) /\
(forall (x: t1) (y: t1). key_compare x y < 0 <==> key_compare y x > 0) /\
FStar.List.Tot.Properties.sorted (CBOR.Spec.Type.map_entry_order key_order t2) (accu @ l1) /\
FStar.List.Tot.Properties.sorted (CBOR.Spec.Type.map_entry_order key_order t2) (accu @ l2))
(ensures
(let _ = CBOR.Spec.Map.map_sort_merge key_compare accu l1 l2 in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ sorted res = _ in
(forall (x: (t1 * t2)).
FStar.List.Tot.Base.memP x res <==> FStar.List.Tot.Base.memP x (accu @ l1 @ l2)) /\
(FStar.List.Tot.Base.no_repeats_p (FStar.List.Tot.Base.map FStar.Pervasives.Native.fst
res) <==>
FStar.List.Tot.Base.no_repeats_p (FStar.List.Tot.Base.map FStar.Pervasives.Native.fst
(accu @ l1 @ l2))) /\
(match sorted with
| true ->
FStar.List.Tot.Properties.sorted (CBOR.Spec.Type.map_entry_order key_order t2) res
| _ ->
~(FStar.List.Tot.Base.no_repeats_p (FStar.List.Tot.Base.map FStar.Pervasives.Native.fst
res))))
<:
Type0))
(decreases FStar.List.Tot.Base.length l1 + FStar.List.Tot.Base.length l2) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.bool",
"Prims.int",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"FStar.List.Tot.Properties.append_l_nil",
"Prims.op_Equality",
"FStar.List.Tot.Properties.no_repeats_p_false_intro",
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.fst",
"Prims.Cons",
"Prims.Nil",
"Prims.op_LessThan",
"CBOR.Spec.Map.map_sort_merge_correct",
"Prims.unit",
"CBOR.Spec.Map.list_sorted_append_chunk_intro",
"CBOR.Spec.Type.map_entry_order",
"CBOR.Spec.Map.list_sorted_append_elim",
"FStar.List.Tot.Properties.append_assoc",
"FStar.List.Tot.Base.append",
"FStar.List.Tot.Properties.map_append",
"FStar.List.Tot.Properties.no_repeats_p_append_permut",
"FStar.List.Tot.Properties.append_memP_forall",
"Prims.l_and",
"Prims.l_Forall",
"Prims.eq2",
"Prims.l_imp",
"Prims.b2t",
"Prims.l_iff",
"Prims.op_GreaterThan",
"FStar.List.Tot.Properties.sorted",
"Prims.squash",
"FStar.List.Tot.Base.memP",
"FStar.List.Tot.Base.no_repeats_p",
"Prims.l_not",
"Prims.logical",
"CBOR.Spec.Map.map_sort_merge",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec map_sort_merge_correct
(#t1 #t2: Type)
(key_order: (t1 -> t1 -> bool))
(key_compare: (t1 -> t1 -> int))
(accu l1 l2: list (t1 & t2))
: Lemma
(requires
((forall x. key_order x x == false) /\
(forall x y z. (key_order x y /\ key_order y z) ==> key_order x z) /\
(forall x y. key_order x y == (key_compare x y < 0)) /\
(forall x y. key_compare x y == 0 <==> x == y) /\
(forall x y. (key_compare x y < 0 <==> key_compare y x > 0)) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l1) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l2)))
(ensures
(let sorted, res = map_sort_merge key_compare accu l1 l2 in
(forall x.
List.Tot.memP x res <==>
List.Tot.memP x (accu `List.Tot.append` (l1 `List.Tot.append` l2))) /\
(List.Tot.no_repeats_p (List.Tot.map fst res) <==>
List.Tot.no_repeats_p (List.Tot.map fst
(accu `List.Tot.append` (l1 `List.Tot.append` l2)))) /\
(if sorted
then List.Tot.sorted (map_entry_order key_order _) res
else ~(List.Tot.no_repeats_p (List.Tot.map fst res)))))
(decreases (List.Tot.length l1 + List.Tot.length l2)) =
| match l1, l2 with
| [], _ -> ()
| _, [] -> List.Tot.append_l_nil l1
| (k1, v1) :: l1', (k2, v2) :: l2' ->
List.Tot.map_append fst l1 l2;
List.Tot.map_append fst accu (l1 `List.Tot.append` l2);
let c = key_compare k1 k2 in
if c = 0
then
List.Tot.no_repeats_p_false_intro (List.Tot.map fst accu)
[k1]
(List.Tot.map fst l1')
(List.Tot.map fst l2')
else
if c < 0
then
let accu' = accu `List.Tot.append` [(k1, v1)] in
List.Tot.append_assoc accu l1 l2;
List.Tot.append_assoc accu [(k1, v1)] l1';
List.Tot.append_assoc accu' l1' l2;
List.Tot.append_assoc accu [(k1, v1)] l2;
list_sorted_append_elim (map_entry_order key_order _) accu' l1';
list_sorted_append_elim (map_entry_order key_order _) accu l2;
list_sorted_append_chunk_intro (map_entry_order key_order _) accu [(k1, v1)] l2;
map_sort_merge_correct key_order key_compare accu' l1' l2
else
let accu' = accu `List.Tot.append` [(k2, v2)] in
List.Tot.append_memP_forall l1 l2;
List.Tot.append_memP_forall accu (l1 `List.Tot.append` l2);
List.Tot.append_memP_forall accu [(k2, v2)];
List.Tot.append_memP_forall l1 l2';
List.Tot.append_memP_forall accu' (l1 `List.Tot.append` l2');
List.Tot.no_repeats_p_append_permut (List.Tot.map fst accu)
[k2]
(List.Tot.map fst l1)
[]
(List.Tot.map fst l2');
List.Tot.append_assoc (List.Tot.map fst accu)
[k2]
((List.Tot.map fst l1) `List.Tot.append` (List.Tot.map fst l2'));
List.Tot.map_append fst accu [(k2, v2)];
List.Tot.map_append fst l1 l2';
List.Tot.map_append fst accu' (l1 `List.Tot.append` l2');
List.Tot.append_assoc accu [(k2, v2)] l2';
list_sorted_append_elim (map_entry_order key_order _) accu' l2';
list_sorted_append_elim (map_entry_order key_order _) accu l1;
list_sorted_append_chunk_intro (map_entry_order key_order _) accu [(k2, v2)] l1;
List.Tot.append_assoc accu [(k2, v2)] l1;
map_sort_merge_correct key_order key_compare accu' l1 l2' | false |
Vale.AES.PPC64LE.AES256.fsti | Vale.AES.PPC64LE.AES256.va_quick_AES256EncryptBlock_6way | val va_quick_AES256EncryptBlock_6way
(in1 in2 in3 in4 in5 in6: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
: (va_quickCode unit (va_code_AES256EncryptBlock_6way ())) | val va_quick_AES256EncryptBlock_6way
(in1 in2 in3 in4 in5 in6: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
: (va_quickCode unit (va_code_AES256EncryptBlock_6way ())) | let va_quick_AES256EncryptBlock_6way (in1:quad32) (in2:quad32) (in3:quad32) (in4:quad32)
(in5:quad32) (in6:quad32) (key:(seq nat32)) (round_keys:(seq quad32)) (keys_buffer:buffer128) :
(va_quickCode unit (va_code_AES256EncryptBlock_6way ())) =
(va_QProc (va_code_AES256EncryptBlock_6way ()) ([va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4;
va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10])
(va_wp_AES256EncryptBlock_6way in1 in2 in3 in4 in5 in6 key round_keys keys_buffer)
(va_wpProof_AES256EncryptBlock_6way in1 in2 in3 in4 in5 in6 key round_keys keys_buffer)) | {
"file_name": "obj/Vale.AES.PPC64LE.AES256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 92,
"end_line": 230,
"start_col": 0,
"start_line": 224
} | module Vale.AES.PPC64LE.AES256
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.AES.AES_BE_s
open Vale.PPC64LE.Machine_s
open Vale.PPC64LE.Memory
open Vale.PPC64LE.State
open Vale.PPC64LE.Decls
open Vale.PPC64LE.InsBasic
open Vale.PPC64LE.InsMem
open Vale.PPC64LE.InsVector
open Vale.PPC64LE.QuickCode
open Vale.PPC64LE.QuickCodes
open Vale.Arch.Types
open Vale.AES.AES256_helpers_BE
#reset-options "--z3rlimit 20"
//-- KeyExpansion256Stdcall
val va_code_KeyExpansion256Stdcall : va_dummy:unit -> Tot va_code
val va_codegen_success_KeyExpansion256Stdcall : va_dummy:unit -> Tot va_pbool
val va_lemma_KeyExpansion256Stdcall : va_b0:va_code -> va_s0:va_state -> input_key_b:buffer128 ->
output_key_expansion_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_KeyExpansion256Stdcall ()) va_s0 /\ va_get_ok va_s0 /\
(let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_s0) (va_get_reg 4 va_s0) input_key_b 2 (va_get_mem_layout va_s0) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0)
output_key_expansion_b 15 (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 /\
(let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_sM) (va_get_reg 4 va_sM) input_key_b 2 (va_get_mem_layout va_sM) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM)
output_key_expansion_b 15 (va_get_mem_layout va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers_BE.make_AES256_key
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0
(va_get_mem_heaplet 0 va_s0))) (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0))) in
Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(reverse_bytes_quad32
(buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)))}j <= 14 ==>
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read output_key_expansion_b
j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key) j)) /\ va_state_eq va_sM (va_update_vec
5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM (va_update_vec 1
va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_mem_heaplet 1 va_sM
(va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))))
[@ va_qattr]
let va_wp_KeyExpansion256Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128)
(va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_s0) (va_get_reg 4 va_s0) input_key_b 2 (va_get_mem_layout va_s0) Secret /\
Vale.PPC64LE.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0) (va_get_reg 3 va_s0)
output_key_expansion_b 15 (va_get_mem_layout va_s0) Secret) /\ (forall (va_x_mem:vale_heap)
(va_x_heap1:vale_heap) (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32)
(va_x_v3:quad32) (va_x_v4:quad32) (va_x_v5:quad32) . let va_sM = va_upd_vec 5 va_x_v5
(va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2 (va_upd_vec 1 va_x_v1
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_mem
va_x_mem va_s0)))))))) in va_get_ok va_sM /\ (let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers_BE.make_AES256_key
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 0
(va_get_mem_heaplet 0 va_s0))) (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0))) in
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM) (va_get_reg 4 va_sM)
input_key_b 2 (va_get_mem_layout va_sM) Secret /\ Vale.PPC64LE.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_sM) (va_get_reg 3 va_sM) output_key_expansion_b 15 (va_get_mem_layout
va_sM) Secret) /\ (let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers_BE.make_AES256_key (Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0)))
(Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read input_key_b 1
(va_get_mem_heaplet 0 va_s0))) in Vale.PPC64LE.Decls.modifies_buffer128 output_key_expansion_b
(va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) .
{:pattern(reverse_bytes_quad32 (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1
va_sM)))}j <= 14 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM)) == FStar.Seq.Base.index
#Vale.Def.Types_s.quad32 (Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key) j)) ==> va_k
va_sM (())))
val va_wpProof_KeyExpansion256Stdcall : input_key_b:buffer128 -> output_key_expansion_b:buffer128
-> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_KeyExpansion256Stdcall input_key_b output_key_expansion_b
va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion256Stdcall ())
([va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0;
va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_KeyExpansion256Stdcall (input_key_b:buffer128) (output_key_expansion_b:buffer128) :
(va_quickCode unit (va_code_KeyExpansion256Stdcall ())) =
(va_QProc (va_code_KeyExpansion256Stdcall ()) ([va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3;
va_Mod_vec 2; va_Mod_vec 1; va_Mod_vec 0; va_Mod_reg 10; va_Mod_mem_heaplet 1; va_Mod_mem])
(va_wp_KeyExpansion256Stdcall input_key_b output_key_expansion_b)
(va_wpProof_KeyExpansion256Stdcall input_key_b output_key_expansion_b))
//--
//-- AES256EncryptBlock
val va_code_AES256EncryptBlock : va_dummy:unit -> Tot va_code
val va_codegen_success_AES256EncryptBlock : va_dummy:unit -> Tot va_pbool
val va_lemma_AES256EncryptBlock : va_b0:va_code -> va_s0:va_state -> input:quad32 -> key:(seq
nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AES256EncryptBlock ()) va_s0 /\ va_get_ok va_s0 /\
Vale.AES.AES_BE_s.is_aes_key_word AES_256 key /\ FStar.Seq.Base.length #quad32 round_keys == 15
/\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key /\ va_get_vec 0 va_s0 ==
input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128
keys_buffer (va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128
(va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0) keys_buffer 15 (va_get_mem_layout va_s0)
Secret /\ (forall (i:nat) . i < 15 ==> Vale.Def.Types_s.reverse_bytes_quad32
(Vale.PPC64LE.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0)) ==
FStar.Seq.Base.index #quad32 round_keys i)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key input /\ va_state_eq va_sM
(va_update_vec 2 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_ok va_sM
va_s0))))))
[@ va_qattr]
let va_wp_AES256EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_256 key /\ FStar.Seq.Base.length
#quad32 round_keys == 15 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key
/\ va_get_vec 0 va_s0 == input /\ va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr
#Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\
Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0)
keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 15 ==>
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i
(va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i) /\ (forall
(va_x_r10:nat64) (va_x_v0:quad32) (va_x_v2:quad32) . let va_sM = va_upd_vec 2 va_x_v2
(va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0)) in va_get_ok va_sM /\ va_get_vec 0 va_sM
== Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key input ==> va_k va_sM (())))
val va_wpProof_AES256EncryptBlock : input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) ->
keys_buffer:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_AES256EncryptBlock input key round_keys keys_buffer va_s0
va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AES256EncryptBlock ()) ([va_Mod_vec 2;
va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_AES256EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) : (va_quickCode unit (va_code_AES256EncryptBlock ())) =
(va_QProc (va_code_AES256EncryptBlock ()) ([va_Mod_vec 2; va_Mod_vec 0; va_Mod_reg 10])
(va_wp_AES256EncryptBlock input key round_keys keys_buffer) (va_wpProof_AES256EncryptBlock
input key round_keys keys_buffer))
//--
//-- AES256EncryptBlock_6way
val va_code_AES256EncryptBlock_6way : va_dummy:unit -> Tot va_code
val va_codegen_success_AES256EncryptBlock_6way : va_dummy:unit -> Tot va_pbool
val va_lemma_AES256EncryptBlock_6way : va_b0:va_code -> va_s0:va_state -> in1:quad32 -> in2:quad32
-> in3:quad32 -> in4:quad32 -> in5:quad32 -> in6:quad32 -> key:(seq nat32) -> round_keys:(seq
quad32) -> keys_buffer:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AES256EncryptBlock_6way ()) va_s0 /\ va_get_ok va_s0
/\ Vale.AES.AES_BE_s.is_aes_key_word AES_256 key /\ FStar.Seq.Base.length #quad32 round_keys ==
15 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key /\ va_get_vec 0 va_s0
== in1 /\ va_get_vec 1 va_s0 == in2 /\ va_get_vec 2 va_s0 == in3 /\ va_get_vec 3 va_s0 == in4
/\ va_get_vec 4 va_s0 == in5 /\ va_get_vec 5 va_s0 == in6 /\ va_get_reg 4 va_s0 ==
Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0
va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) (va_get_reg 4 va_s0)
keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 15 ==>
Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read keys_buffer i
(va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in1 /\ va_get_vec 1 va_sM
== Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in2 /\ va_get_vec 2 va_sM ==
Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in3 /\ va_get_vec 3 va_sM ==
Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in4 /\ va_get_vec 4 va_sM ==
Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in5 /\ va_get_vec 5 va_sM ==
Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in6 /\ va_state_eq va_sM (va_update_vec 6 va_sM
(va_update_vec 5 va_sM (va_update_vec 4 va_sM (va_update_vec 3 va_sM (va_update_vec 2 va_sM
(va_update_vec 1 va_sM (va_update_vec 0 va_sM (va_update_reg 10 va_sM (va_update_ok va_sM
va_s0)))))))))))
[@ va_qattr]
let va_wp_AES256EncryptBlock_6way (in1:quad32) (in2:quad32) (in3:quad32) (in4:quad32) (in5:quad32)
(in6:quad32) (key:(seq nat32)) (round_keys:(seq quad32)) (keys_buffer:buffer128) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ Vale.AES.AES_BE_s.is_aes_key_word AES_256 key /\ FStar.Seq.Base.length
#quad32 round_keys == 15 /\ round_keys == Vale.AES.AES_BE_s.key_to_round_keys_word AES_256 key
/\ va_get_vec 0 va_s0 == in1 /\ va_get_vec 1 va_s0 == in2 /\ va_get_vec 2 va_s0 == in3 /\
va_get_vec 3 va_s0 == in4 /\ va_get_vec 4 va_s0 == in5 /\ va_get_vec 5 va_s0 == in6 /\
va_get_reg 4 va_s0 == Vale.PPC64LE.Memory.buffer_addr #Vale.PPC64LE.Memory.vuint128 keys_buffer
(va_get_mem_heaplet 0 va_s0) /\ Vale.PPC64LE.Decls.validSrcAddrs128 (va_get_mem_heaplet 0
va_s0) (va_get_reg 4 va_s0) keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat)
. i < 15 ==> Vale.Def.Types_s.reverse_bytes_quad32 (Vale.PPC64LE.Decls.buffer128_read
keys_buffer i (va_get_mem_heaplet 0 va_s0)) == FStar.Seq.Base.index #quad32 round_keys i) /\
(forall (va_x_r10:nat64) (va_x_v0:quad32) (va_x_v1:quad32) (va_x_v2:quad32) (va_x_v3:quad32)
(va_x_v4:quad32) (va_x_v5:quad32) (va_x_v6:quad32) . let va_sM = va_upd_vec 6 va_x_v6
(va_upd_vec 5 va_x_v5 (va_upd_vec 4 va_x_v4 (va_upd_vec 3 va_x_v3 (va_upd_vec 2 va_x_v2
(va_upd_vec 1 va_x_v1 (va_upd_vec 0 va_x_v0 (va_upd_reg 10 va_x_r10 va_s0))))))) in va_get_ok
va_sM /\ va_get_vec 0 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in1 /\ va_get_vec
1 va_sM == Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in2 /\ va_get_vec 2 va_sM ==
Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in3 /\ va_get_vec 3 va_sM ==
Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in4 /\ va_get_vec 4 va_sM ==
Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in5 /\ va_get_vec 5 va_sM ==
Vale.AES.AES_BE_s.aes_encrypt_word AES_256 key in6 ==> va_k va_sM (())))
val va_wpProof_AES256EncryptBlock_6way : in1:quad32 -> in2:quad32 -> in3:quad32 -> in4:quad32 ->
in5:quad32 -> in6:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128
-> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_AES256EncryptBlock_6way in1 in2 in3 in4 in5 in6 key
round_keys keys_buffer va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AES256EncryptBlock_6way ())
([va_Mod_vec 6; va_Mod_vec 5; va_Mod_vec 4; va_Mod_vec 3; va_Mod_vec 2; va_Mod_vec 1;
va_Mod_vec 0; va_Mod_reg 10]) va_s0 va_k ((va_sM, va_f0, va_g)))) | {
"checked_file": "/",
"dependencies": [
"Vale.PPC64LE.State.fsti.checked",
"Vale.PPC64LE.QuickCodes.fsti.checked",
"Vale.PPC64LE.QuickCode.fst.checked",
"Vale.PPC64LE.Memory.fsti.checked",
"Vale.PPC64LE.Machine_s.fst.checked",
"Vale.PPC64LE.InsVector.fsti.checked",
"Vale.PPC64LE.InsMem.fsti.checked",
"Vale.PPC64LE.InsBasic.fsti.checked",
"Vale.PPC64LE.Decls.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_BE_s.fst.checked",
"Vale.AES.AES256_helpers_BE.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.PPC64LE.AES256.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers_BE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.PPC64LE.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_BE_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.PPC64LE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
in1: Vale.PPC64LE.Memory.quad32 ->
in2: Vale.PPC64LE.Memory.quad32 ->
in3: Vale.PPC64LE.Memory.quad32 ->
in4: Vale.PPC64LE.Memory.quad32 ->
in5: Vale.PPC64LE.Memory.quad32 ->
in6: Vale.PPC64LE.Memory.quad32 ->
key: FStar.Seq.Base.seq Vale.PPC64LE.Memory.nat32 ->
round_keys: FStar.Seq.Base.seq Vale.PPC64LE.Memory.quad32 ->
keys_buffer: Vale.PPC64LE.Memory.buffer128
-> Vale.PPC64LE.QuickCode.va_quickCode Prims.unit
(Vale.AES.PPC64LE.AES256.va_code_AES256EncryptBlock_6way ()) | Prims.Tot | [
"total"
] | [] | [
"Vale.PPC64LE.Memory.quad32",
"FStar.Seq.Base.seq",
"Vale.PPC64LE.Memory.nat32",
"Vale.PPC64LE.Memory.buffer128",
"Vale.PPC64LE.QuickCode.va_QProc",
"Prims.unit",
"Vale.AES.PPC64LE.AES256.va_code_AES256EncryptBlock_6way",
"Prims.Cons",
"Vale.PPC64LE.QuickCode.mod_t",
"Vale.PPC64LE.QuickCode.va_Mod_vec",
"Vale.PPC64LE.QuickCode.va_Mod_reg",
"Prims.Nil",
"Vale.AES.PPC64LE.AES256.va_wp_AES256EncryptBlock_6way",
"Vale.AES.PPC64LE.AES256.va_wpProof_AES256EncryptBlock_6way",
"Vale.PPC64LE.QuickCode.va_quickCode"
] | [] | false | false | false | false | false | let va_quick_AES256EncryptBlock_6way
(in1 in2 in3 in4 in5 in6: quad32)
(key: (seq nat32))
(round_keys: (seq quad32))
(keys_buffer: buffer128)
: (va_quickCode unit (va_code_AES256EncryptBlock_6way ())) =
| (va_QProc (va_code_AES256EncryptBlock_6way ())
([
va_Mod_vec 6;
va_Mod_vec 5;
va_Mod_vec 4;
va_Mod_vec 3;
va_Mod_vec 2;
va_Mod_vec 1;
va_Mod_vec 0;
va_Mod_reg 10
])
(va_wp_AES256EncryptBlock_6way in1 in2 in3 in4 in5 in6 key round_keys keys_buffer)
(va_wpProof_AES256EncryptBlock_6way in1 in2 in3 in4 in5 in6 key round_keys keys_buffer)) | false |
Hacl.Impl.Chacha20.Core32.fst | Hacl.Impl.Chacha20.Core32.double_round | val double_round:
st:state ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.double_round (as_seq h0 st)) | val double_round:
st:state ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.double_round (as_seq h0 st)) | let double_round st =
quarter_round st (size 0) (size 4) (size 8) (size 12);
quarter_round st (size 1) (size 5) (size 9) (size 13);
quarter_round st (size 2) (size 6) (size 10) (size 14);
quarter_round st (size 3) (size 7) (size 11) (size 15);
quarter_round st (size 0) (size 5) (size 10) (size 15);
quarter_round st (size 1) (size 6) (size 11) (size 12);
quarter_round st (size 2) (size 7) (size 8) (size 13);
quarter_round st (size 3) (size 4) (size 9) (size 14) | {
"file_name": "code/chacha20/Hacl.Impl.Chacha20.Core32.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 185,
"start_col": 0,
"start_line": 176
} | module Hacl.Impl.Chacha20.Core32
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.Sequence
open Lib.Buffer
open Lib.ByteBuffer
module ST = FStar.HyperStack.ST
module Spec = Spec.Chacha20
let state = lbuffer uint32 16ul
let index = i:size_t{size_v i < 16}
inline_for_extraction
val create_state: unit ->
StackInline state
(requires fun h -> True)
(ensures fun h0 r h1 -> live h1 r /\
as_seq h1 r == Seq.create 16 (u32 0) /\
stack_allocated r h0 h1 (Seq.create 16 (u32 0)))
let create_state () = create (size 16) (u32 0)
inline_for_extraction
val load_state:
st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Lib.ByteSequence.uints_from_bytes_le (as_seq h0 b))
let load_state st b =
uints_from_bytes_le st b
inline_for_extraction
val store_state:
b:lbuffer uint8 64ul
-> st:state ->
Stack unit
(requires fun h -> live h st /\ live h b /\ disjoint st b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
as_seq h1 b == Lib.ByteSequence.uints_to_bytes_le (as_seq h0 st))
let store_state st b =
uints_to_bytes_le 16ul st b
inline_for_extraction
val set_counter:
st:state
-> c:size_t ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Seq.upd (as_seq h0 st) 12 (size_to_uint32 c))
let set_counter st c =
st.(size 12) <- size_to_uint32 c
inline_for_extraction
val incr_counter:
st:state ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1)
let incr_counter st =
let c = st.(size 12) in
st.(size 12) <- c +. u32 1
inline_for_extraction
val copy_state:
st:state
-> ost:state ->
Stack unit
(requires fun h -> live h st /\ live h ost /\ disjoint st ost)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == as_seq h0 ost)
let copy_state st ost = copy #MUT #uint32 #(size 16) st ost
inline_for_extraction
val sum_state:
st:state
-> ost:state ->
Stack unit
(requires fun h -> live h st /\ live h ost /\ eq_or_disjoint st ost)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.sum_state (as_seq h0 st) (as_seq h0 ost))
let sum_state st ost = map2T #MUT #MUT #uint32 #uint32 #uint32 (size 16) st ( +. ) st ost
#set-options "--z3rlimit 100"
inline_for_extraction
val xor_block:
o:lbuffer uint8 64ul
-> st:state
-> b:lbuffer uint8 64ul ->
Stack unit
(requires fun h -> live h o /\ live h st /\ live h b)
(ensures fun h0 _ h1 -> modifies (loc o) h0 h1 /\
as_seq h1 o == Spec.xor_block (as_seq h0 st) (as_seq h0 b))
let xor_block o st b =
push_frame();
let bl = create_state() in
load_state bl b;
map2T (size 16) bl ( ^. ) bl st;
store_state o bl;
pop_frame()
inline_for_extraction
val line:
st:state
-> a:index
-> b:index
-> d:index
-> r:rotval U32 ->
Stack unit
(requires fun h -> live h st /\ v a <> v d)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.line (v a) (v b) (v d) r (as_seq h0 st))
let line st a b d r =
let sta = st.(a) in
let stb = st.(b) in
let std = st.(d) in
let sta = sta +. stb in
let std = std ^. sta in
let std = rotate_left std r in
st.(a) <- sta;
st.(d) <- std
val quarter_round:
st:state
-> a:index
-> b:index
-> c:index
-> d:index ->
Stack unit
(requires fun h -> live h st /\ v a <> v d /\ v c <> v b)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.quarter_round (v a) (v b) (v c) (v d) (as_seq h0 st))
[@ CInline ]
let quarter_round st a b c d =
line st a b d (size 16);
line st c d b (size 12);
line st a b d (size 8);
line st c d b (size 7)
#reset-options "--z3rlimit 50"
val double_round:
st:state ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
as_seq h1 st == Spec.double_round (as_seq h0 st)) | {
"checked_file": "/",
"dependencies": [
"Spec.Chacha20.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Chacha20.Core32.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Chacha20",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Chacha20",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | st: Hacl.Impl.Chacha20.Core32.state -> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Chacha20.Core32.state",
"Hacl.Impl.Chacha20.Core32.quarter_round",
"Lib.IntTypes.size",
"Prims.unit"
] | [] | false | true | false | false | false | let double_round st =
| quarter_round st (size 0) (size 4) (size 8) (size 12);
quarter_round st (size 1) (size 5) (size 9) (size 13);
quarter_round st (size 2) (size 6) (size 10) (size 14);
quarter_round st (size 3) (size 7) (size 11) (size 15);
quarter_round st (size 0) (size 5) (size 10) (size 15);
quarter_round st (size 1) (size 6) (size 11) (size 12);
quarter_round st (size 2) (size 7) (size 8) (size 13);
quarter_round st (size 3) (size 4) (size 9) (size 14) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_tele_correct_exists_no_abs0 | val compute_gen_elim_tele_correct_exists_no_abs0 (ty: _) (body: (ty -> vprop))
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body)) | val compute_gen_elim_tele_correct_exists_no_abs0 (ty: _) (body: (ty -> vprop))
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body)) | let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 43,
"end_line": 352,
"start_col": 0,
"start_line": 342
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ty: Type0 -> body: (_: ty -> Steel.Effect.Common.vprop)
-> Steel.ST.GenElim1.ge_to_tele_t (Steel.ST.GenElim1.Base.GEExistsNoAbs0 body) | Prims.Tot | [
"total"
] | [] | [
"Steel.Effect.Common.vprop",
"Steel.Memory.inames",
"Steel.ST.GenElim1.rewrite_with_trefl",
"Steel.ST.Util.exists_",
"FStar.Universe.raise_t",
"Steel.Effect.Common.star",
"FStar.Universe.downgrade_val",
"Steel.ST.Util.pure",
"Prims.l_True",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.GenElim1.Base.compute_gen_elim_tele",
"Steel.ST.GenElim1.Base.GEExistsNoAbs0",
"Prims.unit",
"Steel.ST.Util.intro_exists",
"FStar.Universe.raise_val",
"Steel.ST.Util.rewrite",
"Steel.ST.Util.intro_pure",
"Steel.ST.GenElim1.elim_exists'",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.ST.GenElim1.ge_to_tele_t"
] | [] | false | false | false | false | false | let compute_gen_elim_tele_correct_exists_no_abs0 (ty: _) (body: (ty -> vprop))
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body)) =
| fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> (body (U.downgrade_val x)) `star` (pure True));
rewrite_with_trefl (exists_ _) (tele_p _) | false |
Hacl.Impl.Ed25519.PointCompress.fst | Hacl.Impl.Ed25519.PointCompress.lemma_fits_in_prime_last_byte | val lemma_fits_in_prime_last_byte (b: lbytes 32)
: Lemma (requires nat_from_bytes_le b < Spec.Curve25519.prime)
(ensures v (Seq.index b 31) < pow2 7) | val lemma_fits_in_prime_last_byte (b: lbytes 32)
: Lemma (requires nat_from_bytes_le b < Spec.Curve25519.prime)
(ensures v (Seq.index b 31) < pow2 7) | let lemma_fits_in_prime_last_byte (b:lbytes 32) : Lemma
(requires nat_from_bytes_le b < Spec.Curve25519.prime)
(ensures v (Seq.index b 31) < pow2 7)
= calc (==) {
nat_from_bytes_le b <: nat;
(==) { nat_from_intseq_le_slice_lemma b 31 }
nat_from_intseq_le (Seq.slice b 0 31) +
pow2 (31 * 8) * nat_from_intseq_le (Seq.slice b 31 32);
(==) { nat_from_intseq_le_lemma0 (Seq.slice b 31 32) }
nat_from_intseq_le (Seq.slice b 0 31) + pow2 (31*8) * v (Seq.index b 31);
};
assert (nat_from_intseq_le (Seq.slice b 0 31) < pow2 (31 * 8));
calc (<) {
pow2 (31*8) * v (Seq.index b 31);
(<) { }
Spec.Curve25519.prime - nat_from_intseq_le (Seq.slice b 0 31);
(<=) { }
Spec.Curve25519.prime;
(<) { }
pow2 255;
};
FStar.Math.Lemmas.lemma_div_lt_nat (pow2 (31*8) * v (Seq.index b 31)) 255 (31*8);
calc (==) {
(pow2 (31 *8) * v (Seq.index b 31))/ (pow2 (31*8));
(==) { FStar.Math.Lemmas.swap_mul (pow2 (31*8)) (v (Seq.index b 31)) }
(v (Seq.index b 31) * pow2 (31 *8)) / (pow2 (31*8));
(==) { FStar.Math.Lemmas.cancel_mul_div (v (Seq.index b 31)) (pow2 (31*8)) }
v (Seq.index b 31);
};
assert_norm (255 - 31 * 8 == 7) | {
"file_name": "code/ed25519/Hacl.Impl.Ed25519.PointCompress.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 65,
"start_col": 0,
"start_line": 36
} | module Hacl.Impl.Ed25519.PointCompress
module ST = FStar.HyperStack.ST
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.ByteSequence
open Lib.Buffer
open Hacl.Bignum25519
module F51 = Hacl.Impl.Ed25519.Field51
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0"
inline_for_extraction noextract
val x_mod_2:
x:felem ->
Stack uint64
(requires fun h -> live h x)
(ensures fun h0 z h1 -> h0 == h1 /\ v z < 2 /\
v z == F51.as_nat h0 x % 2
)
let x_mod_2 x =
(**) let h0 = ST.get() in
let x0 = x.(0ul) in
let z = x0 &. u64 1 in
mod_mask_lemma x0 1ul;
Lib.IntTypes.Compatibility.uintv_extensionality (u64 1) (mod_mask #U64 1ul);
z
open FStar.Calc | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.Compatibility.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Bignum25519.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Ed25519.PointCompress.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.ByteSequence.lbytes 32
-> FStar.Pervasives.Lemma (requires Lib.ByteSequence.nat_from_bytes_le b < Spec.Curve25519.prime)
(ensures Lib.IntTypes.v (FStar.Seq.Base.index b 31) < Prims.pow2 7) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.ByteSequence.lbytes",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.op_Subtraction",
"FStar.Mul.op_Star",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.op_Division",
"Prims.pow2",
"Lib.IntTypes.v",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.Seq.Base.index",
"Lib.IntTypes.uint_t",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Math.Lemmas.swap_mul",
"Prims.squash",
"FStar.Math.Lemmas.cancel_mul_div",
"FStar.Math.Lemmas.lemma_div_lt_nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_LessThanOrEqual",
"Spec.Curve25519.prime",
"Lib.ByteSequence.nat_from_intseq_le",
"FStar.Seq.Base.slice",
"Prims._assert",
"Prims.nat",
"Lib.ByteSequence.nat_from_bytes_le",
"Prims.op_Addition",
"Lib.ByteSequence.nat_from_intseq_le_slice_lemma",
"Lib.ByteSequence.nat_from_intseq_le_lemma0",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_fits_in_prime_last_byte (b: lbytes 32)
: Lemma (requires nat_from_bytes_le b < Spec.Curve25519.prime)
(ensures v (Seq.index b 31) < pow2 7) =
| calc ( == ) {
nat_from_bytes_le b <: nat;
( == ) { nat_from_intseq_le_slice_lemma b 31 }
nat_from_intseq_le (Seq.slice b 0 31) + pow2 (31 * 8) * nat_from_intseq_le (Seq.slice b 31 32);
( == ) { nat_from_intseq_le_lemma0 (Seq.slice b 31 32) }
nat_from_intseq_le (Seq.slice b 0 31) + pow2 (31 * 8) * v (Seq.index b 31);
};
assert (nat_from_intseq_le (Seq.slice b 0 31) < pow2 (31 * 8));
calc ( < ) {
pow2 (31 * 8) * v (Seq.index b 31);
( < ) { () }
Spec.Curve25519.prime - nat_from_intseq_le (Seq.slice b 0 31);
( <= ) { () }
Spec.Curve25519.prime;
( < ) { () }
pow2 255;
};
FStar.Math.Lemmas.lemma_div_lt_nat (pow2 (31 * 8) * v (Seq.index b 31)) 255 (31 * 8);
calc ( == ) {
(pow2 (31 * 8) * v (Seq.index b 31)) / (pow2 (31 * 8));
( == ) { FStar.Math.Lemmas.swap_mul (pow2 (31 * 8)) (v (Seq.index b 31)) }
(v (Seq.index b 31) * pow2 (31 * 8)) / (pow2 (31 * 8));
( == ) { FStar.Math.Lemmas.cancel_mul_div (v (Seq.index b 31)) (pow2 (31 * 8)) }
v (Seq.index b 31);
};
assert_norm (255 - 31 * 8 == 7) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_tele_correct_exists_unit1 | val compute_gen_elim_tele_correct_exists_unit1 (ty: _) (body: (ty -> gen_unit_elim_i))
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body)) | val compute_gen_elim_tele_correct_exists_unit1 (ty: _) (body: (ty -> gen_unit_elim_i))
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body)) | let compute_gen_elim_tele_correct_exists_unit1
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x)));
rewrite_with_trefl (exists_ _) (tele_p _) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 43,
"end_line": 401,
"start_col": 0,
"start_line": 391
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | ty: Type -> body: (_: ty -> Steel.ST.GenElim1.Base.gen_unit_elim_i)
-> Steel.ST.GenElim1.ge_to_tele_t (Steel.ST.GenElim1.Base.GEExistsUnit1 body) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_unit_elim_i",
"Steel.Memory.inames",
"Steel.ST.GenElim1.rewrite_with_trefl",
"Steel.ST.Util.exists_",
"Steel.Effect.Common.star",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_q",
"Steel.ST.Util.pure",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_post",
"Steel.Effect.Common.vprop",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.GenElim1.Base.compute_gen_elim_tele",
"Steel.ST.GenElim1.Base.GEExistsUnit1",
"Prims.unit",
"Steel.ST.Util.intro_exists",
"Steel.ST.Util.intro_pure",
"FStar.Universe.raise_t",
"Steel.ST.GenElim1.compute_gen_unit_elim_f",
"Steel.ST.GenElim1.elim_exists'",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_p",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.ST.GenElim1.ge_to_tele_t"
] | [] | false | false | false | false | false | let compute_gen_elim_tele_correct_exists_unit1 (ty: _) (body: (ty -> gen_unit_elim_i))
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body)) =
| fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x
(fun x -> (compute_gen_unit_elim_q (body x)) `star` (pure (compute_gen_unit_elim_post (body x)))
);
rewrite_with_trefl (exists_ _) (tele_p _) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_tele_correct_exists0 | val compute_gen_elim_tele_correct_exists0
(ty: _)
(body: (ty -> gen_elim_i))
(ih: (x: ty -> GTot (ge_to_tele_t (body x))))
: Tot (ge_to_tele_t (GEExists0 #ty body)) | val compute_gen_elim_tele_correct_exists0
(ty: _)
(body: (ty -> gen_elim_i))
(ih: (x: ty -> GTot (ge_to_tele_t (body x))))
: Tot (ge_to_tele_t (GEExists0 #ty body)) | let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 43,
"end_line": 378,
"start_col": 0,
"start_line": 367
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ty: Type0 ->
body: (_: ty -> Steel.ST.GenElim1.Base.gen_elim_i) ->
ih: (x: ty -> Prims.GTot (Steel.ST.GenElim1.ge_to_tele_t (body x)))
-> Steel.ST.GenElim1.ge_to_tele_t (Steel.ST.GenElim1.Base.GEExists0 body) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.ge_to_tele_t",
"Steel.Memory.inames",
"Steel.ST.GenElim1.rewrite_with_trefl",
"Steel.ST.Util.exists_",
"FStar.Universe.raise_t",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.GenElim1.Base.compute_gen_elim_tele",
"FStar.Universe.downgrade_val",
"Steel.Effect.Common.vprop",
"Steel.ST.GenElim1.Base.GEExists0",
"Prims.unit",
"Steel.ST.Util.intro_exists",
"FStar.Universe.raise_val",
"Steel.ST.Util.rewrite",
"Steel.ST.GenElim1.elim_exists'",
"Steel.ST.GenElim1.Base.compute_gen_elim_p"
] | [] | false | false | false | false | false | let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: (ty -> gen_elim_i))
(ih: (x: ty -> GTot (ge_to_tele_t (body x))))
: Tot (ge_to_tele_t (GEExists0 #ty body)) =
| fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x)))
(tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x)
(fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _) | false |
Hacl.Impl.Ed25519.PointCompress.fst | Hacl.Impl.Ed25519.PointCompress.add_sign | val add_sign:
out:lbuffer uint8 32ul
-> x:uint64{v x < 2} ->
Stack unit
(requires fun h -> live h out /\ nat_from_bytes_le (as_seq h out) < Spec.Curve25519.prime)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
nat_from_bytes_le (as_seq h1 out) == nat_from_bytes_le (as_seq h0 out) + pow2 255 * (v x)
) | val add_sign:
out:lbuffer uint8 32ul
-> x:uint64{v x < 2} ->
Stack unit
(requires fun h -> live h out /\ nat_from_bytes_le (as_seq h out) < Spec.Curve25519.prime)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
nat_from_bytes_le (as_seq h1 out) == nat_from_bytes_le (as_seq h0 out) + pow2 255 * (v x)
) | let add_sign out x =
(**) let h0 = ST.get() in
let xbyte = to_u8 x in
let o31 = out.(31ul) in
(**) FStar.Math.Lemmas.lemma_mult_le_left (pow2 7) (v x) 1;
(**) assert (pow2 7 * (v x) <= pow2 7);
(**) assert_norm (pow2 7 < pow2 8);
(**) assert (v (xbyte <<. 7ul) == pow2 7 * (v x));
out.(31ul) <- o31 +. (xbyte <<. 7ul);
(**) let h1 = ST.get() in
(**) calc (==) {
(**) nat_from_intseq_le (as_seq h1 out) <: nat;
(**) (==) { nat_from_intseq_le_slice_lemma (as_seq h1 out) 31 }
(**) nat_from_intseq_le (Seq.slice (as_seq h1 out) 0 31) +
(**) pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h1 out) 31 32);
(**) (==) {
(**) calc (==) {
(**) pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h1 out) 31 32);
(**) (==) { calc (==) {
(**) nat_from_intseq_le (Seq.slice (as_seq h1 out) 31 32) <: nat;
(**) (==) { nat_from_intseq_le_lemma0 (Seq.slice (as_seq h1 out) 31 32) }
(**) v (o31 +. (xbyte <<. 7ul));
(**) (==) { calc (==) {
(**) v (o31 +. (xbyte <<. 7ul)) <: nat;
(**) (==) { }
(**) (v o31 + v (xbyte <<. 7ul)) % pow2 8;
(**) (==) { FStar.Math.Lemmas.lemma_mult_le_left (pow2 7) (v x) 1;
(**) assert (pow2 7 * (v x) <= pow2 7);
(**) assert_norm (pow2 7 < pow2 8);
(**) lemma_fits_in_prime_last_byte (as_seq h0 out);
(**) assert_norm (pow2 7 + pow2 7 == pow2 8);
(**) FStar.Math.Lemmas.modulo_lemma (v o31 + pow2 7 * (v x)) (pow2 8)
(**) }
(**) v o31 + pow2 7 * (v x);
(**) }; nat_from_intseq_le_lemma0 (Seq.slice (as_seq h0 out) 31 32)
(**) }
(**) nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) + pow2 7 * (v x);
(**) } }
(**) pow2 (31 * 8) * (nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) + pow2 7 * (v x));
(**) (==) { FStar.Math.Lemmas.distributivity_add_right (pow2 (31 * 8))
(**) (nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32)) (pow2 7 * (v x)) }
(**) pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) +
(**) pow2 (31 * 8) * pow2 7 * (v x);
(**) (==) { assert_norm (pow2 (31*8) * pow2 7 == pow2 255) }
(**) pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) +
(**) pow2 255 * (v x);
(**) }
(**) }
(**) nat_from_intseq_le (Seq.slice (as_seq h1 out) 0 31) +
(**) pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) +
(**) pow2 255 * (v x);
(**) (==) { nat_from_intseq_le_slice_lemma (as_seq h0 out) 31 }
(**) nat_from_bytes_le (as_seq h0 out) + pow2 255 * (v x);
(**) } | {
"file_name": "code/ed25519/Hacl.Impl.Ed25519.PointCompress.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 129,
"start_col": 0,
"start_line": 76
} | module Hacl.Impl.Ed25519.PointCompress
module ST = FStar.HyperStack.ST
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.ByteSequence
open Lib.Buffer
open Hacl.Bignum25519
module F51 = Hacl.Impl.Ed25519.Field51
#set-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0"
inline_for_extraction noextract
val x_mod_2:
x:felem ->
Stack uint64
(requires fun h -> live h x)
(ensures fun h0 z h1 -> h0 == h1 /\ v z < 2 /\
v z == F51.as_nat h0 x % 2
)
let x_mod_2 x =
(**) let h0 = ST.get() in
let x0 = x.(0ul) in
let z = x0 &. u64 1 in
mod_mask_lemma x0 1ul;
Lib.IntTypes.Compatibility.uintv_extensionality (u64 1) (mod_mask #U64 1ul);
z
open FStar.Calc
let lemma_fits_in_prime_last_byte (b:lbytes 32) : Lemma
(requires nat_from_bytes_le b < Spec.Curve25519.prime)
(ensures v (Seq.index b 31) < pow2 7)
= calc (==) {
nat_from_bytes_le b <: nat;
(==) { nat_from_intseq_le_slice_lemma b 31 }
nat_from_intseq_le (Seq.slice b 0 31) +
pow2 (31 * 8) * nat_from_intseq_le (Seq.slice b 31 32);
(==) { nat_from_intseq_le_lemma0 (Seq.slice b 31 32) }
nat_from_intseq_le (Seq.slice b 0 31) + pow2 (31*8) * v (Seq.index b 31);
};
assert (nat_from_intseq_le (Seq.slice b 0 31) < pow2 (31 * 8));
calc (<) {
pow2 (31*8) * v (Seq.index b 31);
(<) { }
Spec.Curve25519.prime - nat_from_intseq_le (Seq.slice b 0 31);
(<=) { }
Spec.Curve25519.prime;
(<) { }
pow2 255;
};
FStar.Math.Lemmas.lemma_div_lt_nat (pow2 (31*8) * v (Seq.index b 31)) 255 (31*8);
calc (==) {
(pow2 (31 *8) * v (Seq.index b 31))/ (pow2 (31*8));
(==) { FStar.Math.Lemmas.swap_mul (pow2 (31*8)) (v (Seq.index b 31)) }
(v (Seq.index b 31) * pow2 (31 *8)) / (pow2 (31*8));
(==) { FStar.Math.Lemmas.cancel_mul_div (v (Seq.index b 31)) (pow2 (31*8)) }
v (Seq.index b 31);
};
assert_norm (255 - 31 * 8 == 7)
inline_for_extraction noextract
val add_sign:
out:lbuffer uint8 32ul
-> x:uint64{v x < 2} ->
Stack unit
(requires fun h -> live h out /\ nat_from_bytes_le (as_seq h out) < Spec.Curve25519.prime)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
nat_from_bytes_le (as_seq h1 out) == nat_from_bytes_le (as_seq h0 out) + pow2 255 * (v x) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.Compatibility.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Bignum25519.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Ed25519.PointCompress.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | out: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> x: Lib.IntTypes.uint64{Lib.IntTypes.v x < 2}
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.uint64",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.Calc.calc_finish",
"Prims.nat",
"Prims.eq2",
"Lib.ByteSequence.nat_from_intseq_le",
"Lib.IntTypes.U8",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Prims.op_Addition",
"Lib.ByteSequence.nat_from_bytes_le",
"FStar.Mul.op_Star",
"Prims.pow2",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Seq.Base.slice",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Lib.ByteSequence.nat_from_intseq_le_slice_lemma",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.squash",
"Prims.int",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.ByteSequence.nat_from_intseq_le_lemma0",
"Prims.op_Modulus",
"FStar.Math.Lemmas.modulo_lemma",
"FStar.Pervasives.assert_norm",
"Hacl.Impl.Ed25519.PointCompress.lemma_fits_in_prime_last_byte",
"Prims._assert",
"Prims.op_LessThanOrEqual",
"FStar.Math.Lemmas.lemma_mult_le_left",
"FStar.Math.Lemmas.distributivity_add_right",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.op_Array_Assignment",
"Lib.IntTypes.int_t",
"Lib.Buffer.op_Array_Access",
"Lib.IntTypes.to_u8"
] | [] | false | true | false | false | false | let add_sign out x =
| let h0 = ST.get () in
let xbyte = to_u8 x in
let o31 = out.(31ul) in
FStar.Math.Lemmas.lemma_mult_le_left (pow2 7) (v x) 1;
assert (pow2 7 * (v x) <= pow2 7);
assert_norm (pow2 7 < pow2 8);
assert (v (xbyte <<. 7ul) == pow2 7 * (v x));
out.(31ul) <- o31 +. (xbyte <<. 7ul);
let h1 = ST.get () in
calc ( == ) {
nat_from_intseq_le (as_seq h1 out) <: nat;
( == ) { nat_from_intseq_le_slice_lemma (as_seq h1 out) 31 }
nat_from_intseq_le (Seq.slice (as_seq h1 out) 0 31) +
pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h1 out) 31 32);
( == ) { calc ( == ) {
pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h1 out) 31 32);
( == ) { calc ( == ) {
nat_from_intseq_le (Seq.slice (as_seq h1 out) 31 32) <: nat;
( == ) { nat_from_intseq_le_lemma0 (Seq.slice (as_seq h1 out) 31 32) }
v (o31 +. (xbyte <<. 7ul));
( == ) { (calc ( == ) {
v (o31 +. (xbyte <<. 7ul)) <: nat;
( == ) { () }
(v o31 + v (xbyte <<. 7ul)) % pow2 8;
( == ) { (FStar.Math.Lemmas.lemma_mult_le_left (pow2 7) (v x) 1;
assert (pow2 7 * (v x) <= pow2 7);
assert_norm (pow2 7 < pow2 8);
lemma_fits_in_prime_last_byte (as_seq h0 out);
assert_norm (pow2 7 + pow2 7 == pow2 8);
FStar.Math.Lemmas.modulo_lemma (v o31 + pow2 7 * (v x)) (pow2 8)) }
v o31 + pow2 7 * (v x);
};
nat_from_intseq_le_lemma0 (Seq.slice (as_seq h0 out) 31 32)) }
nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) + pow2 7 * (v x);
} }
pow2 (31 * 8) * (nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) + pow2 7 * (v x));
( == ) { FStar.Math.Lemmas.distributivity_add_right (pow2 (31 * 8))
(nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32))
(pow2 7 * (v x)) }
pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) +
(pow2 (31 * 8) * pow2 7) * (v x);
( == ) { assert_norm (pow2 (31 * 8) * pow2 7 == pow2 255) }
pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) + pow2 255 * (v x);
} }
nat_from_intseq_le (Seq.slice (as_seq h1 out) 0 31) +
pow2 (31 * 8) * nat_from_intseq_le (Seq.slice (as_seq h0 out) 31 32) +
pow2 255 * (v x);
( == ) { nat_from_intseq_le_slice_lemma (as_seq h0 out) 31 }
nat_from_bytes_le (as_seq h0 out) + pow2 255 * (v x);
} | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_tele_correct_star_l | val compute_gen_elim_tele_correct_star_l (l: gen_elim_i) (ihl: ge_to_tele_t l) (ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru)) | val compute_gen_elim_tele_correct_star_l (l: gen_elim_i) (ihl: ge_to_tele_t l) (ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru)) | let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 42,
"end_line": 314,
"start_col": 0,
"start_line": 303
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
l: Steel.ST.GenElim1.Base.gen_elim_i ->
ihl: Steel.ST.GenElim1.ge_to_tele_t l ->
ru: Steel.ST.GenElim1.Base.gen_unit_elim_i
-> Steel.ST.GenElim1.ge_to_tele_t (Steel.ST.GenElim1.Base.GEStarL l ru) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.ge_to_tele_t",
"Steel.ST.GenElim1.Base.gen_unit_elim_i",
"Steel.Memory.inames",
"Steel.ST.GenElim1.rewrite_with_trefl",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.GenElim1.Base.tele_star_vprop",
"Steel.ST.GenElim1.Base.compute_gen_elim_tele",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_q",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_post",
"Steel.ST.GenElim1.Base.GEStarL",
"Prims.unit",
"Steel.ST.GenElim1.tele_star_vprop_correct",
"Steel.ST.Util.intro_pure",
"FStar.Universe.raise_t",
"Steel.ST.GenElim1.compute_gen_unit_elim_f",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.Effect.Common.star",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_p"
] | [] | false | false | false | false | false | let compute_gen_elim_tele_correct_star_l (l: gen_elim_i) (ihl: ge_to_tele_t l) (ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru)) =
| fun _ ->
rewrite_with_trefl (compute_gen_elim_p _)
((compute_gen_elim_p l) `star` (compute_gen_unit_elim_p ru));
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_tele_correct_star_r | val compute_gen_elim_tele_correct_star_r (lu: gen_unit_elim_i) (r: gen_elim_i) (ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r)) | val compute_gen_elim_tele_correct_star_r (lu: gen_unit_elim_i) (r: gen_elim_i) (ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r)) | let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _) | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 42,
"end_line": 327,
"start_col": 0,
"start_line": 316
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
lu: Steel.ST.GenElim1.Base.gen_unit_elim_i ->
r: Steel.ST.GenElim1.Base.gen_elim_i ->
ihr: Steel.ST.GenElim1.ge_to_tele_t r
-> Steel.ST.GenElim1.ge_to_tele_t (Steel.ST.GenElim1.Base.GEStarR lu r) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_unit_elim_i",
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.ge_to_tele_t",
"Steel.Memory.inames",
"Steel.ST.GenElim1.rewrite_with_trefl",
"Steel.ST.GenElim1.tele_p",
"Steel.ST.GenElim1.Base.tele_star_vprop",
"Steel.ST.GenElim1.Base.compute_gen_elim_tele",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_q",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_post",
"Steel.ST.GenElim1.Base.GEStarR",
"Prims.unit",
"Steel.ST.GenElim1.tele_star_vprop_correct",
"Steel.ST.Util.intro_pure",
"FStar.Universe.raise_t",
"Steel.ST.GenElim1.compute_gen_unit_elim_f",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.Effect.Common.star",
"Steel.ST.GenElim1.Base.compute_gen_unit_elim_p"
] | [] | false | false | false | false | false | let compute_gen_elim_tele_correct_star_r (lu: gen_unit_elim_i) (r: gen_elim_i) (ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r)) =
| fun _ ->
rewrite_with_trefl (compute_gen_elim_p _)
((compute_gen_unit_elim_p lu) `star` (compute_gen_elim_p r));
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _) | false |
CBOR.Spec.Map.fst | CBOR.Spec.Map.map_sort_correct | val map_sort_correct
(#t1 #t2: Type)
(key_order: (t1 -> t1 -> bool))
(key_compare: (t1 -> t1 -> int))
(l: list (t1 & t2))
: Lemma
(requires
((forall x. key_order x x == false) /\
(forall x y z. (key_order x y /\ key_order y z) ==> key_order x z) /\
(forall x y. key_order x y == (key_compare x y < 0)) /\
(forall x y. key_compare x y == 0 <==> x == y) /\
(forall x y. (key_compare x y < 0 <==> key_compare y x > 0))))
(ensures
(let res, l' = map_sort key_compare l in
(forall x. List.Tot.memP x l' <==> List.Tot.memP x l) /\
(List.Tot.no_repeats_p (List.Tot.map fst l') <==>
List.Tot.no_repeats_p (List.Tot.map fst l)) /\
(res == true <==> List.Tot.no_repeats_p (List.Tot.map fst l)) /\
(res == true ==>
(List.Tot.sorted (map_entry_order key_order _) l' /\
(forall k. list_ghost_assoc k l' == list_ghost_assoc k l)))))
(decreases (List.Tot.length l)) | val map_sort_correct
(#t1 #t2: Type)
(key_order: (t1 -> t1 -> bool))
(key_compare: (t1 -> t1 -> int))
(l: list (t1 & t2))
: Lemma
(requires
((forall x. key_order x x == false) /\
(forall x y z. (key_order x y /\ key_order y z) ==> key_order x z) /\
(forall x y. key_order x y == (key_compare x y < 0)) /\
(forall x y. key_compare x y == 0 <==> x == y) /\
(forall x y. (key_compare x y < 0 <==> key_compare y x > 0))))
(ensures
(let res, l' = map_sort key_compare l in
(forall x. List.Tot.memP x l' <==> List.Tot.memP x l) /\
(List.Tot.no_repeats_p (List.Tot.map fst l') <==>
List.Tot.no_repeats_p (List.Tot.map fst l)) /\
(res == true <==> List.Tot.no_repeats_p (List.Tot.map fst l)) /\
(res == true ==>
(List.Tot.sorted (map_entry_order key_order _) l' /\
(forall k. list_ghost_assoc k l' == list_ghost_assoc k l)))))
(decreases (List.Tot.length l)) | let rec map_sort_correct
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool)
(key_compare: t1 -> t1 -> int)
(l: list (t1 & t2))
: Lemma
(requires (
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z) /\
(forall x y . key_order x y == (key_compare x y < 0)) /\
(forall x y . key_compare x y == 0 <==> x == y) /\
(forall x y . (key_compare x y < 0 <==> key_compare y x > 0))
))
(ensures (let (res, l') = map_sort key_compare l in
(forall x . List.Tot.memP x l' <==> List.Tot.memP x l) /\
(List.Tot.no_repeats_p (List.Tot.map fst l') <==> List.Tot.no_repeats_p (List.Tot.map fst l)) /\
(res == true <==> List.Tot.no_repeats_p (List.Tot.map fst l)) /\
(res == true ==> (
List.Tot.sorted (map_entry_order key_order _) l' /\
(forall k . list_ghost_assoc k l' == list_ghost_assoc k l)
))
))
(decreases (List.Tot.length l))
= let len = List.Tot.length l in
if len < 2
then ()
else begin
let (l1, l2) = List.Tot.splitAt (len / 2) l in
List.Tot.append_memP_forall l1 l2;
List.Tot.map_append fst l1 l2;
List.Tot.no_repeats_p_append (List.Tot.map fst l1) (List.Tot.map fst l2);
List.Tot.append_memP_forall (List.Tot.map fst l1) (List.Tot.map fst l2);
list_memP_map_forall fst l1;
list_memP_map_forall fst l2;
let (res, l1') = map_sort key_compare l1 in
map_sort_correct key_order key_compare l1;
list_memP_map_forall fst l1';
List.Tot.append_memP_forall (List.Tot.map fst l1') (List.Tot.map fst l2);
List.Tot.no_repeats_p_append (List.Tot.map fst l1') (List.Tot.map fst l2);
List.Tot.map_append fst l1' l2;
List.Tot.append_memP_forall l1' l2;
if not res
then ()
else begin
let (res, l2') = map_sort key_compare l2 in
map_sort_correct key_order key_compare l2;
list_memP_map_forall fst l2';
List.Tot.append_memP_forall (List.Tot.map fst l1') (List.Tot.map fst l2');
List.Tot.no_repeats_p_append (List.Tot.map fst l1') (List.Tot.map fst l2');
List.Tot.map_append fst l1' l2';
List.Tot.append_memP_forall l1' l2';
if not res
then ()
else begin
let (res, l') = map_sort_merge key_compare [] l1' l2' in
assert (map_sort key_compare l == (res, l'));
map_sort_merge_correct key_order key_compare [] l1' l2';
assert (forall x . List.Tot.memP x l' <==> (List.Tot.memP x l1' \/ List.Tot.memP x l2'));
assert (forall x . List.Tot.memP x l' <==> List.Tot.memP x l);
assert (List.Tot.no_repeats_p (List.Tot.map fst l') <==> List.Tot.no_repeats_p (List.Tot.map fst l));
if res
then begin
assert (List.Tot.sorted (map_entry_order key_order _) l');
list_sorted_map_entry_order_no_repeats key_order l';
list_ghost_assoc_no_repeats_equiv l l';
assert (forall k . list_ghost_assoc k l' == list_ghost_assoc k l)
end
else ()
end
end
end | {
"file_name": "share/steel/examples/pulse/dice/cbor/CBOR.Spec.Map.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 538,
"start_col": 0,
"start_line": 468
} | (*
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 CBOR.Spec.Map
include CBOR.Spec.Type
let rec list_for_all_weaken
(#t: Type)
(p1: t -> bool)
(p2: t -> bool { forall x . p1 x ==> p2 x })
(l: list t)
: Lemma
(requires (List.Tot.for_all p1 l))
(ensures (List.Tot.for_all p2 l))
= match l with
| [] -> ()
| _ :: q -> list_for_all_weaken p1 p2 q
let rec list_sorted_cons_elim
(#t1: Type)
(key_order: t1 -> t1 -> bool {
forall x y z . (key_order x y /\ key_order y z) ==> key_order x z
})
(a: t1)
(q: list t1)
: Lemma
(requires (List.Tot.sorted key_order (a :: q)))
(ensures (List.Tot.for_all (key_order a) q))
(decreases q)
= match q with
| [] -> ()
| b :: r ->
list_sorted_cons_elim key_order b r;
list_for_all_weaken (key_order b) (key_order a) r
let rec list_sorted_map_entry_order_lt_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
(k: t1)
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l) /\ List.Tot.memP k (List.Tot.map fst l)))
(ensures (key_order (fst a) k))
(decreases l)
= let b :: q = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == fst b)
then ()
else list_sorted_map_entry_order_lt_tail key_order b q k
let list_sorted_map_entry_order_not_memP_tail
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(a: (t1 & t2))
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) (a :: l)))
(ensures (~ (List.Tot.memP (fst a) (List.Tot.map fst l))))
= Classical.move_requires (list_sorted_map_entry_order_lt_tail key_order a l) (fst a)
let rec list_sorted_map_entry_order_no_repeats
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool {
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z)
})
(l: list (t1 & t2))
: Lemma
(requires (List.Tot.sorted (map_entry_order key_order _) l))
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l)))
= match l with
| [] -> ()
| a :: q ->
list_sorted_map_entry_order_no_repeats key_order q;
list_sorted_map_entry_order_not_memP_tail key_order a q
let rec list_tot_for_all_order_trans
(#t1: Type)
(order: t1 -> t1 -> bool {
(forall x . order x x == false) /\
(forall x y z . (order x y /\ order y z) ==> order x z)
})
(k1v1: _)
(k2v2: _)
(l1: list t1)
: Lemma
(requires (order k1v1 k2v2 /\
List.Tot.for_all (order k2v2) l1
))
(ensures (
List.Tot.for_all (order k1v1) l1
))
(decreases l1)
= match l1 with
| [] -> ()
| _ :: q -> list_tot_for_all_order_trans order k1v1 k2v2 q
let rec list_ghost_assoc
(#key: Type)
(#value: Type)
(k: key)
(m: list (key & value))
: GTot (option value)
(decreases m)
= match m with
| [] -> None
| (k', v') :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then Some v'
else list_ghost_assoc k m'
let rec list_ghost_assoc_append
(#tk #tv: Type)
(k: tk)
(l1 l2: list (tk & tv))
: Lemma
(ensures (list_ghost_assoc k (l1 `List.Tot.append` l2) == (
match list_ghost_assoc k l1 with
| Some v -> Some v
| None -> list_ghost_assoc k l2
)))
(decreases l1)
= match l1 with
| [] -> ()
| (k1, _ ) :: q1 ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k1)
then ()
else list_ghost_assoc_append k q1 l2
let rec list_ghost_assoc_mem_intro
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (list_ghost_assoc k l == Some v))
(ensures (List.Tot.memP (k, v) l))
(decreases l)
= let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_mem_intro k v l'
let rec list_ghost_assoc_no_repeats_mem_elim
(#tk #tv: Type)
(k: tk)
(v: tv)
(l: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l) /\
List.Tot.memP (k, v) l
))
(ensures (list_ghost_assoc k l == Some v))
(decreases l)
= List.Tot.memP_map_intro fst (k, v) l;
let (k', v') :: l' = l in
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then
if FStar.StrongExcludedMiddle.strong_excluded_middle (v == v')
then ()
else List.Tot.memP_map_intro fst (k, v) l'
else list_ghost_assoc_no_repeats_mem_elim k v l'
let list_ghost_assoc_no_repeats_mem
(#tk #tv: Type)
(l: list (tk & tv))
(k: tk)
(v: tv)
: Lemma
(ensures (List.Tot.no_repeats_p (List.Tot.map fst l) ==> (list_ghost_assoc k l == Some v <==> List.Tot.memP (k, v) l)))
= Classical.move_requires (list_ghost_assoc_no_repeats_mem_elim k v) l;
Classical.move_requires (list_ghost_assoc_mem_intro k v) l
let list_ghost_assoc_no_repeats_equiv'
(#tk #tv: Type)
(l1 l2: list (tk & tv))
(k: tk)
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (list_ghost_assoc k l1 == list_ghost_assoc k l2))
= match list_ghost_assoc k l1 with
| None ->
begin match list_ghost_assoc k l2 with
| None -> ()
| Some v ->
list_ghost_assoc_no_repeats_mem l2 k v;
list_ghost_assoc_no_repeats_mem l1 k v
end
| Some v ->
list_ghost_assoc_no_repeats_mem l1 k v;
list_ghost_assoc_no_repeats_mem l2 k v
let list_ghost_assoc_no_repeats_equiv
(#tk #tv: Type)
(l1 l2: list (tk & tv))
: Lemma
(requires (
List.Tot.no_repeats_p (List.Tot.map fst l1) /\
List.Tot.no_repeats_p (List.Tot.map fst l2) /\
(forall kv . List.Tot.memP kv l1 <==> List.Tot.memP kv l2)
))
(ensures (forall k . list_ghost_assoc k l1 == list_ghost_assoc k l2))
= Classical.forall_intro (Classical.move_requires (list_ghost_assoc_no_repeats_equiv' l1 l2))
[@@noextract_to "krml"] noextract
let rec map_sort_merge
(#t1 #t2: Type)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Tot (bool & list (t1 & t2))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| (k1, v1) :: l1', (k2, v2) :: l2' ->
begin let c = key_compare k1 k2 in
if c = 0
then (false, accu `List.Tot.append` (l1 `List.Tot.append` l2))
else if c < 0
then map_sort_merge key_compare (accu `List.Tot.append` [(k1, v1)]) l1' l2
else
map_sort_merge key_compare (accu `List.Tot.append` [(k2, v2)]) l1 l2'
// TODO in this case:
// 1. prove that the sort is stable, i.e. that the maps are extensionally equal throughout
// 2. extract and swap the whole prefix of l2 less than the head of l1, rather than just the head of l2
end
| [], _ -> (true, accu `List.Tot.append` l2)
| _, [] -> (true, accu `List.Tot.append` l1)
let rec list_sorted_append_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2: list t)
: Lemma
(requires (List.Tot.sorted order (l1 `List.Tot.append` l2)))
(ensures (
List.Tot.sorted order l1 /\
List.Tot.sorted order l2
))
(decreases l1)
= match l1 with
| [] -> ()
| [_] -> ()
| a :: b :: q ->
list_sorted_append_elim order (b :: q) l2
let rec list_sorted_append_chunk_intro
(#t: Type)
(order: t -> t -> bool)
(l1 l2 l3: list t)
: Lemma
(requires (
List.Tot.sorted order (l1 `List.Tot.append` l2) /\
List.Tot.sorted order (l2 `List.Tot.append` l3) /\
Cons? l2
))
(ensures (
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))
))
(decreases l1)
= match l1 with
| [] -> ()
| [a] -> () // because of List.Tot.sorted (l2 `List.Tot.append` l3) and Cons? l2
| a :: l1' -> list_sorted_append_chunk_intro order l1' l2 l3
let rec list_sorted_order_elim
(#t: Type)
(order: t -> t -> bool)
(l0: list t)
(a1: t)
(l1: list t)
(a2: t)
(l2: list t)
: Lemma
(requires (
(forall x y z . (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l0 `List.Tot.append` (a1 :: (l1 `List.Tot.append` (a2 :: l2))))
))
(ensures (order a1 a2 == true))
(decreases (List.Tot.length l0 + List.Tot.length l1))
= match l0 with
| [] ->
begin match l1 with
| [] -> ()
| a1' :: l1' ->
list_sorted_order_elim order [] a1' l1' a2 l2 // and transitivity
end
| a0 :: l0' ->
list_sorted_order_elim order l0' a1 l1 a2 l2
let rec list_sorted_append_chunk_elim
(#t: Type)
(order: t -> t -> bool)
(l1 l2 l3: list t)
: Lemma
(requires (
(forall x y z . (order x y /\ order y z) ==> order x z) /\
List.Tot.sorted order (l1 `List.Tot.append` (l2 `List.Tot.append` l3))
))
(ensures (
List.Tot.sorted order (l1 `List.Tot.append` l3)
))
(decreases l1)
= match l1 with
| [] -> list_sorted_append_elim order l2 l3
| [a] ->
begin match l3 with
| [] -> ()
| b :: q ->
list_sorted_append_elim order l2 l3;
list_sorted_order_elim order [] a l2 b q
end
| _ :: l1' -> list_sorted_append_chunk_elim order l1' l2 l3
let rec map_sort_merge_correct
(#t1 #t2: Type)
(key_order: t1 -> t1 -> bool)
(key_compare: t1 -> t1 -> int)
(accu: list (t1 & t2))
(l1: list (t1 & t2))
(l2: list (t1 & t2))
: Lemma
(requires (
(forall x . key_order x x == false) /\
(forall x y z . (key_order x y /\ key_order y z) ==> key_order x z) /\
(forall x y . key_order x y == (key_compare x y < 0)) /\
(forall x y . key_compare x y == 0 <==> x == y) /\
(forall x y . (key_compare x y < 0 <==> key_compare y x > 0)) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l1) /\
List.Tot.sorted (map_entry_order key_order _) (accu `List.Tot.append` l2)
))
(ensures (
let (sorted, res) = map_sort_merge key_compare accu l1 l2 in
(forall x . List.Tot.memP x res <==> List.Tot.memP x (accu `List.Tot.append` (l1 `List.Tot.append` l2))) /\
(List.Tot.no_repeats_p (List.Tot.map fst res) <==> List.Tot.no_repeats_p (List.Tot.map fst (accu `List.Tot.append` (l1 `List.Tot.append` l2)))) /\
(if sorted
then List.Tot.sorted (map_entry_order key_order _) res
else ~ (List.Tot.no_repeats_p (List.Tot.map fst res))
)
))
(decreases (List.Tot.length l1 + List.Tot.length l2))
= match l1, l2 with
| [], _ -> ()
| _, [] -> List.Tot.append_l_nil l1
| (k1, v1) :: l1', (k2, v2) :: l2' ->
List.Tot.map_append fst l1 l2;
List.Tot.map_append fst accu (l1 `List.Tot.append` l2);
let c = key_compare k1 k2 in
if c = 0
then
List.Tot.no_repeats_p_false_intro (List.Tot.map fst accu) [k1] (List.Tot.map fst l1') (List.Tot.map fst l2')
else if c < 0
then begin
let accu' = accu `List.Tot.append` [(k1, v1)] in
List.Tot.append_assoc accu l1 l2;
List.Tot.append_assoc accu [(k1, v1)] l1';
List.Tot.append_assoc accu' l1' l2;
List.Tot.append_assoc accu [(k1, v1)] l2;
list_sorted_append_elim (map_entry_order key_order _) accu' l1';
list_sorted_append_elim (map_entry_order key_order _) accu l2;
list_sorted_append_chunk_intro (map_entry_order key_order _) accu [(k1, v1)] l2;
map_sort_merge_correct key_order key_compare accu' l1' l2
end
else begin
let accu' = accu `List.Tot.append` [(k2, v2)] in
List.Tot.append_memP_forall l1 l2;
List.Tot.append_memP_forall accu (l1 `List.Tot.append` l2);
List.Tot.append_memP_forall accu [(k2, v2)];
List.Tot.append_memP_forall l1 l2';
List.Tot.append_memP_forall accu' (l1 `List.Tot.append` l2');
List.Tot.no_repeats_p_append_permut (List.Tot.map fst accu) [k2] (List.Tot.map fst l1) [] (List.Tot.map fst l2');
List.Tot.append_assoc (List.Tot.map fst accu) [k2] (List.Tot.map fst l1 `List.Tot.append` List.Tot.map fst l2');
List.Tot.map_append fst accu [(k2, v2)];
List.Tot.map_append fst l1 l2';
List.Tot.map_append fst accu' (l1 `List.Tot.append` l2');
List.Tot.append_assoc accu [(k2, v2)] l2';
list_sorted_append_elim (map_entry_order key_order _) accu' l2';
list_sorted_append_elim (map_entry_order key_order _) accu l1;
list_sorted_append_chunk_intro (map_entry_order key_order _) accu [(k2, v2)] l1;
List.Tot.append_assoc accu [(k2, v2)] l1;
map_sort_merge_correct key_order key_compare accu' l1 l2'
end
let rec list_splitAt_length
(#t: Type)
(n: nat)
(l: list t)
: Lemma
(requires (List.Tot.length l >= n))
(ensures (
let (l1, l2) = List.Tot.splitAt n l in
List.Tot.length l1 == n /\
List.Tot.length l1 + List.Tot.length l2 == List.Tot.length l
))
[SMTPat (List.Tot.splitAt n l)]
= if n = 0 then () else list_splitAt_length (n - 1) (List.Tot.tl l)
let rec list_splitAt_append
(#t: Type)
(n: nat)
(l: list t)
: Lemma
(ensures (let (l1, l2) = List.Tot.splitAt n l in
l == l1 `List.Tot.append` l2
))
[SMTPat (List.Tot.splitAt n l)]
= match l with
| [] -> ()
| a :: q ->
if n = 0 then () else list_splitAt_append (n - 1) q
[@@noextract_to "krml"] noextract
let rec map_sort
(#t1 #t2: Type)
(key_compare: t1 -> t1 -> int)
(l: list (t1 & t2))
: Tot (bool & list (t1 & t2))
(decreases (List.Tot.length l))
= let len = List.Tot.length l in
if len < 2
then (true, l)
else
let (l1, l2) = List.Tot.splitAt (len / 2) l in
let (res, l1') = map_sort key_compare l1 in
if not res
then (false, l1' `List.Tot.append` l2)
else
let (res, l2') = map_sort key_compare l2 in
if not res
then (false, l1' `List.Tot.append` l2')
else map_sort_merge key_compare [] l1' l2'
let list_memP_map_forall
(#t1 #t2: Type)
(f: t1 -> t2)
(l: list t1)
: Lemma
(forall y . List.Tot.memP y (List.Tot.map f l) <==> (exists x . List.Tot.memP x l /\ y == f x))
= Classical.forall_intro (fun y -> List.Tot.memP_map_elim f y l);
Classical.forall_intro (fun x -> List.Tot.memP_map_intro f x l)
#push-options "--z3rlimit 16" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked",
"CBOR.Spec.Type.fsti.checked"
],
"interface_file": false,
"source_file": "CBOR.Spec.Map.fst"
} | [
{
"abbrev": false,
"full_module": "CBOR.Spec.Type",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "CBOR.Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
key_order: (_: t1 -> _: t1 -> Prims.bool) ->
key_compare: (_: t1 -> _: t1 -> Prims.int) ->
l: Prims.list (t1 * t2)
-> FStar.Pervasives.Lemma
(requires
(forall (x: t1). key_order x x == false) /\
(forall (x: t1) (y: t1) (z: t1). key_order x y /\ key_order y z ==> key_order x z) /\
(forall (x: t1) (y: t1). key_order x y == (key_compare x y < 0)) /\
(forall (x: t1) (y: t1). key_compare x y == 0 <==> x == y) /\
(forall (x: t1) (y: t1). key_compare x y < 0 <==> key_compare y x > 0))
(ensures
(let _ = CBOR.Spec.Map.map_sort key_compare l in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ res l' = _ in
(forall (x: (t1 * t2)). FStar.List.Tot.Base.memP x l' <==> FStar.List.Tot.Base.memP x l) /\
(FStar.List.Tot.Base.no_repeats_p (FStar.List.Tot.Base.map FStar.Pervasives.Native.fst
l') <==>
FStar.List.Tot.Base.no_repeats_p (FStar.List.Tot.Base.map FStar.Pervasives.Native.fst
l)) /\
(res == true <==>
FStar.List.Tot.Base.no_repeats_p (FStar.List.Tot.Base.map FStar.Pervasives.Native.fst
l)) /\
(res == true ==>
FStar.List.Tot.Properties.sorted (CBOR.Spec.Type.map_entry_order key_order t2) l' /\
(forall (k: t1).
CBOR.Spec.Map.list_ghost_assoc k l' == CBOR.Spec.Map.list_ghost_assoc k l)))
<:
Type0))
(decreases FStar.List.Tot.Base.length l) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.bool",
"Prims.int",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.op_LessThan",
"Prims.op_Negation",
"Prims._assert",
"Prims.l_Forall",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"CBOR.Spec.Map.list_ghost_assoc",
"Prims.unit",
"CBOR.Spec.Map.list_ghost_assoc_no_repeats_equiv",
"CBOR.Spec.Map.list_sorted_map_entry_order_no_repeats",
"Prims.b2t",
"FStar.List.Tot.Properties.sorted",
"CBOR.Spec.Type.map_entry_order",
"Prims.l_iff",
"FStar.List.Tot.Base.no_repeats_p",
"FStar.List.Tot.Base.map",
"FStar.Pervasives.Native.fst",
"FStar.List.Tot.Base.memP",
"Prims.l_or",
"CBOR.Spec.Map.map_sort_merge_correct",
"Prims.Nil",
"CBOR.Spec.Map.map_sort",
"FStar.Pervasives.Native.Mktuple2",
"CBOR.Spec.Map.map_sort_merge",
"FStar.List.Tot.Properties.append_memP_forall",
"FStar.List.Tot.Properties.map_append",
"FStar.List.Tot.Properties.no_repeats_p_append",
"CBOR.Spec.Map.list_memP_map_forall",
"CBOR.Spec.Map.map_sort_correct",
"FStar.List.Tot.Base.splitAt",
"Prims.op_Division",
"Prims.nat",
"FStar.List.Tot.Base.length",
"Prims.l_and",
"Prims.l_imp",
"Prims.op_GreaterThan",
"Prims.squash",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec map_sort_correct
(#t1 #t2: Type)
(key_order: (t1 -> t1 -> bool))
(key_compare: (t1 -> t1 -> int))
(l: list (t1 & t2))
: Lemma
(requires
((forall x. key_order x x == false) /\
(forall x y z. (key_order x y /\ key_order y z) ==> key_order x z) /\
(forall x y. key_order x y == (key_compare x y < 0)) /\
(forall x y. key_compare x y == 0 <==> x == y) /\
(forall x y. (key_compare x y < 0 <==> key_compare y x > 0))))
(ensures
(let res, l' = map_sort key_compare l in
(forall x. List.Tot.memP x l' <==> List.Tot.memP x l) /\
(List.Tot.no_repeats_p (List.Tot.map fst l') <==>
List.Tot.no_repeats_p (List.Tot.map fst l)) /\
(res == true <==> List.Tot.no_repeats_p (List.Tot.map fst l)) /\
(res == true ==>
(List.Tot.sorted (map_entry_order key_order _) l' /\
(forall k. list_ghost_assoc k l' == list_ghost_assoc k l)))))
(decreases (List.Tot.length l)) =
| let len = List.Tot.length l in
if len < 2
then ()
else
let l1, l2 = List.Tot.splitAt (len / 2) l in
List.Tot.append_memP_forall l1 l2;
List.Tot.map_append fst l1 l2;
List.Tot.no_repeats_p_append (List.Tot.map fst l1) (List.Tot.map fst l2);
List.Tot.append_memP_forall (List.Tot.map fst l1) (List.Tot.map fst l2);
list_memP_map_forall fst l1;
list_memP_map_forall fst l2;
let res, l1' = map_sort key_compare l1 in
map_sort_correct key_order key_compare l1;
list_memP_map_forall fst l1';
List.Tot.append_memP_forall (List.Tot.map fst l1') (List.Tot.map fst l2);
List.Tot.no_repeats_p_append (List.Tot.map fst l1') (List.Tot.map fst l2);
List.Tot.map_append fst l1' l2;
List.Tot.append_memP_forall l1' l2;
if not res
then ()
else
let res, l2' = map_sort key_compare l2 in
map_sort_correct key_order key_compare l2;
list_memP_map_forall fst l2';
List.Tot.append_memP_forall (List.Tot.map fst l1') (List.Tot.map fst l2');
List.Tot.no_repeats_p_append (List.Tot.map fst l1') (List.Tot.map fst l2');
List.Tot.map_append fst l1' l2';
List.Tot.append_memP_forall l1' l2';
if not res
then ()
else
let res, l' = map_sort_merge key_compare [] l1' l2' in
assert (map_sort key_compare l == (res, l'));
map_sort_merge_correct key_order key_compare [] l1' l2';
assert (forall x. List.Tot.memP x l' <==> (List.Tot.memP x l1' \/ List.Tot.memP x l2'));
assert (forall x. List.Tot.memP x l' <==> List.Tot.memP x l);
assert (List.Tot.no_repeats_p (List.Tot.map fst l') <==>
List.Tot.no_repeats_p (List.Tot.map fst l));
if res
then
(assert (List.Tot.sorted (map_entry_order key_order _) l');
list_sorted_map_entry_order_no_repeats key_order l';
list_ghost_assoc_no_repeats_equiv l l';
assert (forall k. list_ghost_assoc k l' == list_ghost_assoc k l)) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_nondep_correct1 | val compute_gen_elim_nondep_correct1 (i0: gen_elim_i) (t1: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1]) | val compute_gen_elim_nondep_correct1 (i0: gen_elim_i) (t1: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1]) | let compute_gen_elim_nondep_correct1
(i0: gen_elim_i)
(t1: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> q x1 (U.raise_val ()) `star` pure (post x1 (U.raise_val ()))));
let res = elim_exists' () in
elim_pure _;
rewrite_with_trefl (q _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res | {
"file_name": "lib/steel/Steel.ST.GenElim1.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 7,
"end_line": 497,
"start_col": 0,
"start_line": 487
} | module Steel.ST.GenElim1
let gen_elim_f
(p: vprop)
(a: Type)
(q: (a -> vprop))
(post: (a -> prop))
: Tot Type
= ((opened: inames) -> STGhost a opened p q True post)
module U = FStar.Universe
let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type =
gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i)
let compute_gen_unit_elim_f_id
(v: vprop)
: Tot (gen_unit_elim_t (GUEId v))
= fun _ -> noop (); U.raise_val ()
let compute_gen_unit_elim_f_pure
(p: prop)
: Tot (gen_unit_elim_t (GUEPure p))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p);
elim_pure p;
U.raise_val ()
let compute_gen_unit_elim_f_star
(i1 i2: gen_unit_elim_i)
(f1: gen_unit_elim_t i1)
(f2: gen_unit_elim_t i2)
: Tot (gen_unit_elim_t (GUEStar i1 i2))
= fun _ ->
rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2);
let _ = f1 _ in
let _ = f2 _ in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2));
U.raise_val ()
let rec compute_gen_unit_elim_f
(i: gen_unit_elim_i)
: GTot (gen_unit_elim_t i)
= match i returns (gen_unit_elim_t i) with
| GUEId v -> compute_gen_unit_elim_f_id v
| GUEPure p -> compute_gen_unit_elim_f_pure p
| GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2)
let gen_elim_t (i: gen_elim_i) : Tot Type =
gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i)
let compute_gen_elim_f_unit
(i: gen_unit_elim_i)
: GTot (gen_elim_t (GEUnit i))
= compute_gen_unit_elim_f i
let compute_gen_elim_f_star_l
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_unit_elim_i)
: GTot (gen_elim_t (GEStarL i1 i2))
= let f2 = compute_gen_unit_elim_f i2 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2);
let res = f1 _ in
let _ = f2 _ in
let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res');
res'
let compute_gen_elim_f_star_r
(i1: gen_unit_elim_i)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStarR i1 i2))
= let f1 = compute_gen_unit_elim_f i1 in
fun _ ->
rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2);
let _ = f1 _ in
let res = f2 _ in
let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in
rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res');
res'
let compute_gen_elim_f_star
(i1: gen_elim_i)
(f1: gen_elim_t i1)
(i2: gen_elim_i)
(f2: gen_elim_t i2)
: GTot (gen_elim_t (GEStar i1 i2))
= fun _ ->
rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2);
let res1 = f1 _ in
let res2 = f2 _ in
let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in
rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res);
res
let compute_gen_elim_f_exists_no_abs0
(a: Type0)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs0 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res);
res
let rewrite_with_trefl (#opened:_) (p q:vprop)
: STGhost unit opened
p
(fun _ -> q)
(requires T.with_tactic T.trefl (p == q))
(ensures fun _ -> True)
= rewrite p q
let compute_gen_elim_f_exists_unit0
(a: Type0)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res);
res
let compute_gen_elim_f_exists0
(a: Type0)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists0 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res);
res
let compute_gen_elim_f_exists_no_abs1
(a: Type)
(body: (a -> vprop))
: GTot (gen_elim_t (GEExistsNoAbs1 body))
= fun _ ->
rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body);
let gres = elim_exists () in
let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res);
res
let compute_gen_elim_f_exists_unit1
(a: Type)
(body: a -> gen_unit_elim_i)
: Tot (gen_elim_t (GEExistsUnit1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let gres = elim_exists () in
let _ = compute_gen_unit_elim_f (body gres) _ in
let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in
rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res);
res
let compute_gen_elim_f_exists1
(a: Type)
(body: a -> gen_elim_i)
(f: (x: a) -> GTot (gen_elim_t (body x)))
: Tot (gen_elim_t (GEExists1 body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x)));
let gres1 = elim_exists () in
let gres2 = f gres1 _ in
let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in
rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res);
res
let rec compute_gen_elim_f
(i: gen_elim_i)
: GTot (gen_elim_t i)
= match i returns (gen_elim_t i) with
| GEUnit i -> compute_gen_elim_f_unit i
| GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2
| GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2)
| GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2)
| GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body
| GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body
| GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x))
| GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body
| GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body
| GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x))
let rec tele_p (x: gen_elim_tele) : Tot vprop =
match x with
| TRet v p -> v `star` pure p
| TExists ty body -> exists_ (fun x -> tele_p (body x))
let elim_exists' (#a:Type)
(#opened_invariants:_)
(#p:a -> vprop)
(_:unit)
: STGhostT (a) opened_invariants
(exists_ p)
(fun x -> p x)
= let gx = elim_exists () in
let x = Ghost.reveal gx in
rewrite (p gx) (p x);
x
let vprop_rewrite (from to: vprop) : Tot Type =
gen_elim_f from unit (fun _ -> to) (fun _ -> True)
let tele_star_vprop_correct_ret
(v': vprop) (p': prop) (v: vprop) (p: prop)
: Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p)))
= fun _ ->
elim_pure p;
rewrite (tele_p _) (v' `star` pure p');
elim_pure p';
intro_pure (p /\ p');
rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _)
let tele_star_vprop_correct_exists
(v: vprop) (p: prop)
(ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p))))
: Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p)))
= fun _ ->
rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p));
rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _)
let rec tele_star_vprop_correct
(i: gen_elim_tele) (v: vprop) (p: prop)
: GTot (vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p))
)
= match i returns vprop_rewrite
(tele_p i `star` v `star` pure p)
(tele_p (tele_star_vprop i v p)) with
| TRet v' p' -> tele_star_vprop_correct_ret v' p' v p
| TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p)
let tele_star_correct_ret_l
(v1: vprop) (p1: prop) (i2: gen_elim_tele)
: Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2)))
= fun _ ->
rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1);
tele_star_vprop_correct i2 v1 p1 _;
rewrite (tele_p _) (tele_p _)
let tele_star_correct_ret_r
(i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop)
: Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2)))
= fun _ ->
rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2);
tele_star_vprop_correct i1 v2 p2 _;
rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2))
let tele_star_correct_exists
(ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele)
(ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2))))
: Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2))))
= fun _ ->
rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1)));
let x1 = elim_exists' () in
rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2)));
let x2 = elim_exists' () in
ih x1 x2 _;
intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)));
intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec tele_star_correct
(i1 i2: gen_elim_tele)
: GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)))
= match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with
| TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2
| TExists ty1 f1 ->
begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with
| TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2
| TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2))
end
[@@noextract_to "Plugin" ]
let ge_to_tele_t
(i: gen_elim_i)
: Tot Type
= vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i))
let compute_gen_elim_tele_correct_unit
(v: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEUnit v))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v);
let _ = compute_gen_unit_elim_f v _ in
intro_pure (compute_gen_unit_elim_post v);
rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _)
let compute_gen_elim_tele_correct_star_l
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(ru: gen_unit_elim_i)
: Tot (ge_to_tele_t (GEStarL l ru))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru);
ihl _;
let _ = compute_gen_unit_elim_f ru _ in
intro_pure (compute_gen_unit_elim_post ru);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star_r
(lu: gen_unit_elim_i)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStarR lu r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r);
ihr _;
let _ = compute_gen_unit_elim_f lu _ in
intro_pure (compute_gen_unit_elim_post lu);
tele_star_vprop_correct _ _ _ _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_star
(l: gen_elim_i)
(ihl: ge_to_tele_t l)
(r: gen_elim_i)
(ihr: ge_to_tele_t r)
: Tot (ge_to_tele_t (GEStar l r))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r);
ihl _;
ihr _;
tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _;
rewrite_with_trefl (tele_p _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs0
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
rewrite (body x) (body (U.downgrade_val (U.raise_val x)));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit0
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x))));
rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists0
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists0 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x)))));
intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x))));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_no_abs1
(ty: _)
(body: ty -> vprop)
: Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ body);
let x = elim_exists' () in
intro_pure True;
intro_exists x (fun x -> body x `star` pure True);
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists_unit1
(ty: _)
(body: ty -> gen_unit_elim_i)
: Tot (ge_to_tele_t (GEExistsUnit1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x)));
let x = elim_exists' () in
let _ = compute_gen_unit_elim_f (body x) _ in
intro_pure (compute_gen_unit_elim_post (body x));
intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let compute_gen_elim_tele_correct_exists1
(ty: _)
(body: ty -> gen_elim_i)
(ih: (x: ty) -> GTot (ge_to_tele_t (body x)))
: Tot (ge_to_tele_t (GEExists1 #ty body))
= fun _ ->
rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x)));
let x = elim_exists' () in
ih x _;
intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x)));
rewrite_with_trefl (exists_ _) (tele_p _)
let rec compute_gen_elim_tele_correct
(x: gen_elim_i)
: GTot (ge_to_tele_t x)
= match x returns ge_to_tele_t x with
| GEUnit v -> compute_gen_elim_tele_correct_unit v
| GEStarL l ru -> compute_gen_elim_tele_correct_star_l l (compute_gen_elim_tele_correct l) ru
| GEStarR lu r -> compute_gen_elim_tele_correct_star_r lu r (compute_gen_elim_tele_correct r)
| GEStar l r -> compute_gen_elim_tele_correct_star l (compute_gen_elim_tele_correct l) r (compute_gen_elim_tele_correct r)
| GEExistsNoAbs0 #ty body -> compute_gen_elim_tele_correct_exists_no_abs0 ty body
| GEExistsUnit0 #ty body -> compute_gen_elim_tele_correct_exists_unit0 ty body
| GEExists0 #ty body -> compute_gen_elim_tele_correct_exists0 ty body (fun x -> compute_gen_elim_tele_correct (body x))
| GEExistsNoAbs1 #ty body -> compute_gen_elim_tele_correct_exists_no_abs1 ty body
| GEExistsUnit1 #ty body -> compute_gen_elim_tele_correct_exists_unit1 ty body
| GEExists1 #ty body -> compute_gen_elim_tele_correct_exists1 ty body (fun x -> compute_gen_elim_tele_correct (body x))
let rec gen_elim_nondep_p (ty: list (Type u#a)) : Tot (curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop) =
match ty as ty' returns curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop with
| [] -> fun q post -> q (U.raise_val ()) `star` pure (post (U.raise_val ()))
| t :: tq -> fun q post -> exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x))
let rec gen_elim_nondep_sem_correct
(ty: list (Type u#a))
: Tot ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
= match ty returns ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma
(tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post)
)
with
| [] -> fun q post -> equiv_refl (q (U.raise_val ()) `star` pure (post (U.raise_val ())))
| ta :: tq -> fun q post ->
let phi
(x: ta)
: Lemma
(tele_p (gen_elim_nondep_sem tq (q x) (post x)) `equiv` gen_elim_nondep_p tq (q x) (post x))
= gen_elim_nondep_sem_correct tq (q x) (post x)
in
Classical.forall_intro phi;
let prf () : Lemma
(exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) `equiv` exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)))
=
exists_equiv (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) (fun x -> gen_elim_nondep_p tq (q x) (post x))
in
assert_norm (tele_p (gen_elim_nondep_sem (ta :: tq) q post) == exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))));
assert_norm (gen_elim_nondep_p (ta :: tq) q post == exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)));
prf ()
let compute_gen_elim_nondep_correct_t
(i0: gen_elim_i)
(ty: list (Type u#1))
: Tot Type
= (q: _) ->
(post: _) ->
(intro: vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post)) ->
GTot (gen_elim_f
(compute_gen_elim_p i0)
(compute_gen_elim_nondep_a' ty)
(fun x -> compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) ty q x (U.raise_val ()))
(fun x -> compute_uncurry _ (fun _ -> True) ty post x (U.raise_val ()))
)
let compute_gen_elim_nondep_correct0
(i0: gen_elim_i)
: Tot (compute_gen_elim_nondep_correct_t i0 [])
= fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _) (q (U.raise_val ()) `star` pure (post (U.raise_val ())));
let res = U.raise_val () in
elim_pure _;
rewrite_with_trefl (q (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.GenElim1.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "FStar.Tactics",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Steel.ST.GenElim1.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i0: Steel.ST.GenElim1.Base.gen_elim_i -> t1: Type
-> Steel.ST.GenElim1.compute_gen_elim_nondep_correct_t i0 [t1] | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.GenElim1.Base.gen_elim_i",
"Steel.ST.GenElim1.Base.curried_function_type",
"Prims.Cons",
"Prims.Nil",
"FStar.Universe.raise_t",
"Prims.unit",
"Steel.Effect.Common.vprop",
"Prims.prop",
"Steel.ST.GenElim1.vprop_rewrite",
"Steel.ST.GenElim1.Base.compute_gen_elim_p",
"Steel.ST.GenElim1.gen_elim_nondep_p",
"Steel.Memory.inames",
"Steel.ST.GenElim1.Base.compute_gen_elim_nondep_a'",
"Steel.ST.GenElim1.rewrite_with_trefl",
"FStar.Universe.raise_val",
"Steel.ST.GenElim1.Base.compute_uncurry",
"Steel.ST.GenElim1.Base.compute_gen_elim_p'",
"Steel.ST.Util.elim_pure",
"Steel.ST.GenElim1.elim_exists'",
"Steel.Effect.Common.VStar",
"Steel.ST.Util.pure",
"Steel.ST.Util.exists_",
"Steel.Effect.Common.star",
"Steel.ST.GenElim1.compute_gen_elim_nondep_correct_t"
] | [] | false | false | false | false | false | let compute_gen_elim_nondep_correct1 (i0: gen_elim_i) (t1: Type)
: Tot (compute_gen_elim_nondep_correct_t i0 [t1]) =
| fun q post intro _ ->
intro _;
rewrite_with_trefl (gen_elim_nondep_p _ _ _)
(exists_ (fun x1 -> (q x1 (U.raise_val ())) `star` (pure (post x1 (U.raise_val ())))));
let res = elim_exists' () in
elim_pure _;
rewrite_with_trefl (q _ (U.raise_val ()))
(compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ()));
res | false |
Steel.Primitive.ForkJoin.fst | Steel.Primitive.ForkJoin.maybe_p | val maybe_p : p: Steel.Effect.Common.vprop -> v: Prims.bool -> Steel.Effect.Common.vprop | let maybe_p (p:vprop) (v:bool) = if v then p else emp | {
"file_name": "lib/steel/Steel.Primitive.ForkJoin.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 53,
"end_line": 28,
"start_col": 0,
"start_line": 28
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Primitive.ForkJoin
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module L = Steel.SpinLock
open Steel.FractionalPermission
open Steel.Reference
//////////////////////////////////////////////////////////////////////////////// | {
"checked_file": "/",
"dependencies": [
"Steel.SpinLock.fsti.checked",
"Steel.Reference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Primitive.ForkJoin.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.SpinLock",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Primitive",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Primitive",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: Steel.Effect.Common.vprop -> v: Prims.bool -> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"Steel.Effect.Common.vprop",
"Prims.bool",
"Steel.Effect.Common.emp"
] | [] | false | false | false | true | false | let maybe_p (p: vprop) (v: bool) =
| if v then p else emp | false |
|
Steel.Primitive.ForkJoin.fst | Steel.Primitive.ForkJoin.lock_inv_pred | val lock_inv_pred (r: ref bool) (p: vprop) (v: bool) : vprop | val lock_inv_pred (r: ref bool) (p: vprop) (v: bool) : vprop | let lock_inv_pred (r:ref bool) (p:vprop) (v:bool) : vprop =
pts_to r full_perm v `star` maybe_p p v | {
"file_name": "lib/steel/Steel.Primitive.ForkJoin.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 41,
"end_line": 32,
"start_col": 0,
"start_line": 31
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Primitive.ForkJoin
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module L = Steel.SpinLock
open Steel.FractionalPermission
open Steel.Reference
////////////////////////////////////////////////////////////////////////////////
let maybe_p (p:vprop) (v:bool) = if v then p else emp | {
"checked_file": "/",
"dependencies": [
"Steel.SpinLock.fsti.checked",
"Steel.Reference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Primitive.ForkJoin.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.SpinLock",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Primitive",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Primitive",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: Steel.Reference.ref Prims.bool -> p: Steel.Effect.Common.vprop -> v: Prims.bool
-> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"Steel.Reference.ref",
"Prims.bool",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.star",
"Steel.Reference.pts_to",
"Steel.FractionalPermission.full_perm",
"Steel.Primitive.ForkJoin.maybe_p"
] | [] | false | false | false | true | false | let lock_inv_pred (r: ref bool) (p: vprop) (v: bool) : vprop =
| (pts_to r full_perm v) `star` (maybe_p p v) | false |
Steel.Primitive.ForkJoin.fst | Steel.Primitive.ForkJoin.lock_inv | val lock_inv (r: ref bool) (p: vprop) : vprop | val lock_inv (r: ref bool) (p: vprop) : vprop | let lock_inv (r:ref bool) (p:vprop)
: vprop
= h_exists (lock_inv_pred r p) | {
"file_name": "lib/steel/Steel.Primitive.ForkJoin.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 32,
"end_line": 36,
"start_col": 0,
"start_line": 34
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Primitive.ForkJoin
open FStar.Ghost
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
module L = Steel.SpinLock
open Steel.FractionalPermission
open Steel.Reference
////////////////////////////////////////////////////////////////////////////////
let maybe_p (p:vprop) (v:bool) = if v then p else emp
[@@__reduce__]
let lock_inv_pred (r:ref bool) (p:vprop) (v:bool) : vprop =
pts_to r full_perm v `star` maybe_p p v | {
"checked_file": "/",
"dependencies": [
"Steel.SpinLock.fsti.checked",
"Steel.Reference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Primitive.ForkJoin.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.Reference",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.SpinLock",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Primitive",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Primitive",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: Steel.Reference.ref Prims.bool -> p: Steel.Effect.Common.vprop -> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"Steel.Reference.ref",
"Prims.bool",
"Steel.Effect.Common.vprop",
"Steel.Effect.Atomic.h_exists",
"Steel.Primitive.ForkJoin.lock_inv_pred"
] | [] | false | false | false | true | false | let lock_inv (r: ref bool) (p: vprop) : vprop =
| h_exists (lock_inv_pred r p) | false |
MerkleTree.New.High.Correct.Rhs.fst | MerkleTree.New.High.Correct.Rhs.construct_rhs_acc_consistent | val construct_rhs_acc_consistent:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv)} ->
olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
rhs:hashes #hsz {S.length rhs = 32} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures
(log2c_bound j (32 - lv);
mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs;
mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs);
(let rrf = construct_rhs_acc #_ #f j
(S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd in
let rr = construct_rhs #_ #f lv hs rhs i j acc actd in
rhs_equiv #hsz j (fst rrf) (S.slice (fst rr) lv (lv + log2c j)) actd /\
snd rrf == snd rr)))
(decreases j) | val construct_rhs_acc_consistent:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv)} ->
olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
rhs:hashes #hsz {S.length rhs = 32} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures
(log2c_bound j (32 - lv);
mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs;
mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs);
(let rrf = construct_rhs_acc #_ #f j
(S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd in
let rr = construct_rhs #_ #f lv hs rhs i j acc actd in
rhs_equiv #hsz j (fst rrf) (S.slice (fst rr) lv (lv + log2c j)) actd /\
snd rrf == snd rr)))
(decreases j) | let rec construct_rhs_acc_consistent #hsz #f lv i j olds hs rhs acc actd =
assert (j < pow2 (32 - lv));
assert (j <> 0 ==> j / 2 < pow2 (32 - (lv + 1)));
log2c_bound j (32 - lv);
mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs;
mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs);
let rrf = construct_rhs_acc #_ #f j
(S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd in
let rr = construct_rhs #_ #f lv hs rhs i j acc actd in
construct_rhs_unchanged #_ #f lv hs rhs i j acc actd;
assert (S.equal (S.slice rhs 0 lv) (S.slice (fst rr) 0 lv));
if j = 0 then ()
else begin
log2c_div j;
assert (32 - (lv + 1) >= 0);
log2c_bound (j / 2) (32 - (lv + 1));
mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs;
mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) (merge_hs #_ #f olds hs);
if j % 2 = 0 then begin
construct_rhs_acc_consistent #_ #f (lv + 1) (i / 2) (j / 2)
olds hs rhs acc actd;
log2c_bound (j/2) (32 - (lv + 1));
mt_olds_hs_lth_inv_ok #hsz #f (lv+1) (i/2) (j/2) olds hs;
mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs);
let rrf = construct_rhs_acc #_ #f j
(S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd in
let rr = construct_rhs #_ #f lv hs rhs i j acc actd in
assert (rhs_equiv #hsz j (fst rrf) (S.slice (fst rr) lv (lv + log2c j)) actd);
assert (snd rrf == snd rr)
end
else
begin
let rhd = if actd then acc else hash_init in
let nacc = if actd
then f (S.last (S.index hs lv)) acc
else S.last (S.index hs lv) in
assert (S.equal (S.tail (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)))
(S.slice (merge_hs #_ #f olds hs)
(lv + 1) (lv + 1 + log2c (j / 2))));
// Recursion step for `construct_rhs_acc`
let nrrf = construct_rhs_acc #_ #f (j / 2)
(S.slice (merge_hs #_ #f olds hs) (lv + 1) (lv + 1 + (log2c (j / 2))))
nacc true in
construct_rhs_acc_odd #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd;
// Recursion step for `construct_rhs`
assert (hs_wf_elts (lv + 1) hs (i / 2) (j / 2));
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nrr = construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true in
construct_rhs_odd #_ #f lv hs rhs i j acc actd;
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
assert (S.equal (S.slice nrhs 0 (lv + 1)) (S.slice (fst nrr) 0 (lv + 1)));
assert (S.index (fst nrr) lv == S.index nrhs lv);
// Recursion for the proof
construct_rhs_acc_consistent #_ #f (lv + 1) (i / 2) (j / 2)
olds hs nrhs nacc true;
assert (rhs_equiv #hsz (j / 2) (fst nrrf)
(S.slice (fst nrr) (lv + 1) (lv + 1 + log2c (j / 2))) true);
assert (snd nrrf == snd nrr);
// All together
(if actd
then (assert (S.head (fst rrf) == rhd);
assert (rhd == acc);
assert (S.index (fst rr) lv == S.index nrhs lv);
assert (S.index nrhs lv == acc);
assert (S.head (fst rrf) == S.index (fst rr) lv))
else ());
assert (if actd then S.head (fst rrf) == S.index (fst rr) lv else true);
assert (rhs_equiv #hsz (j / 2) (S.tail (fst rrf))
(S.slice (fst rr) (lv + 1) (lv + 1 + log2c (j / 2))) true);
assert (rhs_equiv #hsz j (fst rrf) (S.slice (fst rr) lv (lv + log2c j)) actd);
assert (snd rrf == snd rr)
end
end | {
"file_name": "src/MerkleTree.New.High.Correct.Rhs.fst",
"git_rev": "7d7bdc20f2033171e279c176b26e84f9069d23c6",
"git_url": "https://github.com/hacl-star/merkle-tree.git",
"project_name": "merkle-tree"
} | {
"end_col": 5,
"end_line": 314,
"start_col": 0,
"start_line": 235
} | module MerkleTree.New.High.Correct.Rhs
open FStar.Classical
open FStar.Ghost
open FStar.Seq
module S = FStar.Seq
module MTS = MerkleTree.Spec
open MerkleTree.New.High
open MerkleTree.New.High.Correct.Base
#set-options "--z3rlimit 10 --initial_fuel 1 --max_fuel 1 --initial_ifuel 0 --max_ifuel 0"
/// Correctness of rightmost hashes
// Another version of `construct_rhs` that recursively
// accumulates rightmost hashes.
val construct_rhs_acc:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
j:nat ->
fhs:hashess #hsz {
S.length fhs = log2c j /\
mt_hashes_lth_inv_log #hsz j fhs} ->
acc:hash #hsz ->
actd:bool ->
GTot (rhs:hashes #hsz {S.length rhs = log2c j} * hash #hsz) (decreases j)
let rec construct_rhs_acc #_ #f j fhs acc actd =
if j = 0 then (S.empty, acc)
else begin
if j % 2 = 0
then (let nrhsh = construct_rhs_acc #_ #f(j / 2) (S.tail fhs) acc actd in
(S.cons hash_init (fst nrhsh), snd nrhsh))
else (let rhd = if actd then acc else hash_init in
let nacc = if actd
then f (S.last (S.head fhs)) acc
else S.last (S.head fhs) in
let nrhsh = construct_rhs_acc #_ #f (j / 2) (S.tail fhs) nacc true in
(S.cons rhd (fst nrhsh), snd nrhsh))
end
#push-options "--initial_ifuel 1 --max_ifuel 1"
val construct_rhs_acc_odd:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
j:nat ->
fhs:hashess #hsz {
S.length fhs = log2c j /\
mt_hashes_lth_inv_log #hsz j fhs} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires (j % 2 <> 0))
(ensures (let rrf = construct_rhs_acc #_ #f j fhs acc actd in
let nacc = if actd
then f (S.last (S.head fhs)) acc
else S.last (S.head fhs) in
let nrrf = construct_rhs_acc #_ #f (j / 2) (S.tail fhs) nacc true in
S.equal (S.tail (fst rrf)) (fst nrrf) /\
snd rrf == snd nrrf))
let construct_rhs_acc_odd #_ #f j fhs acc actd = ()
#pop-options
#push-options "--initial_fuel 2 --max_fuel 2"
val construct_rhs_acc_inv_ok_0:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
fhs:hashess #hsz {
S.length fhs = 1 /\
mt_hashes_lth_inv_log #hsz 1 fhs /\
mt_hashes_inv_log #_ #f 1 fhs} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures (let crhs = construct_rhs_acc #_ #f 1 fhs acc actd in
mt_rhs_inv #_ #f 1
(hash_seq_spec_full #_ #f (S.head fhs) acc actd)
(fst crhs) actd /\
MTS.mt_get_root #_ #f #1
(hash_seq_spec_full #_ #f (S.head fhs) acc actd) ==
MTS.HRaw #hsz (snd crhs)))
let construct_rhs_acc_inv_ok_0 #_ #f fhs acc actd = ()
#pop-options
#push-options "--z3rlimit 300"
#restart-solver
val construct_rhs_acc_inv_ok:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
j:nat{j > 0} ->
fhs:hashess #hsz {
S.length fhs = log2c j /\
mt_hashes_lth_inv_log #hsz j fhs /\
mt_hashes_inv_log #_ #f j fhs} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures (let crhs = construct_rhs_acc #_ #f j fhs acc actd in
mt_rhs_inv #_ #f j
(hash_seq_spec_full #_ #f (S.head fhs) acc actd)
(fst crhs) actd /\
MTS.mt_get_root #_ #f #(log2c j)
(hash_seq_spec_full #_ #f (S.head fhs) acc actd) ==
MTS.HRaw (snd crhs)))
(decreases j)
let rec construct_rhs_acc_inv_ok #hsz #f j fhs acc actd =
if j = 1 then
construct_rhs_acc_inv_ok_0 #_ #f fhs acc actd
else if j % 2 = 0 then begin
construct_rhs_acc_inv_ok #_ #f (j / 2) (S.tail fhs) acc actd;
let rcrhs = construct_rhs_acc #_ #f (j / 2) (S.tail fhs) acc actd in
assert (mt_rhs_inv #_ #f (j / 2)
(hash_seq_spec_full #_ #f (S.head (S.tail fhs)) acc actd)
(fst rcrhs) actd);
assert (MTS.mt_get_root #_ #f #(log2c j - 1)
(hash_seq_spec_full #_ #f (S.head (S.tail fhs)) acc actd) ==
MTS.HRaw (snd rcrhs));
let crhs = (S.cons hash_init (fst rcrhs), snd rcrhs) in
mt_hashes_lth_inv_log_next #_ #f j fhs;
hash_seq_spec_full_even_next #_ #f
j (S.head fhs) (S.head (S.tail fhs)) acc actd;
assert (mt_rhs_inv #_ #f (j / 2)
(MTS.mt_next_lv #_ #f #(log2c j)
(hash_seq_spec_full #_ #f (S.head fhs) acc actd))
(fst rcrhs) actd);
assert (mt_rhs_inv #_ #f j
(hash_seq_spec_full #_ #f (S.head fhs) acc actd)
(fst crhs) actd);
assert (MTS.mt_get_root #_ #f #(log2c j)
(hash_seq_spec_full #_ #f (S.head fhs) acc actd) ==
MTS.HRaw (snd rcrhs))
end
else begin
let rhd = if actd then acc else hash_init #hsz in
let nacc = if actd
then f (S.last (S.head fhs)) acc
else S.last (S.head fhs) in
construct_rhs_acc_inv_ok #_ #f (j / 2) (S.tail fhs) nacc true;
let rcrhs = construct_rhs_acc #_ #f (j / 2) (S.tail fhs) nacc true in
assert (mt_rhs_inv #_ #f (j / 2)
(hash_seq_spec_full #_ #f (S.head (S.tail fhs)) nacc true)
(fst rcrhs) true);
assert (MTS.mt_get_root #_ #f #(log2c j - 1)
(hash_seq_spec_full #_ #f (S.head (S.tail fhs)) nacc true) ==
MTS.HRaw (snd rcrhs));
let crhs = (S.cons rhd (fst rcrhs), snd rcrhs) in
mt_hashes_lth_inv_log_next #_ #f j fhs;
hash_seq_spec_full_odd_next #_ #f
j (S.head fhs) (S.head (S.tail fhs)) acc actd nacc;
(if actd then hash_seq_spec_full_case_true #_ #f (S.head fhs) acc);
assert (if actd
then (S.index (hash_seq_spec_full #_ #f (S.head fhs) acc actd) j ==
MTS.HRaw rhd)
else true);
assert (mt_rhs_inv #_ #f (j / 2)
(MTS.mt_next_lv #_ #f #(log2c j)
(hash_seq_spec_full #_ #f (S.head fhs) acc actd))
(fst rcrhs) true);
assert (mt_rhs_inv #_ #f j
(hash_seq_spec_full #_ #f (S.head fhs) acc actd)
(fst crhs) actd);
assert (MTS.mt_get_root #_ #f #(log2c j)
(hash_seq_spec_full #_ #f (S.head fhs) acc actd) ==
MTS.HRaw (snd crhs))
end
#pop-options
val rhs_equiv:
#hsz:pos ->
j:nat ->
rhs1:hashes #hsz {S.length rhs1 = log2c j} ->
rhs2:hashes #hsz {S.length rhs2 = log2c j} ->
actd:bool ->
GTot Type0 (decreases j)
let rec rhs_equiv #hsz j rhs1 rhs2 actd =
if j = 0 then true
else if j % 2 = 0
then rhs_equiv #hsz (j / 2) (S.tail rhs1) (S.tail rhs2) actd
else ((if actd then S.head rhs1 == S.head rhs2 else true) /\
rhs_equiv #hsz (j / 2) (S.tail rhs1) (S.tail rhs2) true)
val rhs_equiv_inv_preserved:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
j:nat ->
smt:MTS.merkle_tree (log2c j) ->
rhs1:hashes #hsz {S.length rhs1 = log2c j} ->
rhs2:hashes #hsz {S.length rhs2 = log2c j} ->
actd:bool ->
Lemma (requires (mt_rhs_inv #_ #f j smt rhs1 actd /\
rhs_equiv #hsz j rhs1 rhs2 actd))
(ensures (mt_rhs_inv #_ #f j smt rhs2 actd))
(decreases j)
let rec rhs_equiv_inv_preserved #_ #f j smt rhs1 rhs2 actd =
if j = 0 then ()
else if j % 2 = 0
then rhs_equiv_inv_preserved #_ #f (j / 2) (MTS.mt_next_lv #_ #f #(log2c j) smt)
(S.tail rhs1) (S.tail rhs2) actd
else begin
(if actd
then (assert (S.index smt j == MTS.HRaw (S.head rhs1));
assert (S.head rhs1 == S.head rhs2))
else ());
rhs_equiv_inv_preserved #_ #f (j / 2) (MTS.mt_next_lv #_ #f #(log2c j) smt)
(S.tail rhs1) (S.tail rhs2) true
end
val construct_rhs_acc_consistent:
#hsz:pos -> #f:MTS.hash_fun_t #hsz ->
lv:nat{lv <= 32} ->
i:nat ->
j:nat{i <= j /\ j < pow2 (32 - lv)} ->
olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} ->
hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts lv hs i j} ->
rhs:hashes #hsz {S.length rhs = 32} ->
acc:hash #hsz ->
actd:bool ->
Lemma (requires True)
(ensures
(log2c_bound j (32 - lv);
mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs;
mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs);
(let rrf = construct_rhs_acc #_ #f j
(S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd in
let rr = construct_rhs #_ #f lv hs rhs i j acc actd in
rhs_equiv #hsz j (fst rrf) (S.slice (fst rr) lv (lv + log2c j)) actd /\
snd rrf == snd rr)))
(decreases j)
#push-options "--z3rlimit 300 --ifuel 1" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"MerkleTree.Spec.fst.checked",
"MerkleTree.New.High.Correct.Base.fst.checked",
"MerkleTree.New.High.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "MerkleTree.New.High.Correct.Rhs.fst"
} | [
{
"abbrev": false,
"full_module": "MerkleTree.New.High.Correct.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New.High",
"short_module": null
},
{
"abbrev": true,
"full_module": "MerkleTree.Spec",
"short_module": "MTS"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Classical",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New.High.Correct",
"short_module": null
},
{
"abbrev": false,
"full_module": "MerkleTree.New.High.Correct",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 3,
"quake_keep": false,
"quake_lo": 1,
"retry": true,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 300,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
lv: Prims.nat{lv <= 32} ->
i: Prims.nat ->
j: Prims.nat{i <= j /\ j < Prims.pow2 (32 - lv)} ->
olds:
MerkleTree.New.High.hashess
{FStar.Seq.Base.length olds = 32 /\ MerkleTree.New.High.Correct.Base.mt_olds_inv lv i olds} ->
hs:
MerkleTree.New.High.hashess
{FStar.Seq.Base.length hs = 32 /\ MerkleTree.New.High.hs_wf_elts lv hs i j} ->
rhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length rhs = 32} ->
acc: MerkleTree.New.High.hash ->
actd: Prims.bool
-> FStar.Pervasives.Lemma
(ensures
(MerkleTree.New.High.Correct.Base.log2c_bound j (32 - lv);
MerkleTree.New.High.Correct.Base.mt_olds_hs_lth_inv_ok lv i j olds hs;
MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log_converted_ lv
j
(MerkleTree.New.High.Correct.Base.merge_hs olds hs);
let rrf =
MerkleTree.New.High.Correct.Rhs.construct_rhs_acc j
(FStar.Seq.Base.slice (MerkleTree.New.High.Correct.Base.merge_hs olds hs)
lv
(lv + MerkleTree.New.High.Correct.Base.log2c j))
acc
actd
in
let rr = MerkleTree.New.High.construct_rhs lv hs rhs i j acc actd in
MerkleTree.New.High.Correct.Rhs.rhs_equiv j
(FStar.Pervasives.Native.fst rrf)
(FStar.Seq.Base.slice (FStar.Pervasives.Native.fst rr)
lv
(lv + MerkleTree.New.High.Correct.Base.log2c j))
actd /\ FStar.Pervasives.Native.snd rrf == FStar.Pervasives.Native.snd rr))
(decreases j) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.pos",
"MerkleTree.Spec.hash_fun_t",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.l_and",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.op_Subtraction",
"MerkleTree.New.High.hashess",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.length",
"MerkleTree.New.High.hashes",
"MerkleTree.New.High.Correct.Base.mt_olds_inv",
"MerkleTree.New.High.hs_wf_elts",
"MerkleTree.New.High.hash",
"Prims.bool",
"Prims.op_Modulus",
"Prims._assert",
"Prims.eq2",
"FStar.Pervasives.Native.snd",
"MerkleTree.New.High.Correct.Base.log2c",
"Prims.unit",
"MerkleTree.New.High.Correct.Rhs.rhs_equiv",
"FStar.Pervasives.Native.fst",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"FStar.Pervasives.Native.tuple2",
"MerkleTree.New.High.construct_rhs",
"MerkleTree.New.High.Correct.Rhs.construct_rhs_acc",
"MerkleTree.New.High.Correct.Base.merge_hs",
"MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log_converted_",
"MerkleTree.New.High.Correct.Base.mt_olds_hs_lth_inv_ok",
"Prims.op_Division",
"MerkleTree.New.High.Correct.Base.log2c_bound",
"MerkleTree.New.High.Correct.Rhs.construct_rhs_acc_consistent",
"FStar.Seq.Properties.tail",
"FStar.Seq.Properties.head",
"FStar.Seq.Base.index",
"FStar.Seq.Base.equal",
"MerkleTree.New.High.construct_rhs_unchanged",
"MerkleTree.New.High.construct_rhs_odd",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.upd",
"MerkleTree.New.High.Correct.Rhs.construct_rhs_acc_odd",
"FStar.Seq.Properties.last",
"MerkleTree.New.High.hash_init",
"Prims.op_GreaterThanOrEqual",
"MerkleTree.New.High.Correct.Base.log2c_div",
"Prims.l_imp",
"Prims.op_disEquality"
] | [
"recursion"
] | false | false | true | false | false | let rec construct_rhs_acc_consistent #hsz #f lv i j olds hs rhs acc actd =
| assert (j < pow2 (32 - lv));
assert (j <> 0 ==> j / 2 < pow2 (32 - (lv + 1)));
log2c_bound j (32 - lv);
mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs;
mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs);
let rrf = construct_rhs_acc #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd in
let rr = construct_rhs #_ #f lv hs rhs i j acc actd in
construct_rhs_unchanged #_ #f lv hs rhs i j acc actd;
assert (S.equal (S.slice rhs 0 lv) (S.slice (fst rr) 0 lv));
if j = 0
then ()
else
(log2c_div j;
assert (32 - (lv + 1) >= 0);
log2c_bound (j / 2) (32 - (lv + 1));
mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs;
mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) (merge_hs #_ #f olds hs);
if j % 2 = 0
then
(construct_rhs_acc_consistent #_ #f (lv + 1) (i / 2) (j / 2) olds hs rhs acc actd;
log2c_bound (j / 2) (32 - (lv + 1));
mt_olds_hs_lth_inv_ok #hsz #f (lv + 1) (i / 2) (j / 2) olds hs;
mt_hashes_lth_inv_log_converted_ #_ #f lv j (merge_hs #_ #f olds hs);
let rrf =
construct_rhs_acc #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd
in
let rr = construct_rhs #_ #f lv hs rhs i j acc actd in
assert (rhs_equiv #hsz j (fst rrf) (S.slice (fst rr) lv (lv + log2c j)) actd);
assert (snd rrf == snd rr))
else
let rhd = if actd then acc else hash_init in
let nacc = if actd then f (S.last (S.index hs lv)) acc else S.last (S.index hs lv) in
assert (S.equal (S.tail (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)))
(S.slice (merge_hs #_ #f olds hs) (lv + 1) (lv + 1 + log2c (j / 2))));
let nrrf =
construct_rhs_acc #_
#f
(j / 2)
(S.slice (merge_hs #_ #f olds hs) (lv + 1) (lv + 1 + (log2c (j / 2))))
nacc
true
in
construct_rhs_acc_odd #_ #f j (S.slice (merge_hs #_ #f olds hs) lv (lv + log2c j)) acc actd;
assert (hs_wf_elts (lv + 1) hs (i / 2) (j / 2));
let nrhs = if actd then S.upd rhs lv acc else rhs in
let nrr = construct_rhs #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true in
construct_rhs_odd #_ #f lv hs rhs i j acc actd;
construct_rhs_unchanged #_ #f (lv + 1) hs nrhs (i / 2) (j / 2) nacc true;
assert (S.equal (S.slice nrhs 0 (lv + 1)) (S.slice (fst nrr) 0 (lv + 1)));
assert (S.index (fst nrr) lv == S.index nrhs lv);
construct_rhs_acc_consistent #_ #f (lv + 1) (i / 2) (j / 2) olds hs nrhs nacc true;
assert (rhs_equiv #hsz
(j / 2)
(fst nrrf)
(S.slice (fst nrr) (lv + 1) (lv + 1 + log2c (j / 2)))
true);
assert (snd nrrf == snd nrr);
(if actd
then
(assert (S.head (fst rrf) == rhd);
assert (rhd == acc);
assert (S.index (fst rr) lv == S.index nrhs lv);
assert (S.index nrhs lv == acc);
assert (S.head (fst rrf) == S.index (fst rr) lv)));
assert (if actd then S.head (fst rrf) == S.index (fst rr) lv else true);
assert (rhs_equiv #hsz
(j / 2)
(S.tail (fst rrf))
(S.slice (fst rr) (lv + 1) (lv + 1 + log2c (j / 2)))
true);
assert (rhs_equiv #hsz j (fst rrf) (S.slice (fst rr) lv (lv + log2c j)) actd);
assert (snd rrf == snd rr)) | false |
Hacl.Impl.Frodo.Sample.fst | Hacl.Impl.Frodo.Sample.frodo_sample_st | val frodo_sample_st : a: Spec.Frodo.Params.frodo_alg -> Type0 | let frodo_sample_st (a:FP.frodo_alg) =
r:uint16
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 res h1 -> modifies0 h0 h1 /\
res == S.frodo_sample a r) | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Sample.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 60,
"start_col": 0,
"start_line": 55
} | module Hacl.Impl.Frodo.Sample
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
open Hacl.Impl.Frodo.Params
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Lemmas = Spec.Frodo.Lemmas
module S = Spec.Frodo.Sample
module FP = Spec.Frodo.Params
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val frodo_sample_f:
a:FP.frodo_alg
-> t:uint16{uint_v t < pow2 15}
-> i:size_t{v i < v (cdf_table_len a)}
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.frodo_sample_f a t (v i))
let frodo_sample_f a t i =
recall_contents (cdf_table a) (FP.cdf_table a);
let ti = index (cdf_table a) i in
FP.lemma_cdf_list a (v i);
Lemmas.lemma_frodo_sample t ti;
to_u16 (to_u32 (ti -. t)) >>. 15ul
inline_for_extraction noextract
val frodo_sample_res:
a:FP.frodo_alg
-> sign:uint16{v sign <= 1}
-> sample:uint16{v sample < v (cdf_table_len a)}
-> res:uint16{res == S.frodo_sample_res a sign (v sample)}
let frodo_sample_res a sign sample =
Lemmas.lemma_frodo_sample2 sign sample;
((lognot sign +. u16 1) ^. sample) +. sign | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Params.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Sample.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "FP"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Sample",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Frodo.Params.frodo_alg -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Lib.IntTypes.uint16",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_True",
"Prims.l_and",
"Lib.Buffer.modifies0",
"Prims.eq2",
"Spec.Frodo.Sample.frodo_sample"
] | [] | false | false | false | true | true | let frodo_sample_st (a: FP.frodo_alg) =
| r: uint16
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 res h1 -> modifies0 h0 h1 /\ res == S.frodo_sample a r) | false |
|
Hacl.Impl.Frodo.Sample.fst | Hacl.Impl.Frodo.Sample.frodo_sample_matrix64 | val frodo_sample_matrix64:frodo_sample_matrix_st FP.Frodo64 | val frodo_sample_matrix64:frodo_sample_matrix_st FP.Frodo64 | let frodo_sample_matrix64 : frodo_sample_matrix_st FP.Frodo64 =
frodo_sample_matrix_ FP.Frodo64 (frodo_sample FP.Frodo64) | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Sample.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 59,
"end_line": 161,
"start_col": 0,
"start_line": 160
} | module Hacl.Impl.Frodo.Sample
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
open Hacl.Impl.Frodo.Params
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Lemmas = Spec.Frodo.Lemmas
module S = Spec.Frodo.Sample
module FP = Spec.Frodo.Params
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val frodo_sample_f:
a:FP.frodo_alg
-> t:uint16{uint_v t < pow2 15}
-> i:size_t{v i < v (cdf_table_len a)}
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.frodo_sample_f a t (v i))
let frodo_sample_f a t i =
recall_contents (cdf_table a) (FP.cdf_table a);
let ti = index (cdf_table a) i in
FP.lemma_cdf_list a (v i);
Lemmas.lemma_frodo_sample t ti;
to_u16 (to_u32 (ti -. t)) >>. 15ul
inline_for_extraction noextract
val frodo_sample_res:
a:FP.frodo_alg
-> sign:uint16{v sign <= 1}
-> sample:uint16{v sample < v (cdf_table_len a)}
-> res:uint16{res == S.frodo_sample_res a sign (v sample)}
let frodo_sample_res a sign sample =
Lemmas.lemma_frodo_sample2 sign sample;
((lognot sign +. u16 1) ^. sample) +. sign
inline_for_extraction noextract
let frodo_sample_st (a:FP.frodo_alg) =
r:uint16
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 res h1 -> modifies0 h0 h1 /\
res == S.frodo_sample a r)
#push-options "--fuel 1"
inline_for_extraction noextract
val frodo_sample: a:FP.frodo_alg -> frodo_sample_st a
let frodo_sample a r =
push_frame();
let prnd = r >>. 1ul in
let sign = r &. u16 1 in
mod_mask_lemma r 1ul;
assert (v #U16 #SEC (mod_mask 1ul) == 1);
assert (v sign == 0 \/ v sign == 1);
let sample :lbuffer uint16 1ul = create (size 1) (u16 0) in
let h = ST.get () in
assert (LSeq.index #_ #1 (as_seq h sample) 0 == u16 0);
assert (bget h sample 0 == u16 0);
let bound = cdf_table_len a -! 1ul in
let h0 = ST.get () in
Lib.Loops.for 0ul bound
(fun h i ->
modifies1 sample h0 h /\
v (bget h sample 0) == S.frodo_sample_fc a prnd i)
(fun i ->
let sample0 = sample.(0ul) in
let samplei = frodo_sample_f a prnd i in
sample.(0ul) <- samplei +. sample0
);
let sample0 = sample.(0ul) in
assert (v sample0 == S.frodo_sample_fc a prnd (v bound));
let res = frodo_sample_res a sign sample0 in
pop_frame();
res
#pop-options
inline_for_extraction noextract
val frodo_sample_matrix1:
a:FP.frodo_alg
-> frodo_sample:frodo_sample_st a
-> n1:size_t
-> n2:size_t{0 < 2 * v n1 * v n2 /\ 2 * v n1 * v n2 <= max_size_t}
-> r:lbuffer uint8 (size 2 *! n1 *! n2)
-> i:size_t{v i < v n1}
-> res:matrix_t n1 n2
-> Stack unit
(requires fun h ->
live h r /\ live h res /\ disjoint r res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res ==
S.frodo_sample_matrix1 a (v n1) (v n2) (as_seq h0 r) (v i) (as_matrix h0 res))
let frodo_sample_matrix1 a frodo_sample n1 n2 r i res =
[@ inline_let]
let spec h0 = S.frodo_sample_matrix0 a (v n1) (v n2) (as_seq h0 r) (v i) in
let h0 = ST.get () in
loop1 h0 n2 res spec
(fun j ->
Loops.unfold_repeati (v n2) (spec h0) (as_seq h0 res) (v j);
Lemmas.lemma_matrix_index_repeati1 (v n1) (v n2) (v i) (v j);
let resij = sub r (size 2 *! (n2 *! i +! j)) (size 2) in
mset res i j (frodo_sample (uint_from_bytes_le #U16 resij))
)
inline_for_extraction noextract
let frodo_sample_matrix_st (a:FP.frodo_alg) =
n1:size_t
-> n2:size_t{0 < 2 * v n1 * v n2 /\ 2 * v n1 * v n2 <= max_size_t}
-> r:lbytes (2ul *! n1 *! n2)
-> res:matrix_t n1 n2
-> Stack unit
(requires fun h ->
live h r /\ live h res /\ disjoint r res)
(ensures fun h0 r_ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res == S.frodo_sample_matrix a (v n1) (v n2) (as_seq h0 r))
inline_for_extraction noextract
val frodo_sample_matrix_:
a:FP.frodo_alg
-> frodo_sample:frodo_sample_st a
-> frodo_sample_matrix_st a
let frodo_sample_matrix_ a frodo_sample n1 n2 r res =
memset res (u16 0) (n1 *! n2);
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 (v n1 * v n2)) (as_seq h0 res);
[@ inline_let]
let spec h0 = S.frodo_sample_matrix1 a (v n1) (v n2) (as_seq h0 r) in
loop1 h0 n1 res spec
(fun i ->
Loops.unfold_repeati (v n1) (spec h0) (as_seq h0 res) (v i);
frodo_sample_matrix1 a frodo_sample n1 n2 r i res
) | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Params.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Sample.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "FP"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Sample",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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.Impl.Frodo.Sample.frodo_sample_matrix_st Spec.Frodo.Params.Frodo64 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Frodo.Sample.frodo_sample_matrix_",
"Spec.Frodo.Params.Frodo64",
"Hacl.Impl.Frodo.Sample.frodo_sample"
] | [] | false | false | false | true | false | let frodo_sample_matrix64:frodo_sample_matrix_st FP.Frodo64 =
| frodo_sample_matrix_ FP.Frodo64 (frodo_sample FP.Frodo64) | false |
Hacl.Impl.Frodo.Sample.fst | Hacl.Impl.Frodo.Sample.frodo_sample_matrix640 | val frodo_sample_matrix640:frodo_sample_matrix_st FP.Frodo640 | val frodo_sample_matrix640:frodo_sample_matrix_st FP.Frodo640 | let frodo_sample_matrix640 : frodo_sample_matrix_st FP.Frodo640 =
frodo_sample_matrix_ FP.Frodo640 (frodo_sample FP.Frodo640) | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Sample.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 61,
"end_line": 164,
"start_col": 0,
"start_line": 163
} | module Hacl.Impl.Frodo.Sample
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
open Hacl.Impl.Frodo.Params
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Lemmas = Spec.Frodo.Lemmas
module S = Spec.Frodo.Sample
module FP = Spec.Frodo.Params
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val frodo_sample_f:
a:FP.frodo_alg
-> t:uint16{uint_v t < pow2 15}
-> i:size_t{v i < v (cdf_table_len a)}
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.frodo_sample_f a t (v i))
let frodo_sample_f a t i =
recall_contents (cdf_table a) (FP.cdf_table a);
let ti = index (cdf_table a) i in
FP.lemma_cdf_list a (v i);
Lemmas.lemma_frodo_sample t ti;
to_u16 (to_u32 (ti -. t)) >>. 15ul
inline_for_extraction noextract
val frodo_sample_res:
a:FP.frodo_alg
-> sign:uint16{v sign <= 1}
-> sample:uint16{v sample < v (cdf_table_len a)}
-> res:uint16{res == S.frodo_sample_res a sign (v sample)}
let frodo_sample_res a sign sample =
Lemmas.lemma_frodo_sample2 sign sample;
((lognot sign +. u16 1) ^. sample) +. sign
inline_for_extraction noextract
let frodo_sample_st (a:FP.frodo_alg) =
r:uint16
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 res h1 -> modifies0 h0 h1 /\
res == S.frodo_sample a r)
#push-options "--fuel 1"
inline_for_extraction noextract
val frodo_sample: a:FP.frodo_alg -> frodo_sample_st a
let frodo_sample a r =
push_frame();
let prnd = r >>. 1ul in
let sign = r &. u16 1 in
mod_mask_lemma r 1ul;
assert (v #U16 #SEC (mod_mask 1ul) == 1);
assert (v sign == 0 \/ v sign == 1);
let sample :lbuffer uint16 1ul = create (size 1) (u16 0) in
let h = ST.get () in
assert (LSeq.index #_ #1 (as_seq h sample) 0 == u16 0);
assert (bget h sample 0 == u16 0);
let bound = cdf_table_len a -! 1ul in
let h0 = ST.get () in
Lib.Loops.for 0ul bound
(fun h i ->
modifies1 sample h0 h /\
v (bget h sample 0) == S.frodo_sample_fc a prnd i)
(fun i ->
let sample0 = sample.(0ul) in
let samplei = frodo_sample_f a prnd i in
sample.(0ul) <- samplei +. sample0
);
let sample0 = sample.(0ul) in
assert (v sample0 == S.frodo_sample_fc a prnd (v bound));
let res = frodo_sample_res a sign sample0 in
pop_frame();
res
#pop-options
inline_for_extraction noextract
val frodo_sample_matrix1:
a:FP.frodo_alg
-> frodo_sample:frodo_sample_st a
-> n1:size_t
-> n2:size_t{0 < 2 * v n1 * v n2 /\ 2 * v n1 * v n2 <= max_size_t}
-> r:lbuffer uint8 (size 2 *! n1 *! n2)
-> i:size_t{v i < v n1}
-> res:matrix_t n1 n2
-> Stack unit
(requires fun h ->
live h r /\ live h res /\ disjoint r res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res ==
S.frodo_sample_matrix1 a (v n1) (v n2) (as_seq h0 r) (v i) (as_matrix h0 res))
let frodo_sample_matrix1 a frodo_sample n1 n2 r i res =
[@ inline_let]
let spec h0 = S.frodo_sample_matrix0 a (v n1) (v n2) (as_seq h0 r) (v i) in
let h0 = ST.get () in
loop1 h0 n2 res spec
(fun j ->
Loops.unfold_repeati (v n2) (spec h0) (as_seq h0 res) (v j);
Lemmas.lemma_matrix_index_repeati1 (v n1) (v n2) (v i) (v j);
let resij = sub r (size 2 *! (n2 *! i +! j)) (size 2) in
mset res i j (frodo_sample (uint_from_bytes_le #U16 resij))
)
inline_for_extraction noextract
let frodo_sample_matrix_st (a:FP.frodo_alg) =
n1:size_t
-> n2:size_t{0 < 2 * v n1 * v n2 /\ 2 * v n1 * v n2 <= max_size_t}
-> r:lbytes (2ul *! n1 *! n2)
-> res:matrix_t n1 n2
-> Stack unit
(requires fun h ->
live h r /\ live h res /\ disjoint r res)
(ensures fun h0 r_ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res == S.frodo_sample_matrix a (v n1) (v n2) (as_seq h0 r))
inline_for_extraction noextract
val frodo_sample_matrix_:
a:FP.frodo_alg
-> frodo_sample:frodo_sample_st a
-> frodo_sample_matrix_st a
let frodo_sample_matrix_ a frodo_sample n1 n2 r res =
memset res (u16 0) (n1 *! n2);
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 (v n1 * v n2)) (as_seq h0 res);
[@ inline_let]
let spec h0 = S.frodo_sample_matrix1 a (v n1) (v n2) (as_seq h0 r) in
loop1 h0 n1 res spec
(fun i ->
Loops.unfold_repeati (v n1) (spec h0) (as_seq h0 res) (v i);
frodo_sample_matrix1 a frodo_sample n1 n2 r i res
)
[@CInline]
let frodo_sample_matrix64 : frodo_sample_matrix_st FP.Frodo64 =
frodo_sample_matrix_ FP.Frodo64 (frodo_sample FP.Frodo64) | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Params.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Sample.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "FP"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Sample",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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.Impl.Frodo.Sample.frodo_sample_matrix_st Spec.Frodo.Params.Frodo640 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Frodo.Sample.frodo_sample_matrix_",
"Spec.Frodo.Params.Frodo640",
"Hacl.Impl.Frodo.Sample.frodo_sample"
] | [] | false | false | false | true | false | let frodo_sample_matrix640:frodo_sample_matrix_st FP.Frodo640 =
| frodo_sample_matrix_ FP.Frodo640 (frodo_sample FP.Frodo640) | false |
Hacl.Impl.Frodo.Sample.fst | Hacl.Impl.Frodo.Sample.frodo_sample_res | val frodo_sample_res:
a:FP.frodo_alg
-> sign:uint16{v sign <= 1}
-> sample:uint16{v sample < v (cdf_table_len a)}
-> res:uint16{res == S.frodo_sample_res a sign (v sample)} | val frodo_sample_res:
a:FP.frodo_alg
-> sign:uint16{v sign <= 1}
-> sample:uint16{v sample < v (cdf_table_len a)}
-> res:uint16{res == S.frodo_sample_res a sign (v sample)} | let frodo_sample_res a sign sample =
Lemmas.lemma_frodo_sample2 sign sample;
((lognot sign +. u16 1) ^. sample) +. sign | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Sample.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 51,
"start_col": 0,
"start_line": 49
} | module Hacl.Impl.Frodo.Sample
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
open Hacl.Impl.Frodo.Params
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Lemmas = Spec.Frodo.Lemmas
module S = Spec.Frodo.Sample
module FP = Spec.Frodo.Params
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val frodo_sample_f:
a:FP.frodo_alg
-> t:uint16{uint_v t < pow2 15}
-> i:size_t{v i < v (cdf_table_len a)}
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.frodo_sample_f a t (v i))
let frodo_sample_f a t i =
recall_contents (cdf_table a) (FP.cdf_table a);
let ti = index (cdf_table a) i in
FP.lemma_cdf_list a (v i);
Lemmas.lemma_frodo_sample t ti;
to_u16 (to_u32 (ti -. t)) >>. 15ul
inline_for_extraction noextract
val frodo_sample_res:
a:FP.frodo_alg
-> sign:uint16{v sign <= 1}
-> sample:uint16{v sample < v (cdf_table_len a)}
-> res:uint16{res == S.frodo_sample_res a sign (v sample)} | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Params.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Sample.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "FP"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Sample",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Frodo.Params.frodo_alg ->
sign: Lib.IntTypes.uint16{Lib.IntTypes.v sign <= 1} ->
sample:
Lib.IntTypes.uint16
{Lib.IntTypes.v sample < Lib.IntTypes.v (Hacl.Impl.Frodo.Params.cdf_table_len a)}
-> res:
Lib.IntTypes.uint16{res == Spec.Frodo.Sample.frodo_sample_res a sign (Lib.IntTypes.v sample)} | Prims.Tot | [
"total"
] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Lib.IntTypes.uint16",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Prims.op_LessThan",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Frodo.Params.cdf_table_len",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.op_Hat_Dot",
"Lib.IntTypes.lognot",
"Lib.IntTypes.u16",
"Prims.unit",
"Spec.Frodo.Lemmas.lemma_frodo_sample2",
"Prims.eq2",
"Spec.Frodo.Sample.frodo_sample_res"
] | [] | false | false | false | false | false | let frodo_sample_res a sign sample =
| Lemmas.lemma_frodo_sample2 sign sample;
((lognot sign +. u16 1) ^. sample) +. sign | false |
Hacl.Impl.Frodo.Sample.fst | Hacl.Impl.Frodo.Sample.frodo_sample_matrix976 | val frodo_sample_matrix976:frodo_sample_matrix_st FP.Frodo976 | val frodo_sample_matrix976:frodo_sample_matrix_st FP.Frodo976 | let frodo_sample_matrix976 : frodo_sample_matrix_st FP.Frodo976 =
frodo_sample_matrix_ FP.Frodo976 (frodo_sample FP.Frodo976) | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Sample.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 61,
"end_line": 167,
"start_col": 0,
"start_line": 166
} | module Hacl.Impl.Frodo.Sample
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
open Hacl.Impl.Frodo.Params
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Lemmas = Spec.Frodo.Lemmas
module S = Spec.Frodo.Sample
module FP = Spec.Frodo.Params
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val frodo_sample_f:
a:FP.frodo_alg
-> t:uint16{uint_v t < pow2 15}
-> i:size_t{v i < v (cdf_table_len a)}
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.frodo_sample_f a t (v i))
let frodo_sample_f a t i =
recall_contents (cdf_table a) (FP.cdf_table a);
let ti = index (cdf_table a) i in
FP.lemma_cdf_list a (v i);
Lemmas.lemma_frodo_sample t ti;
to_u16 (to_u32 (ti -. t)) >>. 15ul
inline_for_extraction noextract
val frodo_sample_res:
a:FP.frodo_alg
-> sign:uint16{v sign <= 1}
-> sample:uint16{v sample < v (cdf_table_len a)}
-> res:uint16{res == S.frodo_sample_res a sign (v sample)}
let frodo_sample_res a sign sample =
Lemmas.lemma_frodo_sample2 sign sample;
((lognot sign +. u16 1) ^. sample) +. sign
inline_for_extraction noextract
let frodo_sample_st (a:FP.frodo_alg) =
r:uint16
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 res h1 -> modifies0 h0 h1 /\
res == S.frodo_sample a r)
#push-options "--fuel 1"
inline_for_extraction noextract
val frodo_sample: a:FP.frodo_alg -> frodo_sample_st a
let frodo_sample a r =
push_frame();
let prnd = r >>. 1ul in
let sign = r &. u16 1 in
mod_mask_lemma r 1ul;
assert (v #U16 #SEC (mod_mask 1ul) == 1);
assert (v sign == 0 \/ v sign == 1);
let sample :lbuffer uint16 1ul = create (size 1) (u16 0) in
let h = ST.get () in
assert (LSeq.index #_ #1 (as_seq h sample) 0 == u16 0);
assert (bget h sample 0 == u16 0);
let bound = cdf_table_len a -! 1ul in
let h0 = ST.get () in
Lib.Loops.for 0ul bound
(fun h i ->
modifies1 sample h0 h /\
v (bget h sample 0) == S.frodo_sample_fc a prnd i)
(fun i ->
let sample0 = sample.(0ul) in
let samplei = frodo_sample_f a prnd i in
sample.(0ul) <- samplei +. sample0
);
let sample0 = sample.(0ul) in
assert (v sample0 == S.frodo_sample_fc a prnd (v bound));
let res = frodo_sample_res a sign sample0 in
pop_frame();
res
#pop-options
inline_for_extraction noextract
val frodo_sample_matrix1:
a:FP.frodo_alg
-> frodo_sample:frodo_sample_st a
-> n1:size_t
-> n2:size_t{0 < 2 * v n1 * v n2 /\ 2 * v n1 * v n2 <= max_size_t}
-> r:lbuffer uint8 (size 2 *! n1 *! n2)
-> i:size_t{v i < v n1}
-> res:matrix_t n1 n2
-> Stack unit
(requires fun h ->
live h r /\ live h res /\ disjoint r res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res ==
S.frodo_sample_matrix1 a (v n1) (v n2) (as_seq h0 r) (v i) (as_matrix h0 res))
let frodo_sample_matrix1 a frodo_sample n1 n2 r i res =
[@ inline_let]
let spec h0 = S.frodo_sample_matrix0 a (v n1) (v n2) (as_seq h0 r) (v i) in
let h0 = ST.get () in
loop1 h0 n2 res spec
(fun j ->
Loops.unfold_repeati (v n2) (spec h0) (as_seq h0 res) (v j);
Lemmas.lemma_matrix_index_repeati1 (v n1) (v n2) (v i) (v j);
let resij = sub r (size 2 *! (n2 *! i +! j)) (size 2) in
mset res i j (frodo_sample (uint_from_bytes_le #U16 resij))
)
inline_for_extraction noextract
let frodo_sample_matrix_st (a:FP.frodo_alg) =
n1:size_t
-> n2:size_t{0 < 2 * v n1 * v n2 /\ 2 * v n1 * v n2 <= max_size_t}
-> r:lbytes (2ul *! n1 *! n2)
-> res:matrix_t n1 n2
-> Stack unit
(requires fun h ->
live h r /\ live h res /\ disjoint r res)
(ensures fun h0 r_ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res == S.frodo_sample_matrix a (v n1) (v n2) (as_seq h0 r))
inline_for_extraction noextract
val frodo_sample_matrix_:
a:FP.frodo_alg
-> frodo_sample:frodo_sample_st a
-> frodo_sample_matrix_st a
let frodo_sample_matrix_ a frodo_sample n1 n2 r res =
memset res (u16 0) (n1 *! n2);
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 (v n1 * v n2)) (as_seq h0 res);
[@ inline_let]
let spec h0 = S.frodo_sample_matrix1 a (v n1) (v n2) (as_seq h0 r) in
loop1 h0 n1 res spec
(fun i ->
Loops.unfold_repeati (v n1) (spec h0) (as_seq h0 res) (v i);
frodo_sample_matrix1 a frodo_sample n1 n2 r i res
)
[@CInline]
let frodo_sample_matrix64 : frodo_sample_matrix_st FP.Frodo64 =
frodo_sample_matrix_ FP.Frodo64 (frodo_sample FP.Frodo64)
[@CInline]
let frodo_sample_matrix640 : frodo_sample_matrix_st FP.Frodo640 =
frodo_sample_matrix_ FP.Frodo640 (frodo_sample FP.Frodo640) | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Params.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Sample.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "FP"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Sample",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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.Impl.Frodo.Sample.frodo_sample_matrix_st Spec.Frodo.Params.Frodo976 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Frodo.Sample.frodo_sample_matrix_",
"Spec.Frodo.Params.Frodo976",
"Hacl.Impl.Frodo.Sample.frodo_sample"
] | [] | false | false | false | true | false | let frodo_sample_matrix976:frodo_sample_matrix_st FP.Frodo976 =
| frodo_sample_matrix_ FP.Frodo976 (frodo_sample FP.Frodo976) | false |
FStar.SizeT.fst | FStar.SizeT.fits | val fits (x: nat) : Tot prop | val fits (x: nat) : Tot prop | let fits x =
FStar.UInt.fits x U64.n == true /\
x < bound | {
"file_name": "ulib/FStar.SizeT.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 11,
"end_line": 17,
"start_col": 0,
"start_line": 15
} | module FStar.SizeT
open FStar.Ghost
module I64 = FStar.Int64
(* This is only intended as a model, but will be extracted natively by Krml
with the correct C semantics *)
(* We assume the existence of some lower bound on the size,
where the bound is at least 2^16 *)
assume
val bound : x:erased nat { x >= pow2 16 }
let t = x:U64.t { U64.v x < bound } | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Int64.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.SizeT.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int64",
"short_module": "I64"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.nat -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"FStar.UInt.fits",
"FStar.UInt64.n",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Ghost.reveal",
"FStar.SizeT.bound",
"Prims.prop"
] | [] | false | false | false | true | true | let fits x =
| FStar.UInt.fits x U64.n == true /\ x < bound | false |
Hacl.Impl.Frodo.Sample.fst | Hacl.Impl.Frodo.Sample.frodo_sample_matrix1344 | val frodo_sample_matrix1344:frodo_sample_matrix_st FP.Frodo1344 | val frodo_sample_matrix1344:frodo_sample_matrix_st FP.Frodo1344 | let frodo_sample_matrix1344 : frodo_sample_matrix_st FP.Frodo1344=
frodo_sample_matrix_ FP.Frodo1344 (frodo_sample FP.Frodo1344) | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Sample.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 170,
"start_col": 0,
"start_line": 169
} | module Hacl.Impl.Frodo.Sample
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
open Hacl.Impl.Frodo.Params
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Lemmas = Spec.Frodo.Lemmas
module S = Spec.Frodo.Sample
module FP = Spec.Frodo.Params
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val frodo_sample_f:
a:FP.frodo_alg
-> t:uint16{uint_v t < pow2 15}
-> i:size_t{v i < v (cdf_table_len a)}
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.frodo_sample_f a t (v i))
let frodo_sample_f a t i =
recall_contents (cdf_table a) (FP.cdf_table a);
let ti = index (cdf_table a) i in
FP.lemma_cdf_list a (v i);
Lemmas.lemma_frodo_sample t ti;
to_u16 (to_u32 (ti -. t)) >>. 15ul
inline_for_extraction noextract
val frodo_sample_res:
a:FP.frodo_alg
-> sign:uint16{v sign <= 1}
-> sample:uint16{v sample < v (cdf_table_len a)}
-> res:uint16{res == S.frodo_sample_res a sign (v sample)}
let frodo_sample_res a sign sample =
Lemmas.lemma_frodo_sample2 sign sample;
((lognot sign +. u16 1) ^. sample) +. sign
inline_for_extraction noextract
let frodo_sample_st (a:FP.frodo_alg) =
r:uint16
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 res h1 -> modifies0 h0 h1 /\
res == S.frodo_sample a r)
#push-options "--fuel 1"
inline_for_extraction noextract
val frodo_sample: a:FP.frodo_alg -> frodo_sample_st a
let frodo_sample a r =
push_frame();
let prnd = r >>. 1ul in
let sign = r &. u16 1 in
mod_mask_lemma r 1ul;
assert (v #U16 #SEC (mod_mask 1ul) == 1);
assert (v sign == 0 \/ v sign == 1);
let sample :lbuffer uint16 1ul = create (size 1) (u16 0) in
let h = ST.get () in
assert (LSeq.index #_ #1 (as_seq h sample) 0 == u16 0);
assert (bget h sample 0 == u16 0);
let bound = cdf_table_len a -! 1ul in
let h0 = ST.get () in
Lib.Loops.for 0ul bound
(fun h i ->
modifies1 sample h0 h /\
v (bget h sample 0) == S.frodo_sample_fc a prnd i)
(fun i ->
let sample0 = sample.(0ul) in
let samplei = frodo_sample_f a prnd i in
sample.(0ul) <- samplei +. sample0
);
let sample0 = sample.(0ul) in
assert (v sample0 == S.frodo_sample_fc a prnd (v bound));
let res = frodo_sample_res a sign sample0 in
pop_frame();
res
#pop-options
inline_for_extraction noextract
val frodo_sample_matrix1:
a:FP.frodo_alg
-> frodo_sample:frodo_sample_st a
-> n1:size_t
-> n2:size_t{0 < 2 * v n1 * v n2 /\ 2 * v n1 * v n2 <= max_size_t}
-> r:lbuffer uint8 (size 2 *! n1 *! n2)
-> i:size_t{v i < v n1}
-> res:matrix_t n1 n2
-> Stack unit
(requires fun h ->
live h r /\ live h res /\ disjoint r res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res ==
S.frodo_sample_matrix1 a (v n1) (v n2) (as_seq h0 r) (v i) (as_matrix h0 res))
let frodo_sample_matrix1 a frodo_sample n1 n2 r i res =
[@ inline_let]
let spec h0 = S.frodo_sample_matrix0 a (v n1) (v n2) (as_seq h0 r) (v i) in
let h0 = ST.get () in
loop1 h0 n2 res spec
(fun j ->
Loops.unfold_repeati (v n2) (spec h0) (as_seq h0 res) (v j);
Lemmas.lemma_matrix_index_repeati1 (v n1) (v n2) (v i) (v j);
let resij = sub r (size 2 *! (n2 *! i +! j)) (size 2) in
mset res i j (frodo_sample (uint_from_bytes_le #U16 resij))
)
inline_for_extraction noextract
let frodo_sample_matrix_st (a:FP.frodo_alg) =
n1:size_t
-> n2:size_t{0 < 2 * v n1 * v n2 /\ 2 * v n1 * v n2 <= max_size_t}
-> r:lbytes (2ul *! n1 *! n2)
-> res:matrix_t n1 n2
-> Stack unit
(requires fun h ->
live h r /\ live h res /\ disjoint r res)
(ensures fun h0 r_ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res == S.frodo_sample_matrix a (v n1) (v n2) (as_seq h0 r))
inline_for_extraction noextract
val frodo_sample_matrix_:
a:FP.frodo_alg
-> frodo_sample:frodo_sample_st a
-> frodo_sample_matrix_st a
let frodo_sample_matrix_ a frodo_sample n1 n2 r res =
memset res (u16 0) (n1 *! n2);
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 (v n1 * v n2)) (as_seq h0 res);
[@ inline_let]
let spec h0 = S.frodo_sample_matrix1 a (v n1) (v n2) (as_seq h0 r) in
loop1 h0 n1 res spec
(fun i ->
Loops.unfold_repeati (v n1) (spec h0) (as_seq h0 res) (v i);
frodo_sample_matrix1 a frodo_sample n1 n2 r i res
)
[@CInline]
let frodo_sample_matrix64 : frodo_sample_matrix_st FP.Frodo64 =
frodo_sample_matrix_ FP.Frodo64 (frodo_sample FP.Frodo64)
[@CInline]
let frodo_sample_matrix640 : frodo_sample_matrix_st FP.Frodo640 =
frodo_sample_matrix_ FP.Frodo640 (frodo_sample FP.Frodo640)
[@CInline]
let frodo_sample_matrix976 : frodo_sample_matrix_st FP.Frodo976 =
frodo_sample_matrix_ FP.Frodo976 (frodo_sample FP.Frodo976) | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Params.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Sample.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "FP"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Sample",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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.Impl.Frodo.Sample.frodo_sample_matrix_st Spec.Frodo.Params.Frodo1344 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Frodo.Sample.frodo_sample_matrix_",
"Spec.Frodo.Params.Frodo1344",
"Hacl.Impl.Frodo.Sample.frodo_sample"
] | [] | false | false | false | true | false | let frodo_sample_matrix1344:frodo_sample_matrix_st FP.Frodo1344 =
| frodo_sample_matrix_ FP.Frodo1344 (frodo_sample FP.Frodo1344) | false |
Hacl.Impl.Frodo.Sample.fst | Hacl.Impl.Frodo.Sample.frodo_sample_f | val frodo_sample_f:
a:FP.frodo_alg
-> t:uint16{uint_v t < pow2 15}
-> i:size_t{v i < v (cdf_table_len a)}
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.frodo_sample_f a t (v i)) | val frodo_sample_f:
a:FP.frodo_alg
-> t:uint16{uint_v t < pow2 15}
-> i:size_t{v i < v (cdf_table_len a)}
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.frodo_sample_f a t (v i)) | let frodo_sample_f a t i =
recall_contents (cdf_table a) (FP.cdf_table a);
let ti = index (cdf_table a) i in
FP.lemma_cdf_list a (v i);
Lemmas.lemma_frodo_sample t ti;
to_u16 (to_u32 (ti -. t)) >>. 15ul | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Sample.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 39,
"start_col": 0,
"start_line": 34
} | module Hacl.Impl.Frodo.Sample
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
open Hacl.Impl.Frodo.Params
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Lemmas = Spec.Frodo.Lemmas
module S = Spec.Frodo.Sample
module FP = Spec.Frodo.Params
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val frodo_sample_f:
a:FP.frodo_alg
-> t:uint16{uint_v t < pow2 15}
-> i:size_t{v i < v (cdf_table_len a)}
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.frodo_sample_f a t (v i)) | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Params.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Sample.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "FP"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Sample",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Spec.Frodo.Params.frodo_alg ->
t: Lib.IntTypes.uint16{Lib.IntTypes.uint_v t < Prims.pow2 15} ->
i:
Lib.IntTypes.size_t
{Lib.IntTypes.v i < Lib.IntTypes.v (Hacl.Impl.Frodo.Params.cdf_table_len a)}
-> FStar.HyperStack.ST.Stack Lib.IntTypes.uint16 | FStar.HyperStack.ST.Stack | [] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Lib.IntTypes.uint16",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.uint_v",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Lib.IntTypes.size_t",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Frodo.Params.cdf_table_len",
"Lib.IntTypes.op_Greater_Greater_Dot",
"Lib.IntTypes.to_u16",
"Lib.IntTypes.to_u32",
"Lib.IntTypes.op_Subtraction_Dot",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Spec.Frodo.Lemmas.lemma_frodo_sample",
"Spec.Frodo.Params.lemma_cdf_list",
"Lib.IntTypes.int_t",
"Lib.Buffer.index",
"Lib.Buffer.CONST",
"Hacl.Impl.Frodo.Params.cdf_table",
"Lib.Buffer.recall_contents",
"Spec.Frodo.Params.cdf_table"
] | [] | false | true | false | false | false | let frodo_sample_f a t i =
| recall_contents (cdf_table a) (FP.cdf_table a);
let ti = index (cdf_table a) i in
FP.lemma_cdf_list a (v i);
Lemmas.lemma_frodo_sample t ti;
to_u16 (to_u32 (ti -. t)) >>. 15ul | false |
Hacl.Impl.Frodo.Sample.fst | Hacl.Impl.Frodo.Sample.frodo_sample_matrix_st | val frodo_sample_matrix_st : a: Spec.Frodo.Params.frodo_alg -> Type0 | let frodo_sample_matrix_st (a:FP.frodo_alg) =
n1:size_t
-> n2:size_t{0 < 2 * v n1 * v n2 /\ 2 * v n1 * v n2 <= max_size_t}
-> r:lbytes (2ul *! n1 *! n2)
-> res:matrix_t n1 n2
-> Stack unit
(requires fun h ->
live h r /\ live h res /\ disjoint r res)
(ensures fun h0 r_ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res == S.frodo_sample_matrix a (v n1) (v n2) (as_seq h0 r)) | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Sample.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 78,
"end_line": 136,
"start_col": 0,
"start_line": 127
} | module Hacl.Impl.Frodo.Sample
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
open Hacl.Impl.Frodo.Params
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Lemmas = Spec.Frodo.Lemmas
module S = Spec.Frodo.Sample
module FP = Spec.Frodo.Params
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val frodo_sample_f:
a:FP.frodo_alg
-> t:uint16{uint_v t < pow2 15}
-> i:size_t{v i < v (cdf_table_len a)}
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.frodo_sample_f a t (v i))
let frodo_sample_f a t i =
recall_contents (cdf_table a) (FP.cdf_table a);
let ti = index (cdf_table a) i in
FP.lemma_cdf_list a (v i);
Lemmas.lemma_frodo_sample t ti;
to_u16 (to_u32 (ti -. t)) >>. 15ul
inline_for_extraction noextract
val frodo_sample_res:
a:FP.frodo_alg
-> sign:uint16{v sign <= 1}
-> sample:uint16{v sample < v (cdf_table_len a)}
-> res:uint16{res == S.frodo_sample_res a sign (v sample)}
let frodo_sample_res a sign sample =
Lemmas.lemma_frodo_sample2 sign sample;
((lognot sign +. u16 1) ^. sample) +. sign
inline_for_extraction noextract
let frodo_sample_st (a:FP.frodo_alg) =
r:uint16
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 res h1 -> modifies0 h0 h1 /\
res == S.frodo_sample a r)
#push-options "--fuel 1"
inline_for_extraction noextract
val frodo_sample: a:FP.frodo_alg -> frodo_sample_st a
let frodo_sample a r =
push_frame();
let prnd = r >>. 1ul in
let sign = r &. u16 1 in
mod_mask_lemma r 1ul;
assert (v #U16 #SEC (mod_mask 1ul) == 1);
assert (v sign == 0 \/ v sign == 1);
let sample :lbuffer uint16 1ul = create (size 1) (u16 0) in
let h = ST.get () in
assert (LSeq.index #_ #1 (as_seq h sample) 0 == u16 0);
assert (bget h sample 0 == u16 0);
let bound = cdf_table_len a -! 1ul in
let h0 = ST.get () in
Lib.Loops.for 0ul bound
(fun h i ->
modifies1 sample h0 h /\
v (bget h sample 0) == S.frodo_sample_fc a prnd i)
(fun i ->
let sample0 = sample.(0ul) in
let samplei = frodo_sample_f a prnd i in
sample.(0ul) <- samplei +. sample0
);
let sample0 = sample.(0ul) in
assert (v sample0 == S.frodo_sample_fc a prnd (v bound));
let res = frodo_sample_res a sign sample0 in
pop_frame();
res
#pop-options
inline_for_extraction noextract
val frodo_sample_matrix1:
a:FP.frodo_alg
-> frodo_sample:frodo_sample_st a
-> n1:size_t
-> n2:size_t{0 < 2 * v n1 * v n2 /\ 2 * v n1 * v n2 <= max_size_t}
-> r:lbuffer uint8 (size 2 *! n1 *! n2)
-> i:size_t{v i < v n1}
-> res:matrix_t n1 n2
-> Stack unit
(requires fun h ->
live h r /\ live h res /\ disjoint r res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res ==
S.frodo_sample_matrix1 a (v n1) (v n2) (as_seq h0 r) (v i) (as_matrix h0 res))
let frodo_sample_matrix1 a frodo_sample n1 n2 r i res =
[@ inline_let]
let spec h0 = S.frodo_sample_matrix0 a (v n1) (v n2) (as_seq h0 r) (v i) in
let h0 = ST.get () in
loop1 h0 n2 res spec
(fun j ->
Loops.unfold_repeati (v n2) (spec h0) (as_seq h0 res) (v j);
Lemmas.lemma_matrix_index_repeati1 (v n1) (v n2) (v i) (v j);
let resij = sub r (size 2 *! (n2 *! i +! j)) (size 2) in
mset res i j (frodo_sample (uint_from_bytes_le #U16 resij))
) | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Params.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Sample.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "FP"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Sample",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Frodo.Params.frodo_alg -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.max_size_t",
"Hacl.Impl.Matrix.lbytes",
"Lib.IntTypes.op_Star_Bang",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Matrix.matrix_t",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint8",
"Hacl.Impl.Matrix.elem",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies1",
"Prims.eq2",
"Spec.Matrix.matrix",
"Hacl.Impl.Matrix.as_matrix",
"Spec.Frodo.Sample.frodo_sample_matrix",
"Lib.Buffer.as_seq"
] | [] | false | false | false | true | true | let frodo_sample_matrix_st (a: FP.frodo_alg) =
|
n1: size_t ->
n2: size_t{0 < (2 * v n1) * v n2 /\ (2 * v n1) * v n2 <= max_size_t} ->
r: lbytes (2ul *! n1 *! n2) ->
res: matrix_t n1 n2
-> Stack unit
(requires fun h -> live h r /\ live h res /\ disjoint r res)
(ensures
fun h0 r_ h1 ->
modifies1 res h0 h1 /\
as_matrix h1 res == S.frodo_sample_matrix a (v n1) (v n2) (as_seq h0 r)) | false |
|
FStar.SizeT.fst | FStar.SizeT.t | val t : eqtype | val t : eqtype | let t = x:U64.t { U64.v x < bound } | {
"file_name": "ulib/FStar.SizeT.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 35,
"end_line": 13,
"start_col": 0,
"start_line": 13
} | module FStar.SizeT
open FStar.Ghost
module I64 = FStar.Int64
(* This is only intended as a model, but will be extracted natively by Krml
with the correct C semantics *)
(* We assume the existence of some lower bound on the size,
where the bound is at least 2^16 *)
assume
val bound : x:erased nat { x >= pow2 16 } | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Int64.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.SizeT.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int64",
"short_module": "I64"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 | Prims.eqtype | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt64.v",
"FStar.Ghost.reveal",
"Prims.nat",
"FStar.SizeT.bound"
] | [] | false | false | false | true | false | let t =
| x: U64.t{U64.v x < bound} | false |
FStar.SizeT.fst | FStar.SizeT.fits_u32 | val fits_u32 : prop | val fits_u32 : prop | let fits_u32 = (reveal bound >= pow2 32) == true | {
"file_name": "ulib/FStar.SizeT.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 48,
"end_line": 35,
"start_col": 0,
"start_line": 35
} | module FStar.SizeT
open FStar.Ghost
module I64 = FStar.Int64
(* This is only intended as a model, but will be extracted natively by Krml
with the correct C semantics *)
(* We assume the existence of some lower bound on the size,
where the bound is at least 2^16 *)
assume
val bound : x:erased nat { x >= pow2 16 }
let t = x:U64.t { U64.v x < bound }
let fits x =
FStar.UInt.fits x U64.n == true /\
x < bound
let fits_at_least_16 _ = ()
let v x =
U64.v x
irreducible
let uint_to_t x =
U64.uint_to_t x
let size_v_inj (x: t) = ()
let size_uint_to_t_inj (x: nat) = ()
/// These two predicates are only used for modeling purposes, and their definitions must
/// remain abstract to ensure they can only be introduced through a static assert. | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Int64.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.SizeT.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int64",
"short_module": "I64"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 | Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Prims.eq2",
"Prims.bool",
"Prims.op_GreaterThanOrEqual",
"FStar.Ghost.reveal",
"Prims.nat",
"FStar.SizeT.bound",
"Prims.pow2"
] | [] | false | false | false | true | true | let fits_u32 =
| (reveal bound >= pow2 32) == true | false |
FStar.SizeT.fst | FStar.SizeT.v | val v (x: t) : Pure nat
(requires True)
(ensures (fun y -> fits y)) | val v (x: t) : Pure nat
(requires True)
(ensures (fun y -> fits y)) | let v x =
U64.v x | {
"file_name": "ulib/FStar.SizeT.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 9,
"end_line": 22,
"start_col": 0,
"start_line": 21
} | module FStar.SizeT
open FStar.Ghost
module I64 = FStar.Int64
(* This is only intended as a model, but will be extracted natively by Krml
with the correct C semantics *)
(* We assume the existence of some lower bound on the size,
where the bound is at least 2^16 *)
assume
val bound : x:erased nat { x >= pow2 16 }
let t = x:U64.t { U64.v x < bound }
let fits x =
FStar.UInt.fits x U64.n == true /\
x < bound
let fits_at_least_16 _ = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Int64.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.SizeT.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int64",
"short_module": "I64"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.SizeT.t -> Prims.Pure Prims.nat | Prims.Pure | [] | [] | [
"FStar.SizeT.t",
"FStar.UInt64.v",
"Prims.nat"
] | [] | false | false | false | false | false | let v x =
| U64.v x | false |
Steel.ST.C.Types.Scalar.fsti | Steel.ST.C.Types.Scalar.read | val read (#t: Type) (#v: Ghost.erased (scalar_t t)) (r: ref (scalar t))
: ST t
(pts_to r v)
(fun _ -> pts_to r v)
(exists v0 p. Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p)
(fun v1 -> forall v0 p. Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p ==> v0 == v1
) | val read (#t: Type) (#v: Ghost.erased (scalar_t t)) (r: ref (scalar t))
: ST t
(pts_to r v)
(fun _ -> pts_to r v)
(exists v0 p. Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p)
(fun v1 -> forall v0 p. Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p ==> v0 == v1
) | let read (#t: Type) (#v: Ghost.erased (scalar_t t)) (r: ref (scalar t)) : ST t
(pts_to r v)
(fun _ -> pts_to r v)
(exists v0 p . Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p)
(fun v1 -> forall v0 p . (* {:pattern (mk_fraction (scalar t) (mk_scalar v0) p)} *) Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p ==> v0 == v1)
= let v0 = FStar.IndefiniteDescription.indefinite_description_tot _ (fun v0 -> exists p . Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p) in
let p = FStar.IndefiniteDescription.indefinite_description_tot _ (fun p -> Ghost.reveal v == mk_fraction (scalar t) (mk_scalar (Ghost.reveal v0)) p) in
let prf v0' p' : Lemma
(requires (Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0') p'))
(ensures (v0' == Ghost.reveal v0 /\ p' == Ghost.reveal p))
= mk_scalar_inj (Ghost.reveal v0) v0' p p'
in
let prf' v0' p' : Lemma
(Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0') p' ==> (v0' == Ghost.reveal v0 /\ p' == Ghost.reveal p))
= Classical.move_requires (prf v0') p'
in
Classical.forall_intro_2 prf';
rewrite (pts_to _ _) (pts_to r (mk_fraction (scalar t) (mk_scalar (Ghost.reveal v0)) p));
let v1 = read0 r in
rewrite (pts_to _ _) (pts_to r v);
return v1 | {
"file_name": "lib/steel/c/Steel.ST.C.Types.Scalar.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 11,
"end_line": 126,
"start_col": 0,
"start_line": 106
} | module Steel.ST.C.Types.Scalar
open Steel.ST.Util
include Steel.ST.C.Types.Base
module P = Steel.FractionalPermission
// To be extracted as: t
[@@noextract_to "krml"] // primitive
val scalar_t ( [@@@strictly_positive] t: Type0) : Type0
[@@noextract_to "krml"] // proof-only
val scalar (t: Type) : typedef (scalar_t t)
val mk_scalar (#t: Type) (v: t) : Ghost (scalar_t t)
(requires True)
(ensures (fun y ->
fractionable (scalar t) y /\
full (scalar t) y
))
val mk_scalar_fractionable
(#t: Type)
(v: t)
(p: P.perm)
: Lemma
(requires (fractionable (scalar t) (mk_fraction (scalar t) (mk_scalar v) p)))
(ensures (p `P.lesser_equal_perm` P.full_perm))
val mk_scalar_inj
(#t: Type)
(v1 v2: t)
(p1 p2: P.perm)
: Lemma
(requires (mk_fraction (scalar t) (mk_scalar v1) p1 == mk_fraction (scalar t) (mk_scalar v2) p2))
(ensures (v1 == v2 /\ p1 == p2))
[SMTPat [mk_fraction (scalar t) (mk_scalar v1) p1; mk_fraction (scalar t) (mk_scalar v2) p2]]
let scalar_unique
(#opened: _)
(#t: Type)
(v1 v2: t)
(p1 p2: P.perm)
(r: ref (scalar t))
: STGhost unit opened
(pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1) `star` pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2))
(fun _ -> pts_to r (mk_fraction (scalar t) (mk_scalar v1) p1) `star` pts_to r (mk_fraction (scalar t) (mk_scalar v2) p2))
(True)
(fun _ -> v1 == v2 /\ (p1 `P.sum_perm` p2) `P.lesser_equal_perm` P.full_perm)
= fractional_permissions_theorem (mk_scalar v1) (mk_scalar v2) p1 p2 r;
mk_scalar_inj v1 v2 P.full_perm P.full_perm
[@@noextract_to "krml"] // primitive
val read0 (#t: Type) (#v: Ghost.erased t) (#p: P.perm) (r: ref (scalar t)) : ST t
(pts_to r (mk_fraction (scalar t) (mk_scalar (Ghost.reveal v)) p))
(fun _ -> pts_to r (mk_fraction (scalar t) (mk_scalar (Ghost.reveal v)) p))
(True)
(fun v' -> v' == Ghost.reveal v)
let mk_fraction_full_scalar (#t: Type) (v: t) : Lemma
(mk_scalar v == mk_fraction (scalar t) (mk_scalar v) P.full_perm)
[SMTPat (mk_scalar v)]
= ()
val get_scalar_value
(#t: Type)
(c: scalar_t t)
: GTot (option t)
val get_scalar_value_mk_fraction
(#t: Type)
(c: scalar_t t)
(p: perm)
: Lemma
(requires (fractionable (scalar t) c))
(ensures (get_scalar_value (mk_fraction (scalar t) c p) == get_scalar_value c))
[SMTPat (get_scalar_value (mk_fraction (scalar t) c p))]
val get_scalar_value_mk_scalar
(#t: Type)
(c: t)
: Lemma
(get_scalar_value (mk_scalar c) == Some c)
[SMTPat (get_scalar_value (mk_scalar c))]
val get_scalar_value_uninitialized
(t: Type)
: Lemma
(get_scalar_value (uninitialized (scalar t)) == None)
[SMTPat (get_scalar_value (uninitialized (scalar t)))]
val get_scalar_value_unknown
(t: Type)
: Lemma
(get_scalar_value (unknown (scalar t)) == None)
[SMTPat (get_scalar_value (unknown (scalar t)))]
val get_scalar_value_some
(#t: Type)
(c: scalar_t t)
: Lemma
(requires (Some? (get_scalar_value c)))
(ensures (
exists v0 p . Ghost.reveal c == mk_fraction (scalar t) (mk_scalar v0) p
))
[SMTPat (get_scalar_value c)] | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.C.Types.Base.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.C.Types.Scalar.fsti"
} | [
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST.C.Types.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.C.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r: Steel.ST.C.Types.Base.ref (Steel.ST.C.Types.Scalar.scalar t) -> Steel.ST.Effect.ST t | Steel.ST.Effect.ST | [] | [] | [
"FStar.Ghost.erased",
"Steel.ST.C.Types.Scalar.scalar_t",
"Steel.ST.C.Types.Base.ref",
"Steel.ST.C.Types.Scalar.scalar",
"Steel.ST.Util.return",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.ST.C.Types.Base.pts_to",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.ST.Util.rewrite",
"Steel.ST.C.Types.Base.mk_fraction",
"Steel.ST.C.Types.Scalar.mk_scalar",
"FStar.Ghost.reveal",
"Steel.FractionalPermission.perm",
"Steel.ST.C.Types.Scalar.read0",
"FStar.Classical.forall_intro_2",
"Prims.l_imp",
"Prims.eq2",
"Prims.l_and",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Classical.move_requires",
"Steel.ST.C.Types.Scalar.mk_scalar_inj",
"FStar.IndefiniteDescription.indefinite_description_tot",
"Prims.prop",
"Prims.l_Exists",
"Prims.l_Forall"
] | [] | false | true | false | false | false | let read (#t: Type) (#v: Ghost.erased (scalar_t t)) (r: ref (scalar t))
: ST t
(pts_to r v)
(fun _ -> pts_to r v)
(exists v0 p. Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p)
(fun v1 -> forall v0 p. Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p ==> v0 == v1
) =
| let v0 =
FStar.IndefiniteDescription.indefinite_description_tot _
(fun v0 -> exists p. Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0) p)
in
let p =
FStar.IndefiniteDescription.indefinite_description_tot _
(fun p -> Ghost.reveal v == mk_fraction (scalar t) (mk_scalar (Ghost.reveal v0)) p)
in
let prf v0' p'
: Lemma (requires (Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0') p'))
(ensures (v0' == Ghost.reveal v0 /\ p' == Ghost.reveal p)) =
mk_scalar_inj (Ghost.reveal v0) v0' p p'
in
let prf' v0' p'
: Lemma
(Ghost.reveal v == mk_fraction (scalar t) (mk_scalar v0') p' ==>
(v0' == Ghost.reveal v0 /\ p' == Ghost.reveal p)) =
Classical.move_requires (prf v0') p'
in
Classical.forall_intro_2 prf';
rewrite (pts_to _ _) (pts_to r (mk_fraction (scalar t) (mk_scalar (Ghost.reveal v0)) p));
let v1 = read0 r in
rewrite (pts_to _ _) (pts_to r v);
return v1 | false |
FStar.SizeT.fst | FStar.SizeT.uint_to_t | val uint_to_t (x: nat) : Pure t
(requires (fits x))
(ensures (fun y -> v y == x)) | val uint_to_t (x: nat) : Pure t
(requires (fits x))
(ensures (fun y -> v y == x)) | let uint_to_t x =
U64.uint_to_t x | {
"file_name": "ulib/FStar.SizeT.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 17,
"end_line": 26,
"start_col": 0,
"start_line": 25
} | module FStar.SizeT
open FStar.Ghost
module I64 = FStar.Int64
(* This is only intended as a model, but will be extracted natively by Krml
with the correct C semantics *)
(* We assume the existence of some lower bound on the size,
where the bound is at least 2^16 *)
assume
val bound : x:erased nat { x >= pow2 16 }
let t = x:U64.t { U64.v x < bound }
let fits x =
FStar.UInt.fits x U64.n == true /\
x < bound
let fits_at_least_16 _ = ()
let v x =
U64.v x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Int64.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.SizeT.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int64",
"short_module": "I64"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.nat -> Prims.Pure FStar.SizeT.t | Prims.Pure | [] | [] | [
"Prims.nat",
"FStar.UInt64.uint_to_t",
"FStar.SizeT.t"
] | [] | false | false | false | false | false | let uint_to_t x =
| U64.uint_to_t x | false |
Hacl.Impl.Frodo.Sample.fst | Hacl.Impl.Frodo.Sample.frodo_sample_matrix | val frodo_sample_matrix (a: FP.frodo_alg) : frodo_sample_matrix_st a | val frodo_sample_matrix (a: FP.frodo_alg) : frodo_sample_matrix_st a | let frodo_sample_matrix (a:FP.frodo_alg) : frodo_sample_matrix_st a =
match a with
| FP.Frodo64 -> frodo_sample_matrix64
| FP.Frodo640 -> frodo_sample_matrix640
| FP.Frodo976 -> frodo_sample_matrix976
| FP.Frodo1344 -> frodo_sample_matrix1344 | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Sample.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 178,
"start_col": 0,
"start_line": 173
} | module Hacl.Impl.Frodo.Sample
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
open Hacl.Impl.Frodo.Params
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Lemmas = Spec.Frodo.Lemmas
module S = Spec.Frodo.Sample
module FP = Spec.Frodo.Params
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val frodo_sample_f:
a:FP.frodo_alg
-> t:uint16{uint_v t < pow2 15}
-> i:size_t{v i < v (cdf_table_len a)}
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.frodo_sample_f a t (v i))
let frodo_sample_f a t i =
recall_contents (cdf_table a) (FP.cdf_table a);
let ti = index (cdf_table a) i in
FP.lemma_cdf_list a (v i);
Lemmas.lemma_frodo_sample t ti;
to_u16 (to_u32 (ti -. t)) >>. 15ul
inline_for_extraction noextract
val frodo_sample_res:
a:FP.frodo_alg
-> sign:uint16{v sign <= 1}
-> sample:uint16{v sample < v (cdf_table_len a)}
-> res:uint16{res == S.frodo_sample_res a sign (v sample)}
let frodo_sample_res a sign sample =
Lemmas.lemma_frodo_sample2 sign sample;
((lognot sign +. u16 1) ^. sample) +. sign
inline_for_extraction noextract
let frodo_sample_st (a:FP.frodo_alg) =
r:uint16
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 res h1 -> modifies0 h0 h1 /\
res == S.frodo_sample a r)
#push-options "--fuel 1"
inline_for_extraction noextract
val frodo_sample: a:FP.frodo_alg -> frodo_sample_st a
let frodo_sample a r =
push_frame();
let prnd = r >>. 1ul in
let sign = r &. u16 1 in
mod_mask_lemma r 1ul;
assert (v #U16 #SEC (mod_mask 1ul) == 1);
assert (v sign == 0 \/ v sign == 1);
let sample :lbuffer uint16 1ul = create (size 1) (u16 0) in
let h = ST.get () in
assert (LSeq.index #_ #1 (as_seq h sample) 0 == u16 0);
assert (bget h sample 0 == u16 0);
let bound = cdf_table_len a -! 1ul in
let h0 = ST.get () in
Lib.Loops.for 0ul bound
(fun h i ->
modifies1 sample h0 h /\
v (bget h sample 0) == S.frodo_sample_fc a prnd i)
(fun i ->
let sample0 = sample.(0ul) in
let samplei = frodo_sample_f a prnd i in
sample.(0ul) <- samplei +. sample0
);
let sample0 = sample.(0ul) in
assert (v sample0 == S.frodo_sample_fc a prnd (v bound));
let res = frodo_sample_res a sign sample0 in
pop_frame();
res
#pop-options
inline_for_extraction noextract
val frodo_sample_matrix1:
a:FP.frodo_alg
-> frodo_sample:frodo_sample_st a
-> n1:size_t
-> n2:size_t{0 < 2 * v n1 * v n2 /\ 2 * v n1 * v n2 <= max_size_t}
-> r:lbuffer uint8 (size 2 *! n1 *! n2)
-> i:size_t{v i < v n1}
-> res:matrix_t n1 n2
-> Stack unit
(requires fun h ->
live h r /\ live h res /\ disjoint r res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res ==
S.frodo_sample_matrix1 a (v n1) (v n2) (as_seq h0 r) (v i) (as_matrix h0 res))
let frodo_sample_matrix1 a frodo_sample n1 n2 r i res =
[@ inline_let]
let spec h0 = S.frodo_sample_matrix0 a (v n1) (v n2) (as_seq h0 r) (v i) in
let h0 = ST.get () in
loop1 h0 n2 res spec
(fun j ->
Loops.unfold_repeati (v n2) (spec h0) (as_seq h0 res) (v j);
Lemmas.lemma_matrix_index_repeati1 (v n1) (v n2) (v i) (v j);
let resij = sub r (size 2 *! (n2 *! i +! j)) (size 2) in
mset res i j (frodo_sample (uint_from_bytes_le #U16 resij))
)
inline_for_extraction noextract
let frodo_sample_matrix_st (a:FP.frodo_alg) =
n1:size_t
-> n2:size_t{0 < 2 * v n1 * v n2 /\ 2 * v n1 * v n2 <= max_size_t}
-> r:lbytes (2ul *! n1 *! n2)
-> res:matrix_t n1 n2
-> Stack unit
(requires fun h ->
live h r /\ live h res /\ disjoint r res)
(ensures fun h0 r_ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res == S.frodo_sample_matrix a (v n1) (v n2) (as_seq h0 r))
inline_for_extraction noextract
val frodo_sample_matrix_:
a:FP.frodo_alg
-> frodo_sample:frodo_sample_st a
-> frodo_sample_matrix_st a
let frodo_sample_matrix_ a frodo_sample n1 n2 r res =
memset res (u16 0) (n1 *! n2);
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 (v n1 * v n2)) (as_seq h0 res);
[@ inline_let]
let spec h0 = S.frodo_sample_matrix1 a (v n1) (v n2) (as_seq h0 r) in
loop1 h0 n1 res spec
(fun i ->
Loops.unfold_repeati (v n1) (spec h0) (as_seq h0 res) (v i);
frodo_sample_matrix1 a frodo_sample n1 n2 r i res
)
[@CInline]
let frodo_sample_matrix64 : frodo_sample_matrix_st FP.Frodo64 =
frodo_sample_matrix_ FP.Frodo64 (frodo_sample FP.Frodo64)
[@CInline]
let frodo_sample_matrix640 : frodo_sample_matrix_st FP.Frodo640 =
frodo_sample_matrix_ FP.Frodo640 (frodo_sample FP.Frodo640)
[@CInline]
let frodo_sample_matrix976 : frodo_sample_matrix_st FP.Frodo976 =
frodo_sample_matrix_ FP.Frodo976 (frodo_sample FP.Frodo976)
[@CInline]
let frodo_sample_matrix1344 : frodo_sample_matrix_st FP.Frodo1344=
frodo_sample_matrix_ FP.Frodo1344 (frodo_sample FP.Frodo1344) | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Params.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Sample.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "FP"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Sample",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Frodo.Params.frodo_alg -> Hacl.Impl.Frodo.Sample.frodo_sample_matrix_st a | Prims.Tot | [
"total"
] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Hacl.Impl.Frodo.Sample.frodo_sample_matrix64",
"Hacl.Impl.Frodo.Sample.frodo_sample_matrix640",
"Hacl.Impl.Frodo.Sample.frodo_sample_matrix976",
"Hacl.Impl.Frodo.Sample.frodo_sample_matrix1344",
"Hacl.Impl.Frodo.Sample.frodo_sample_matrix_st"
] | [] | false | false | false | false | false | let frodo_sample_matrix (a: FP.frodo_alg) : frodo_sample_matrix_st a =
| match a with
| FP.Frodo64 -> frodo_sample_matrix64
| FP.Frodo640 -> frodo_sample_matrix640
| FP.Frodo976 -> frodo_sample_matrix976
| FP.Frodo1344 -> frodo_sample_matrix1344 | false |
FStar.SizeT.fst | FStar.SizeT.fits_u64 | val fits_u64 : prop | val fits_u64 : prop | let fits_u64 = (reveal bound == pow2 64) | {
"file_name": "ulib/FStar.SizeT.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 36,
"start_col": 0,
"start_line": 36
} | module FStar.SizeT
open FStar.Ghost
module I64 = FStar.Int64
(* This is only intended as a model, but will be extracted natively by Krml
with the correct C semantics *)
(* We assume the existence of some lower bound on the size,
where the bound is at least 2^16 *)
assume
val bound : x:erased nat { x >= pow2 16 }
let t = x:U64.t { U64.v x < bound }
let fits x =
FStar.UInt.fits x U64.n == true /\
x < bound
let fits_at_least_16 _ = ()
let v x =
U64.v x
irreducible
let uint_to_t x =
U64.uint_to_t x
let size_v_inj (x: t) = ()
let size_uint_to_t_inj (x: nat) = ()
/// These two predicates are only used for modeling purposes, and their definitions must
/// remain abstract to ensure they can only be introduced through a static assert.
/// We simply define them as True here | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Int64.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.SizeT.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int64",
"short_module": "I64"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"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 | Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_GreaterThan",
"FStar.Ghost.reveal",
"Prims.nat",
"FStar.SizeT.bound",
"Prims.pow2"
] | [] | false | false | false | true | true | let fits_u64 =
| (reveal bound == pow2 64) | false |
Hacl.Impl.Frodo.Sample.fst | Hacl.Impl.Frodo.Sample.frodo_sample_matrix_ | val frodo_sample_matrix_:
a:FP.frodo_alg
-> frodo_sample:frodo_sample_st a
-> frodo_sample_matrix_st a | val frodo_sample_matrix_:
a:FP.frodo_alg
-> frodo_sample:frodo_sample_st a
-> frodo_sample_matrix_st a | let frodo_sample_matrix_ a frodo_sample n1 n2 r res =
memset res (u16 0) (n1 *! n2);
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 (v n1 * v n2)) (as_seq h0 res);
[@ inline_let]
let spec h0 = S.frodo_sample_matrix1 a (v n1) (v n2) (as_seq h0 r) in
loop1 h0 n1 res spec
(fun i ->
Loops.unfold_repeati (v n1) (spec h0) (as_seq h0 res) (v i);
frodo_sample_matrix1 a frodo_sample n1 n2 r i res
) | {
"file_name": "code/frodo/Hacl.Impl.Frodo.Sample.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 156,
"start_col": 0,
"start_line": 145
} | module Hacl.Impl.Frodo.Sample
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Matrix
open Hacl.Impl.Frodo.Params
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Lemmas = Spec.Frodo.Lemmas
module S = Spec.Frodo.Sample
module FP = Spec.Frodo.Params
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val frodo_sample_f:
a:FP.frodo_alg
-> t:uint16{uint_v t < pow2 15}
-> i:size_t{v i < v (cdf_table_len a)}
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
v r == S.frodo_sample_f a t (v i))
let frodo_sample_f a t i =
recall_contents (cdf_table a) (FP.cdf_table a);
let ti = index (cdf_table a) i in
FP.lemma_cdf_list a (v i);
Lemmas.lemma_frodo_sample t ti;
to_u16 (to_u32 (ti -. t)) >>. 15ul
inline_for_extraction noextract
val frodo_sample_res:
a:FP.frodo_alg
-> sign:uint16{v sign <= 1}
-> sample:uint16{v sample < v (cdf_table_len a)}
-> res:uint16{res == S.frodo_sample_res a sign (v sample)}
let frodo_sample_res a sign sample =
Lemmas.lemma_frodo_sample2 sign sample;
((lognot sign +. u16 1) ^. sample) +. sign
inline_for_extraction noextract
let frodo_sample_st (a:FP.frodo_alg) =
r:uint16
-> Stack uint16
(requires fun h -> True)
(ensures fun h0 res h1 -> modifies0 h0 h1 /\
res == S.frodo_sample a r)
#push-options "--fuel 1"
inline_for_extraction noextract
val frodo_sample: a:FP.frodo_alg -> frodo_sample_st a
let frodo_sample a r =
push_frame();
let prnd = r >>. 1ul in
let sign = r &. u16 1 in
mod_mask_lemma r 1ul;
assert (v #U16 #SEC (mod_mask 1ul) == 1);
assert (v sign == 0 \/ v sign == 1);
let sample :lbuffer uint16 1ul = create (size 1) (u16 0) in
let h = ST.get () in
assert (LSeq.index #_ #1 (as_seq h sample) 0 == u16 0);
assert (bget h sample 0 == u16 0);
let bound = cdf_table_len a -! 1ul in
let h0 = ST.get () in
Lib.Loops.for 0ul bound
(fun h i ->
modifies1 sample h0 h /\
v (bget h sample 0) == S.frodo_sample_fc a prnd i)
(fun i ->
let sample0 = sample.(0ul) in
let samplei = frodo_sample_f a prnd i in
sample.(0ul) <- samplei +. sample0
);
let sample0 = sample.(0ul) in
assert (v sample0 == S.frodo_sample_fc a prnd (v bound));
let res = frodo_sample_res a sign sample0 in
pop_frame();
res
#pop-options
inline_for_extraction noextract
val frodo_sample_matrix1:
a:FP.frodo_alg
-> frodo_sample:frodo_sample_st a
-> n1:size_t
-> n2:size_t{0 < 2 * v n1 * v n2 /\ 2 * v n1 * v n2 <= max_size_t}
-> r:lbuffer uint8 (size 2 *! n1 *! n2)
-> i:size_t{v i < v n1}
-> res:matrix_t n1 n2
-> Stack unit
(requires fun h ->
live h r /\ live h res /\ disjoint r res)
(ensures fun h0 _ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res ==
S.frodo_sample_matrix1 a (v n1) (v n2) (as_seq h0 r) (v i) (as_matrix h0 res))
let frodo_sample_matrix1 a frodo_sample n1 n2 r i res =
[@ inline_let]
let spec h0 = S.frodo_sample_matrix0 a (v n1) (v n2) (as_seq h0 r) (v i) in
let h0 = ST.get () in
loop1 h0 n2 res spec
(fun j ->
Loops.unfold_repeati (v n2) (spec h0) (as_seq h0 res) (v j);
Lemmas.lemma_matrix_index_repeati1 (v n1) (v n2) (v i) (v j);
let resij = sub r (size 2 *! (n2 *! i +! j)) (size 2) in
mset res i j (frodo_sample (uint_from_bytes_le #U16 resij))
)
inline_for_extraction noextract
let frodo_sample_matrix_st (a:FP.frodo_alg) =
n1:size_t
-> n2:size_t{0 < 2 * v n1 * v n2 /\ 2 * v n1 * v n2 <= max_size_t}
-> r:lbytes (2ul *! n1 *! n2)
-> res:matrix_t n1 n2
-> Stack unit
(requires fun h ->
live h r /\ live h res /\ disjoint r res)
(ensures fun h0 r_ h1 -> modifies1 res h0 h1 /\
as_matrix h1 res == S.frodo_sample_matrix a (v n1) (v n2) (as_seq h0 r))
inline_for_extraction noextract
val frodo_sample_matrix_:
a:FP.frodo_alg
-> frodo_sample:frodo_sample_st a
-> frodo_sample_matrix_st a | {
"checked_file": "/",
"dependencies": [
"Spec.Frodo.Sample.fst.checked",
"Spec.Frodo.Params.fst.checked",
"Spec.Frodo.Lemmas.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.Loops.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Matrix.fst.checked",
"Hacl.Impl.Frodo.Params.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Frodo.Sample.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Frodo.Params",
"short_module": "FP"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Sample",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Spec.Frodo.Lemmas",
"short_module": "Lemmas"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo.Params",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Matrix",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Frodo",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Frodo.Params.frodo_alg -> frodo_sample: Hacl.Impl.Frodo.Sample.frodo_sample_st a
-> Hacl.Impl.Frodo.Sample.frodo_sample_matrix_st a | Prims.Tot | [
"total"
] | [] | [
"Spec.Frodo.Params.frodo_alg",
"Hacl.Impl.Frodo.Sample.frodo_sample_st",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.max_size_t",
"Hacl.Impl.Matrix.lbytes",
"Lib.IntTypes.op_Star_Bang",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Matrix.matrix_t",
"Lib.Buffer.loop1",
"Hacl.Impl.Matrix.elem",
"Hacl.Impl.Frodo.Sample.frodo_sample_matrix1",
"Prims.unit",
"Lib.LoopCombinators.unfold_repeati",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U16",
"Lib.IntTypes.SEC",
"Prims.op_Multiply",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"Prims.nat",
"Prims.op_Subtraction",
"Prims.pow2",
"Spec.Frodo.Sample.frodo_sample_matrix1",
"Lib.IntTypes.uint8",
"Lib.Sequence.eq_intro",
"Lib.Sequence.sub",
"FStar.HyperStack.ST.get",
"Lib.Buffer.memset",
"Lib.IntTypes.u16"
] | [] | false | false | false | false | false | let frodo_sample_matrix_ a frodo_sample n1 n2 r res =
| memset res (u16 0) (n1 *! n2);
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 (v n1 * v n2)) (as_seq h0 res);
[@@ inline_let ]let spec h0 = S.frodo_sample_matrix1 a (v n1) (v n2) (as_seq h0 r) in
loop1 h0
n1
res
spec
(fun i ->
Loops.unfold_repeati (v n1) (spec h0) (as_seq h0 res) (v i);
frodo_sample_matrix1 a frodo_sample n1 n2 r i res) | false |
FStar.SizeT.fst | FStar.SizeT.of_u64 | val of_u64 (x: U64.t) : Pure t
(requires fits_u64)
(ensures (fun y -> v y == U64.v x)) | val of_u64 (x: U64.t) : Pure t
(requires fits_u64)
(ensures (fun y -> v y == U64.v x)) | let of_u64 (x: U64.t)
= uint_to_t (U64.v x) | {
"file_name": "ulib/FStar.SizeT.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 23,
"end_line": 60,
"start_col": 0,
"start_line": 59
} | module FStar.SizeT
open FStar.Ghost
module I64 = FStar.Int64
(* This is only intended as a model, but will be extracted natively by Krml
with the correct C semantics *)
(* We assume the existence of some lower bound on the size,
where the bound is at least 2^16 *)
assume
val bound : x:erased nat { x >= pow2 16 }
let t = x:U64.t { U64.v x < bound }
let fits x =
FStar.UInt.fits x U64.n == true /\
x < bound
let fits_at_least_16 _ = ()
let v x =
U64.v x
irreducible
let uint_to_t x =
U64.uint_to_t x
let size_v_inj (x: t) = ()
let size_uint_to_t_inj (x: nat) = ()
/// These two predicates are only used for modeling purposes, and their definitions must
/// remain abstract to ensure they can only be introduced through a static assert.
/// We simply define them as True here
let fits_u32 = (reveal bound >= pow2 32) == true
let fits_u64 = (reveal bound == pow2 64)
let fits_u64_implies_fits_32 ()
: Lemma
(requires fits_u64)
(ensures fits_u32)
= ()
let fits_u32_implies_fits (x:nat)
: Lemma
(requires fits_u32 /\ x < pow2 32)
(ensures fits x)
= ()
let fits_u64_implies_fits (x:nat)
: Lemma
(requires fits_u64 /\ x < pow2 64)
(ensures fits x)
= ()
let of_u32 (x: U32.t)
= uint_to_t (U32.v x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Int64.fsti.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": true,
"source_file": "FStar.SizeT.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Int64",
"short_module": "I64"
},
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.UInt16",
"short_module": "U16"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt64.t -> Prims.Pure FStar.SizeT.t | Prims.Pure | [] | [] | [
"FStar.UInt64.t",
"FStar.SizeT.uint_to_t",
"FStar.UInt64.v",
"FStar.SizeT.t"
] | [] | false | false | false | false | false | let of_u64 (x: U64.t) =
| uint_to_t (U64.v x) | false |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.