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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PulseCore.InstantiatedSemantics.fst | PulseCore.InstantiatedSemantics.slprop_equiv_assoc | val slprop_equiv_assoc (p1 p2 p3:slprop)
: slprop_equiv (p1 ** p2 ** p3) (p1 ** (p2 ** p3)) | val slprop_equiv_assoc (p1 p2 p3:slprop)
: slprop_equiv (p1 ** p2 ** p3) (p1 ** (p2 ** p3)) | let slprop_equiv_assoc p1 p2 p3 = unsquash () | {
"file_name": "lib/pulse_core/PulseCore.InstantiatedSemantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 45,
"end_line": 82,
"start_col": 0,
"start_line": 82
} | module PulseCore.InstantiatedSemantics
module Sem = PulseCore.Semantics
module Mem = PulseCore.Memory
module U = FStar.Universe
module F = FStar.FunctionalExtensionality
open PulseCore.Memory
let laws ()
: squash (
Sem.associative star /\
Sem.commutative star /\
Sem.is_unit emp star
)
= let equiv_eq (x y:slprop)
: Lemma (x `equiv` y <==> x == y)
[SMTPat (x `equiv` y)]
= introduce x `equiv` y ==> x == y
with _h . slprop_extensionality x y
in
let _ : squash (Sem.associative star) =
introduce
forall x y z.
((x `star` y) `star` z) ==
(x `star` (y `star` z))
with star_associative x y z
in
let _ : squash (Sem.commutative star) =
introduce
forall x y.
x `star` y == y `star` x
with star_commutative x y
in
let _ : squash (Sem.is_unit emp star) =
introduce
forall x.
(x `star` emp) == x /\
(emp `star` x) == x
with emp_unit x
in
()
let state0 (e:inames) : Sem.state = {
max_act = U.raise_t u#0 u#100 unit;
s = mem;
is_full_mem = full_mem_pred;
pred = slprop;
emp = emp;
star = star;
interp = interp;
evolves = mem_evolves;
invariant = locks_invariant e;
laws = laws ()
}
let state : Sem.state = state0 Set.empty
let slprop = slprop
let _eq : squash (slprop == state.pred) = ()
let emp = emp
let pure p = pure p
let ( ** ) p q = p `star` q
let ( exists* ) #a p = h_exists (F.on_dom a p)
let prop_squash_idem (p:prop)
: Tot (squash (p == squash p))
= FStar.PropositionalExtensionality.apply p (squash p)
let slprop_equiv p q = Mem.equiv p q
let unsquash (p:squash (slprop_equiv 'p 'q)) : slprop_equiv 'p 'q =
prop_squash_idem (slprop_equiv 'p 'q);
coerce_eq () p
let slprop_equiv_refl p = unsquash ()
let slprop_equiv_elim p q =
introduce (p `slprop_equiv` q) ==> p==q
with _ . Mem.slprop_extensionality p q
let slprop_equiv_unit p = unsquash () | {
"checked_file": "/",
"dependencies": [
"PulseCore.Semantics.fst.checked",
"PulseCore.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": true,
"source_file": "PulseCore.InstantiatedSemantics.fst"
} | [
{
"abbrev": false,
"full_module": "PulseCore.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "PulseCore.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "PulseCore.Semantics",
"short_module": "Sem"
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p1: PulseCore.InstantiatedSemantics.slprop ->
p2: PulseCore.InstantiatedSemantics.slprop ->
p3: PulseCore.InstantiatedSemantics.slprop
-> PulseCore.InstantiatedSemantics.slprop_equiv ((p1 ** p2) ** p3) (p1 ** p2 ** p3) | Prims.Tot | [
"total"
] | [] | [
"PulseCore.InstantiatedSemantics.slprop",
"PulseCore.InstantiatedSemantics.unsquash",
"PulseCore.InstantiatedSemantics.op_Star_Star",
"PulseCore.InstantiatedSemantics.slprop_equiv"
] | [] | false | false | false | false | false | let slprop_equiv_assoc p1 p2 p3 =
| unsquash () | false |
Spec.Blake2.fst | Spec.Blake2.list_sigma | val list_sigma:list_sigma_t | val list_sigma:list_sigma_t | let list_sigma: list_sigma_t =
[@inline_let]
let l : list sigma_elt_t = [
size 0; size 1; size 2; size 3; size 4; size 5; size 6; size 7;
size 8; size 9; size 10; size 11; size 12; size 13; size 14; size 15;
size 14; size 10; size 4; size 8; size 9; size 15; size 13; size 6;
size 1; size 12; size 0; size 2; size 11; size 7; size 5; size 3;
size 11; size 8; size 12; size 0; size 5; size 2; size 15; size 13;
size 10; size 14; size 3; size 6; size 7; size 1; size 9; size 4;
size 7; size 9; size 3; size 1; size 13; size 12; size 11; size 14;
size 2; size 6; size 5; size 10; size 4; size 0; size 15; size 8;
size 9; size 0; size 5; size 7; size 2; size 4; size 10; size 15;
size 14; size 1; size 11; size 12; size 6; size 8; size 3; size 13;
size 2; size 12; size 6; size 10; size 0; size 11; size 8; size 3;
size 4; size 13; size 7; size 5; size 15; size 14; size 1; size 9;
size 12; size 5; size 1; size 15; size 14; size 13; size 4; size 10;
size 0; size 7; size 6; size 3; size 9; size 2; size 8; size 11;
size 13; size 11; size 7; size 14; size 12; size 1; size 3; size 9;
size 5; size 0; size 15; size 4; size 8; size 6; size 2; size 10;
size 6; size 15; size 14; size 9; size 11; size 3; size 0; size 8;
size 12; size 2; size 13; size 7; size 1; size 4; size 10; size 5;
size 10; size 2; size 8; size 4; size 7; size 6; size 1; size 5;
size 15; size 11; size 9; size 14; size 3; size 12; size 13; size 0
] in
assert_norm(List.Tot.length l == 160);
l | {
"file_name": "specs/Spec.Blake2.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": 131
} | module Spec.Blake2
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
module UpdateMulti = Lib.UpdateMulti
include Spec.Blake2.Definitions
#set-options "--z3rlimit 50"
/// Serialize blake2s parameters to be xor'ed with the state during initialization
/// As the state is represented using uint32, we need to serialize to uint32 instead
/// of the more standard bytes representation
let serialize_blake2s_params (p: blake2s_params) : lseq uint32 8 =
let s0 = (u32 (v p.digest_length)) ^.
(u32 (v p.key_length) <<. (size 8)) ^.
(u32 (v p.fanout) <<. (size 16)) ^.
(u32 (v p.depth) <<. (size 24)) in
let s1 = p.leaf_length in
let s2 = p.node_offset in
let s3 = (u32 (v p.xof_length)) ^.
(u32 (v p.node_depth) <<. (size 16)) ^.
(u32 (v p.inner_length) <<. (size 24)) in
let salt_u32: lseq uint32 2 = uints_from_bytes_le p.salt in
let s4 = salt_u32.[0] in
let s5 = salt_u32.[1] in
let personal_u32: lseq uint32 2 = uints_from_bytes_le p.personal in
let s6 = personal_u32.[0] in
let s7 = personal_u32.[1] in
[@inline_let]
let l = [s0; s1; s2; s3; s4; s5; s6; s7] in
assert_norm (List.Tot.length l == 8);
createL l
/// Serialize blake2b parameters to be xor'ed with the state during initialization
/// As the state is represented using uint64, we need to serialize to uint64 instead
/// of the more standard bytes representation
let serialize_blake2b_params (p: blake2b_params) : lseq uint64 8 =
let s0 = (u64 (v p.digest_length)) ^.
(u64 (v p.key_length) <<. (size 8)) ^.
(u64 (v p.fanout) <<. (size 16)) ^.
(u64 (v p.depth) <<. (size 24)) ^.
(u64 (v p.leaf_length) <<. (size 32)) in
let s1 = (u64 (v p.node_offset)) ^.
(u64 (v p.xof_length) <<. (size 32)) in
// The serialization corresponding to s2 contains node_depth and inner_length,
// followed by the 14 reserved bytes which always seem to be zeros, and can hence
// be ignored when building the corresponding uint64 using xor's
let s2 = (u64 (v p.node_depth)) ^.
(u64 (v p.inner_length) <<. (size 8)) in
// s3 corresponds to the remaining of the reserved bytes
let s3 = u64 0 in
let salt_u64: lseq uint64 2 = uints_from_bytes_le p.salt in
let s4 = salt_u64.[0] in
let s5 = salt_u64.[1] in
let personal_u64: lseq uint64 2 = uints_from_bytes_le p.personal in
let s6 = personal_u64.[0] in
let s7 = personal_u64.[1] in
[@inline_let]
let l = [s0; s1; s2; s3; s4; s5; s6; s7] in
assert_norm (List.Tot.length l == 8);
createL l
inline_for_extraction
let serialize_blake2_params (#a: alg) (p: blake2_params a): lseq (word_t a) 8 =
match a with
| Blake2S -> serialize_blake2s_params p
| Blake2B -> serialize_blake2b_params p
[@"opaque_to_smt"]
inline_for_extraction
let rTable_list_S : List.Tot.llist (rotval U32) 4 =
[
size 16; size 12; size 8; size 7
]
[@"opaque_to_smt"]
inline_for_extraction
let rTable_list_B: List.Tot.llist (rotval U64) 4 =
[
size 32; size 24; size 16; size 63
]
inline_for_extraction
let rTable (a:alg) : rtable_t a =
match a with
| Blake2S -> (of_list rTable_list_S)
| Blake2B -> (of_list rTable_list_B)
[@"opaque_to_smt"]
inline_for_extraction
let list_iv_S: List.Tot.llist (uint_t U32 PUB) 8 =
[@inline_let]
let l = [
0x6A09E667ul; 0xBB67AE85ul; 0x3C6EF372ul; 0xA54FF53Aul;
0x510E527Ful; 0x9B05688Cul; 0x1F83D9ABul; 0x5BE0CD19ul] in
assert_norm(List.Tot.length l == 8);
l
[@"opaque_to_smt"]
inline_for_extraction
let list_iv_B: List.Tot.llist (uint_t U64 PUB) 8 =
[@inline_let]
let l = [
0x6A09E667F3BCC908uL; 0xBB67AE8584CAA73BuL;
0x3C6EF372FE94F82BuL; 0xA54FF53A5F1D36F1uL;
0x510E527FADE682D1uL; 0x9B05688C2B3E6C1FuL;
0x1F83D9ABFB41BD6BuL; 0x5BE0CD19137E2179uL] in
assert_norm(List.Tot.length l == 8);
l
[@"opaque_to_smt"]
inline_for_extraction
let list_iv (a:alg): List.Tot.llist (pub_word_t a) 8 =
match a with
| Blake2S -> list_iv_S
| Blake2B -> list_iv_B
inline_for_extraction
let ivTable (a:alg) : lseq (pub_word_t a) 8 =
match a with
| Blake2S -> of_list list_iv_S
| Blake2B -> of_list list_iv_B | {
"checked_file": "/",
"dependencies": [
"Spec.Blake2.Definitions.fst.checked",
"prims.fst.checked",
"Lib.UpdateMulti.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Blake2.fst"
} | [
{
"abbrev": false,
"full_module": "Spec.Blake2.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.UpdateMulti",
"short_module": "UpdateMulti"
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"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": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "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": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Spec.Blake2.Definitions.list_sigma_t | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"FStar.List.Tot.Base.length",
"Spec.Blake2.Definitions.sigma_elt_t",
"Prims.list",
"Prims.Cons",
"Lib.IntTypes.size",
"Prims.Nil"
] | [] | false | false | false | true | false | let list_sigma:list_sigma_t =
| [@@ inline_let ]let l:list sigma_elt_t =
[
size 0; size 1; size 2; size 3; size 4; size 5; size 6; size 7; size 8; size 9; size 10; size 11;
size 12; size 13; size 14; size 15; size 14; size 10; size 4; size 8; size 9; size 15; size 13;
size 6; size 1; size 12; size 0; size 2; size 11; size 7; size 5; size 3; size 11; size 8;
size 12; size 0; size 5; size 2; size 15; size 13; size 10; size 14; size 3; size 6; size 7;
size 1; size 9; size 4; size 7; size 9; size 3; size 1; size 13; size 12; size 11; size 14;
size 2; size 6; size 5; size 10; size 4; size 0; size 15; size 8; size 9; size 0; size 5; size 7;
size 2; size 4; size 10; size 15; size 14; size 1; size 11; size 12; size 6; size 8; size 3;
size 13; size 2; size 12; size 6; size 10; size 0; size 11; size 8; size 3; size 4; size 13;
size 7; size 5; size 15; size 14; size 1; size 9; size 12; size 5; size 1; size 15; size 14;
size 13; size 4; size 10; size 0; size 7; size 6; size 3; size 9; size 2; size 8; size 11;
size 13; size 11; size 7; size 14; size 12; size 1; size 3; size 9; size 5; size 0; size 15;
size 4; size 8; size 6; size 2; size 10; size 6; size 15; size 14; size 9; size 11; size 3;
size 0; size 8; size 12; size 2; size 13; size 7; size 1; size 4; size 10; size 5; size 10;
size 2; size 8; size 4; size 7; size 6; size 1; size 5; size 15; size 11; size 9; size 14;
size 3; size 12; size 13; size 0
]
in
assert_norm (List.Tot.length l == 160);
l | false |
PulseCore.InstantiatedSemantics.fst | PulseCore.InstantiatedSemantics.slprop_equiv_exists | val slprop_equiv_exists
(#a:Type)
(p q: a -> slprop)
(_:squash (forall x. slprop_equiv (p x) (q x)))
: slprop_equiv (op_exists_Star p) (op_exists_Star q) | val slprop_equiv_exists
(#a:Type)
(p q: a -> slprop)
(_:squash (forall x. slprop_equiv (p x) (q x)))
: slprop_equiv (op_exists_Star p) (op_exists_Star q) | let slprop_equiv_exists
(#a:Type)
(p q: a -> slprop)
(_:squash (forall x. slprop_equiv (p x) (q x)))
= introduce forall x. p x == q x
with slprop_equiv_elim (p x) (q x);
F.extensionality _ _ p q;
let pf : squash (eq2 #(F.arrow a (fun _ -> slprop))
(F.on_dom a p)
(F.on_dom a q)) = ()
in
let x : squash (op_exists_Star p == op_exists_Star q) = _ by (
T.norm [delta_only [`%op_exists_Star; `%F.on_dom]; unascribe];
let bindings = T.cur_vars() in
let bindings = List.Tot.rev bindings in
match bindings with
| hd::_ -> (
match T.term_as_formula hd.sort with
| T.Comp (T.Eq _) lhs rhs ->
T.grewrite lhs rhs;
T.trefl();
T.exact (T.binding_to_term hd)
| _ -> T.fail "Unexpected type of hd"
)
| _ ->
T.fail "empty bindings"
) in
unsquash x | {
"file_name": "lib/pulse_core/PulseCore.InstantiatedSemantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 12,
"end_line": 111,
"start_col": 0,
"start_line": 84
} | module PulseCore.InstantiatedSemantics
module Sem = PulseCore.Semantics
module Mem = PulseCore.Memory
module U = FStar.Universe
module F = FStar.FunctionalExtensionality
open PulseCore.Memory
let laws ()
: squash (
Sem.associative star /\
Sem.commutative star /\
Sem.is_unit emp star
)
= let equiv_eq (x y:slprop)
: Lemma (x `equiv` y <==> x == y)
[SMTPat (x `equiv` y)]
= introduce x `equiv` y ==> x == y
with _h . slprop_extensionality x y
in
let _ : squash (Sem.associative star) =
introduce
forall x y z.
((x `star` y) `star` z) ==
(x `star` (y `star` z))
with star_associative x y z
in
let _ : squash (Sem.commutative star) =
introduce
forall x y.
x `star` y == y `star` x
with star_commutative x y
in
let _ : squash (Sem.is_unit emp star) =
introduce
forall x.
(x `star` emp) == x /\
(emp `star` x) == x
with emp_unit x
in
()
let state0 (e:inames) : Sem.state = {
max_act = U.raise_t u#0 u#100 unit;
s = mem;
is_full_mem = full_mem_pred;
pred = slprop;
emp = emp;
star = star;
interp = interp;
evolves = mem_evolves;
invariant = locks_invariant e;
laws = laws ()
}
let state : Sem.state = state0 Set.empty
let slprop = slprop
let _eq : squash (slprop == state.pred) = ()
let emp = emp
let pure p = pure p
let ( ** ) p q = p `star` q
let ( exists* ) #a p = h_exists (F.on_dom a p)
let prop_squash_idem (p:prop)
: Tot (squash (p == squash p))
= FStar.PropositionalExtensionality.apply p (squash p)
let slprop_equiv p q = Mem.equiv p q
let unsquash (p:squash (slprop_equiv 'p 'q)) : slprop_equiv 'p 'q =
prop_squash_idem (slprop_equiv 'p 'q);
coerce_eq () p
let slprop_equiv_refl p = unsquash ()
let slprop_equiv_elim p q =
introduce (p `slprop_equiv` q) ==> p==q
with _ . Mem.slprop_extensionality p q
let slprop_equiv_unit p = unsquash ()
let slprop_equiv_comm p1 p2 = unsquash ()
let slprop_equiv_assoc p1 p2 p3 = unsquash () | {
"checked_file": "/",
"dependencies": [
"PulseCore.Semantics.fst.checked",
"PulseCore.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": true,
"source_file": "PulseCore.InstantiatedSemantics.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "PulseCore.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "PulseCore.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "PulseCore.Semantics",
"short_module": "Sem"
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: (_: a -> PulseCore.InstantiatedSemantics.slprop) ->
q: (_: a -> PulseCore.InstantiatedSemantics.slprop) ->
_: Prims.squash (forall (x: a). PulseCore.InstantiatedSemantics.slprop_equiv (p x) (q x))
-> PulseCore.InstantiatedSemantics.slprop_equiv (exists . p) (exists . q) | Prims.Tot | [
"total"
] | [] | [
"PulseCore.InstantiatedSemantics.slprop",
"Prims.squash",
"Prims.l_Forall",
"PulseCore.InstantiatedSemantics.slprop_equiv",
"PulseCore.InstantiatedSemantics.unsquash",
"PulseCore.InstantiatedSemantics.op_exists_Star",
"Prims.eq2",
"FStar.Tactics.V2.Derived.__cut",
"FStar.FunctionalExtensionality.arrow",
"FStar.FunctionalExtensionality.on_domain",
"PulseCore.Memory.h_exists",
"PulseCore.Memory.slprop",
"Prims.unit",
"FStar.FunctionalExtensionality.extensionality",
"FStar.Classical.Sugar.forall_intro",
"PulseCore.InstantiatedSemantics.slprop_equiv_elim"
] | [] | false | false | false | false | false | let slprop_equiv_exists
(#a: Type)
(p: (a -> slprop))
(q: (a -> slprop))
(_: squash (forall x. slprop_equiv (p x) (q x)))
=
| introduce forall x . p x == q x
with slprop_equiv_elim (p x) (q x);
F.extensionality _ _ p q;
let pf:squash (eq2 #(F.arrow a (fun _ -> slprop)) (F.on_dom a p) (F.on_dom a q)) = () in
let x:squash (op_exists_Star p == op_exists_Star q) =
FStar.Tactics.Effect.synth_by_tactic (fun _ ->
(T.norm [delta_only [`%op_exists_Star; `%F.on_dom]; unascribe];
let bindings = T.cur_vars () in
let bindings = List.Tot.rev bindings in
match bindings with
| hd :: _ ->
(match T.term_as_formula hd.sort with
| T.Comp (T.Eq _) lhs rhs ->
T.grewrite lhs rhs;
T.trefl ();
T.exact (T.binding_to_term hd)
| _ -> T.fail "Unexpected type of hd")
| _ -> T.fail "empty bindings"))
in
unsquash x | false |
PulseCore.InstantiatedSemantics.fst | PulseCore.InstantiatedSemantics.conv | val conv (#a:Type u#a)
(pre1:slprop)
(pre2:slprop)
(post1:a -> slprop)
(post2:a -> slprop)
(pf1:slprop_equiv pre1 pre2)
(pf2:slprop_post_equiv post1 post2)
: Lemma (stt a pre1 post1 == stt a pre2 post2) | val conv (#a:Type u#a)
(pre1:slprop)
(pre2:slprop)
(post1:a -> slprop)
(post2:a -> slprop)
(pf1:slprop_equiv pre1 pre2)
(pf2:slprop_post_equiv post1 post2)
: Lemma (stt a pre1 post1 == stt a pre2 post2) | let conv (#a:Type u#a)
(pre1:slprop)
(pre2:slprop)
(post1:a -> slprop)
(post2:a -> slprop)
(pf1:slprop_equiv pre1 pre2)
(pf2:slprop_post_equiv post1 post2)
: Lemma (stt a pre1 post1 == stt a pre2 post2)
= slprop_equiv_elim pre1 pre2;
introduce forall x. post1 x == post2 x
with slprop_equiv_elim (post1 x) (post2 x);
Sem.conv #state a #pre1 #(F.on_dom _ post1) (F.on_dom _ post2);
() | {
"file_name": "lib/pulse_core/PulseCore.InstantiatedSemantics.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 4,
"end_line": 153,
"start_col": 0,
"start_line": 141
} | module PulseCore.InstantiatedSemantics
module Sem = PulseCore.Semantics
module Mem = PulseCore.Memory
module U = FStar.Universe
module F = FStar.FunctionalExtensionality
open PulseCore.Memory
let laws ()
: squash (
Sem.associative star /\
Sem.commutative star /\
Sem.is_unit emp star
)
= let equiv_eq (x y:slprop)
: Lemma (x `equiv` y <==> x == y)
[SMTPat (x `equiv` y)]
= introduce x `equiv` y ==> x == y
with _h . slprop_extensionality x y
in
let _ : squash (Sem.associative star) =
introduce
forall x y z.
((x `star` y) `star` z) ==
(x `star` (y `star` z))
with star_associative x y z
in
let _ : squash (Sem.commutative star) =
introduce
forall x y.
x `star` y == y `star` x
with star_commutative x y
in
let _ : squash (Sem.is_unit emp star) =
introduce
forall x.
(x `star` emp) == x /\
(emp `star` x) == x
with emp_unit x
in
()
let state0 (e:inames) : Sem.state = {
max_act = U.raise_t u#0 u#100 unit;
s = mem;
is_full_mem = full_mem_pred;
pred = slprop;
emp = emp;
star = star;
interp = interp;
evolves = mem_evolves;
invariant = locks_invariant e;
laws = laws ()
}
let state : Sem.state = state0 Set.empty
let slprop = slprop
let _eq : squash (slprop == state.pred) = ()
let emp = emp
let pure p = pure p
let ( ** ) p q = p `star` q
let ( exists* ) #a p = h_exists (F.on_dom a p)
let prop_squash_idem (p:prop)
: Tot (squash (p == squash p))
= FStar.PropositionalExtensionality.apply p (squash p)
let slprop_equiv p q = Mem.equiv p q
let unsquash (p:squash (slprop_equiv 'p 'q)) : slprop_equiv 'p 'q =
prop_squash_idem (slprop_equiv 'p 'q);
coerce_eq () p
let slprop_equiv_refl p = unsquash ()
let slprop_equiv_elim p q =
introduce (p `slprop_equiv` q) ==> p==q
with _ . Mem.slprop_extensionality p q
let slprop_equiv_unit p = unsquash ()
let slprop_equiv_comm p1 p2 = unsquash ()
let slprop_equiv_assoc p1 p2 p3 = unsquash ()
module T = FStar.Tactics.V2
let slprop_equiv_exists
(#a:Type)
(p q: a -> slprop)
(_:squash (forall x. slprop_equiv (p x) (q x)))
= introduce forall x. p x == q x
with slprop_equiv_elim (p x) (q x);
F.extensionality _ _ p q;
let pf : squash (eq2 #(F.arrow a (fun _ -> slprop))
(F.on_dom a p)
(F.on_dom a q)) = ()
in
let x : squash (op_exists_Star p == op_exists_Star q) = _ by (
T.norm [delta_only [`%op_exists_Star; `%F.on_dom]; unascribe];
let bindings = T.cur_vars() in
let bindings = List.Tot.rev bindings in
match bindings with
| hd::_ -> (
match T.term_as_formula hd.sort with
| T.Comp (T.Eq _) lhs rhs ->
T.grewrite lhs rhs;
T.trefl();
T.exact (T.binding_to_term hd)
| _ -> T.fail "Unexpected type of hd"
)
| _ ->
T.fail "empty bindings"
) in
unsquash x
(* The type of general-purpose computations *)
let lower (t:Type u#a) : Type0 = unit -> Dv t
let stt (a:Type u#a)
(pre:slprop)
(post:a -> slprop)
: Type0
= lower (Sem.m u#2 u#100 u#a #state a pre (F.on_dom a post))
let return (#a:Type u#a) (x:a) (p:a -> slprop)
: stt a (p x) p
= fun _ -> Sem.ret x (F.on_dom a p)
let bind
(#a:Type u#a) (#b:Type u#b)
(#pre1:slprop) (#post1:a -> slprop) (#post2:b -> slprop)
(e1:stt a pre1 post1)
(e2:(x:a -> stt b (post1 x) post2))
: stt b pre1 post2
= fun _ -> Sem.mbind (e1()) (fun x -> e2 x ())
let frame
(#a:Type u#a)
(#pre:slprop) (#post:a -> slprop)
(frame:slprop)
(e:stt a pre post)
: stt a (pre `star` frame) (fun x -> post x `star` frame)
= fun _ -> Sem.frame frame (e()) | {
"checked_file": "/",
"dependencies": [
"PulseCore.Semantics.fst.checked",
"PulseCore.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Universe.fsti.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Set.fsti.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked"
],
"interface_file": true,
"source_file": "PulseCore.InstantiatedSemantics.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "PulseCore.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.Universe",
"short_module": "U"
},
{
"abbrev": true,
"full_module": "PulseCore.Memory",
"short_module": "Mem"
},
{
"abbrev": true,
"full_module": "PulseCore.Semantics",
"short_module": "Sem"
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "PulseCore",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
pre1: PulseCore.InstantiatedSemantics.slprop ->
pre2: PulseCore.InstantiatedSemantics.slprop ->
post1: (_: a -> PulseCore.InstantiatedSemantics.slprop) ->
post2: (_: a -> PulseCore.InstantiatedSemantics.slprop) ->
pf1: PulseCore.InstantiatedSemantics.slprop_equiv pre1 pre2 ->
pf2: PulseCore.InstantiatedSemantics.slprop_post_equiv post1 post2
-> FStar.Pervasives.Lemma
(ensures
PulseCore.InstantiatedSemantics.stt a pre1 post1 ==
PulseCore.InstantiatedSemantics.stt a pre2 post2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"PulseCore.InstantiatedSemantics.slprop",
"PulseCore.InstantiatedSemantics.slprop_equiv",
"PulseCore.InstantiatedSemantics.slprop_post_equiv",
"Prims.unit",
"PulseCore.Semantics.conv",
"PulseCore.InstantiatedSemantics.state",
"FStar.FunctionalExtensionality.on_dom",
"PulseCore.Semantics.__proj__Mkstate__item__pred",
"FStar.Classical.Sugar.forall_intro",
"Prims.eq2",
"PulseCore.InstantiatedSemantics.slprop_equiv_elim",
"Prims.squash",
"Prims.l_True",
"PulseCore.InstantiatedSemantics.stt",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let conv
(#a: Type u#a)
(pre1 pre2: slprop)
(post1 post2: (a -> slprop))
(pf1: slprop_equiv pre1 pre2)
(pf2: slprop_post_equiv post1 post2)
: Lemma (stt a pre1 post1 == stt a pre2 post2) =
| slprop_equiv_elim pre1 pre2;
introduce forall x . post1 x == post2 x
with slprop_equiv_elim (post1 x) (post2 x);
Sem.conv #state a #pre1 #(F.on_dom _ post1) (F.on_dom _ post2);
() | false |
Hacl.Spec.Bignum.Lib.fst | Hacl.Spec.Bignum.Lib.bn_set_ith_bit_lemma | val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma
(requires bn_v b < pow2 i)
(ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) | val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma
(requires bn_v b < pow2 i)
(ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) | let bn_set_ith_bit_lemma #t #len input ind =
let pbits = bits t in
let i = ind / pbits in
let j = ind % pbits in
bn_lt_pow2_index_lemma #t #len input ind;
assert (v input.[i] < pow2 j);
let b = uint #t 1 <<. size j in
let inp = input.[i] <- input.[i] |. b in
FStar.Math.Lemmas.pow2_lt_compat pbits j;
FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits);
assert (v b == pow2 j);
logor_disjoint (input.[i]) b j;
assert (v inp.[i] == v input.[i] + v b);
calc (==) {
bn_v inp;
(==) { bn_eval_split_i #t #len inp (i + 1);
bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1) }
bn_v (slice inp 0 (i + 1));
(==) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i }
bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1));
(==) { bn_eval1 (slice inp i (i + 1)) }
bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[i];
(==) { bn_eval_extensionality_j input inp i }
bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[i];
(==) { }
bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[i] + v b);
(==) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[i]) (v b) }
bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 (i * pbits) * v b;
(==) { Math.Lemmas.pow2_plus (i * pbits) j; Math.Lemmas.euclidean_division_definition ind pbits }
bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[i] + pow2 ind;
(==) { }
bn_v input + pow2 ind;
} | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Lib.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 176,
"start_col": 0,
"start_line": 142
} | module Hacl.Spec.Bignum.Lib
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
module BSeq = Lib.ByteSequence
module Loops = Lib.LoopCombinators
module BB = Hacl.Spec.Bignum.Base
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
///
/// Get and set i-th bit of a bignum
///
val limb_get_ith_bit: #t:limb_t -> a:limb t -> i:nat{i < bits t} -> limb t
let limb_get_ith_bit #t a i = (a >>. size i) &. uint #t 1
val limb_get_ith_bit_lemma: #t:limb_t -> a:limb t -> i:nat{i < bits t} ->
Lemma (v (limb_get_ith_bit a i) == v a / pow2 i % 2)
let limb_get_ith_bit_lemma #t a i =
let tmp1 = a >>. size i in
let tmp2 = tmp1 &. uint #t 1 in
mod_mask_lemma tmp1 1ul;
assert (v (mod_mask #t #SEC 1ul) == v (uint #t #SEC 1));
assert (v tmp2 == v a / pow2 i % 2)
val bn_get_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> limb t
let bn_get_ith_bit #t #len input ind =
let i = ind / bits t in
let j = ind % bits t in
limb_get_ith_bit input.[i] j
val bn_get_ith_bit_aux_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} ->
Lemma (let i = ind / bits t in let j = ind % bits t in
v (b.[i] >>. size j) == (bn_v b / pow2 ind) % pow2 (bits t - j))
let bn_get_ith_bit_aux_lemma #t #len b ind =
let pbits = bits t in
let i = ind / pbits in
let j = ind % pbits in
let res = b.[i] >>. size j in
calc (==) {
v b.[i] / pow2 j;
(==) { bn_eval_index b i }
(bn_v b / pow2 (pbits * i) % pow2 pbits) / pow2 j;
(==) { Math.Lemmas.pow2_modulo_division_lemma_1 (bn_v b / pow2 (pbits * i)) j pbits }
(bn_v b / pow2 (pbits * i) / pow2 j) % pow2 (pbits - j);
(==) { Math.Lemmas.division_multiplication_lemma (bn_v b) (pow2 (pbits * i)) (pow2 j) }
(bn_v b / (pow2 (pbits * i) * pow2 j)) % pow2 (pbits - j);
(==) { Math.Lemmas.pow2_plus (pbits * i) j }
(bn_v b / pow2 (pbits * i + j)) % pow2 (pbits - j);
(==) { Math.Lemmas.euclidean_div_axiom ind pbits }
(bn_v b / pow2 ind) % pow2 (pbits - j);
};
assert (v res == (bn_v b / pow2 ind) % pow2 (pbits - j))
val bn_get_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} ->
Lemma (v (bn_get_ith_bit b i) == (bn_v b / pow2 i % 2))
let bn_get_ith_bit_lemma #t #len b ind =
let pbits = bits t in
let i = ind / pbits in
let j = ind % pbits in
let res = limb_get_ith_bit b.[i] j in
limb_get_ith_bit_lemma b.[i] j;
calc (==) {
v b.[i] / pow2 j % 2;
(==) { bn_get_ith_bit_aux_lemma b ind }
(bn_v b / pow2 ind) % pow2 (pbits - j) % 2;
(==) { assert_norm (pow2 1 = 2);
Math.Lemmas.pow2_modulo_modulo_lemma_1 (bn_v b / pow2 ind) 1 (pbits - j) }
(bn_v b / pow2 ind) % 2;
};
assert (v res == bn_v b / pow2 ind % 2)
val bn_set_ith_bit: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> lbignum t len
let bn_set_ith_bit #t #len input ind =
let i = ind / bits t in
let j = ind % bits t in
let inp = input.[i] <- input.[i] |. (uint #t 1 <<. size j) in
inp
val bn_set_ith_bit_lemma_aux: a:nat -> b:nat -> c:nat -> d:nat -> Lemma
(requires a + b * pow2 c < pow2 (c + d) /\ a < pow2 c)
(ensures b < pow2 d)
let bn_set_ith_bit_lemma_aux a b c d =
Math.Lemmas.lemma_div_lt_nat (a + b * pow2 c) (c + d) c;
assert ((a + b * pow2 c) / pow2 c < pow2 d);
Math.Lemmas.lemma_div_plus a b (pow2 c);
assert (a / pow2 c + b < pow2 d);
Math.Lemmas.small_division_lemma_1 a (pow2 c)
val bn_lt_pow2_index_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> ind:size_nat{ind / bits t < len} -> Lemma
(requires bn_v b < pow2 ind)
(ensures (let i = ind / bits t in v b.[i] < pow2 (ind % bits t) /\
bn_v b == bn_v (slice b 0 i) + pow2 (i * bits t) * v b.[i] /\
bn_v (slice b (i + 1) len) = 0))
let bn_lt_pow2_index_lemma #t #len b ind =
let pbits = bits t in
let i = ind / pbits in
let j = ind % pbits in
Math.Lemmas.euclidean_division_definition ind (pbits);
assert (bn_v b < pow2 (i * pbits + j));
Math.Lemmas.pow2_lt_compat (i * pbits + pbits) (i * pbits + j);
assert (bn_v b < pow2 (i * pbits + pbits));
bn_eval_split_i #t #len b (i + 1);
bn_eval_bound (slice b 0 (i + 1)) (i + 1);
bn_set_ith_bit_lemma_aux (bn_v (slice b 0 (i + 1))) (bn_v (slice b (i + 1) len)) (pbits * (i + 1)) 0;
assert (bn_v b == bn_v (slice b 0 (i + 1)));
bn_eval_split_i #t #(i + 1) (slice b 0 (i + 1)) i;
bn_eval1 (slice b i (i + 1));
assert (bn_v b == bn_v (slice b 0 i) + pow2 (i * pbits) * v b.[i]);
bn_eval_bound #t #i (slice b 0 i) i;
bn_set_ith_bit_lemma_aux (bn_v (slice b 0 i)) (v b.[i]) (i * pbits) j;
assert (v b.[i] < pow2 j)
val bn_set_ith_bit_lemma: #t:limb_t -> #len:size_nat -> b:lbignum t len -> i:size_nat{i / bits t < len} -> Lemma
(requires bn_v b < pow2 i)
(ensures bn_v (bn_set_ith_bit b i) == bn_v b + pow2 i) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.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": false,
"source_file": "Hacl.Spec.Bignum.Lib.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": "BB"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"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.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 |
b: Hacl.Spec.Bignum.Definitions.lbignum t len ->
i: Lib.IntTypes.size_nat{i / Lib.IntTypes.bits t < len}
-> FStar.Pervasives.Lemma (requires Hacl.Spec.Bignum.Definitions.bn_v b < Prims.pow2 i)
(ensures
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.Lib.bn_set_ith_bit b i) ==
Hacl.Spec.Bignum.Definitions.bn_v b + Prims.pow2 i) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Division",
"Lib.IntTypes.bits",
"FStar.Calc.calc_finish",
"Prims.nat",
"Prims.eq2",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Prims.op_Addition",
"Prims.pow2",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Prims.op_Subtraction",
"Lib.Sequence.slice",
"Hacl.Spec.Bignum.Definitions.limb",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Lib.Sequence.op_String_Access",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Hacl.Spec.Bignum.Definitions.bn_eval_extensionality_j",
"Hacl.Spec.Bignum.Definitions.bn_eval_split_i",
"Prims.squash",
"Hacl.Spec.Bignum.Definitions.bn_eval1",
"FStar.Math.Lemmas.distributivity_add_right",
"FStar.Math.Lemmas.euclidean_division_definition",
"FStar.Math.Lemmas.pow2_plus",
"Prims._assert",
"Prims.int",
"Lib.IntTypes.logor_disjoint",
"Prims.l_or",
"Lib.IntTypes.range",
"Prims.op_GreaterThan",
"FStar.Math.Lemmas.modulo_lemma",
"FStar.Math.Lemmas.pow2_lt_compat",
"Lib.Sequence.lseq",
"Prims.l_and",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.upd",
"Lib.IntTypes.logor",
"Lib.Sequence.index",
"Prims.l_Forall",
"Prims.op_LessThanOrEqual",
"Prims.l_imp",
"Prims.op_disEquality",
"FStar.Seq.Base.index",
"Lib.Sequence.op_String_Assignment",
"Lib.IntTypes.op_Bar_Dot",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Less_Less_Dot",
"Lib.IntTypes.uint",
"Lib.IntTypes.size",
"Hacl.Spec.Bignum.Lib.bn_lt_pow2_index_lemma",
"Prims.op_Modulus"
] | [] | false | false | true | false | false | let bn_set_ith_bit_lemma #t #len input ind =
| let pbits = bits t in
let i = ind / pbits in
let j = ind % pbits in
bn_lt_pow2_index_lemma #t #len input ind;
assert (v input.[ i ] < pow2 j);
let b = uint #t 1 <<. size j in
let inp = input.[ i ] <- input.[ i ] |. b in
FStar.Math.Lemmas.pow2_lt_compat pbits j;
FStar.Math.Lemmas.modulo_lemma (pow2 j) (pow2 pbits);
assert (v b == pow2 j);
logor_disjoint (input.[ i ]) b j;
assert (v inp.[ i ] == v input.[ i ] + v b);
calc ( == ) {
bn_v inp;
( == ) { (bn_eval_split_i #t #len inp (i + 1);
bn_eval_extensionality_j (slice inp (i + 1) len) (slice input (i + 1) len) (len - i - 1)) }
bn_v (slice inp 0 (i + 1));
( == ) { bn_eval_split_i #t #(i + 1) (slice inp 0 (i + 1)) i }
bn_v (slice inp 0 i) + pow2 (i * pbits) * bn_v (slice inp i (i + 1));
( == ) { bn_eval1 (slice inp i (i + 1)) }
bn_v (slice inp 0 i) + pow2 (i * pbits) * v inp.[ i ];
( == ) { bn_eval_extensionality_j input inp i }
bn_v (slice input 0 i) + pow2 (i * pbits) * v inp.[ i ];
( == ) { () }
bn_v (slice input 0 i) + pow2 (i * pbits) * (v input.[ i ] + v b);
( == ) { Math.Lemmas.distributivity_add_right (pow2 (i * pbits)) (v input.[ i ]) (v b) }
bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[ i ] + pow2 (i * pbits) * v b;
( == ) { (Math.Lemmas.pow2_plus (i * pbits) j;
Math.Lemmas.euclidean_division_definition ind pbits) }
bn_v (slice input 0 i) + pow2 (i * pbits) * v input.[ i ] + pow2 ind;
( == ) { () }
bn_v input + pow2 ind;
} | false |
CDDL.Spec.fsti | CDDL.Spec.typ | val typ : Type0 | let typ = bounded_typ_gen None | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 30,
"end_line": 38,
"start_col": 0,
"start_line": 38
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.bounded_typ_gen",
"FStar.Pervasives.Native.None",
"CBOR.Spec.Type.raw_data_item"
] | [] | false | false | false | true | true | let typ =
| bounded_typ_gen None | false |
|
CDDL.Spec.fsti | CDDL.Spec.bounded_typ_gen | val bounded_typ_gen : e: FStar.Pervasives.Native.option CBOR.Spec.Type.raw_data_item -> Type0 | let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 112,
"end_line": 35,
"start_col": 0,
"start_line": 35
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | e: FStar.Pervasives.Native.option CBOR.Spec.Type.raw_data_item -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.opt_precedes",
"Prims.bool"
] | [] | false | false | false | true | true | let bounded_typ_gen (e: option Cbor.raw_data_item) =
| e': Cbor.raw_data_item{opt_precedes e' e} -> GTot bool | false |
|
CDDL.Spec.fsti | CDDL.Spec.bounded_typ | val bounded_typ : e: CBOR.Spec.Type.raw_data_item -> Type0 | let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 66,
"end_line": 41,
"start_col": 0,
"start_line": 41
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | e: CBOR.Spec.Type.raw_data_item -> Type0 | Prims.Tot | [
"total"
] | [] | [
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.bounded_typ_gen",
"FStar.Pervasives.Native.Some"
] | [] | false | false | false | true | true | let bounded_typ (e: Cbor.raw_data_item) =
| bounded_typ_gen (Some e) | false |
|
CDDL.Spec.fsti | CDDL.Spec.t_choice | val t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b | val t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b | let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 117,
"end_line": 56,
"start_col": 0,
"start_line": 56
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | t1: CDDL.Spec.bounded_typ_gen b -> t2: CDDL.Spec.bounded_typ_gen b -> CDDL.Spec.bounded_typ_gen b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.bounded_typ_gen",
"CDDL.Spec.opt_precedes",
"Prims.op_BarBar",
"Prims.bool"
] | [] | false | false | false | false | false | let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b =
| (fun x -> t1 x || t2 x) | false |
CDDL.Spec.fsti | CDDL.Spec.t_always_false | val t_always_false:typ | val t_always_false:typ | let t_always_false : typ = (fun _ -> false) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 43,
"end_line": 74,
"start_col": 0,
"start_line": 74
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.opt_precedes",
"FStar.Pervasives.Native.None",
"Prims.bool"
] | [] | false | false | false | true | false | let t_always_false:typ =
| (fun _ -> false) | false |
CDDL.Spec.fsti | CDDL.Spec.t_literal | val t_literal (i: Cbor.raw_data_item) : typ | val t_literal (i: Cbor.raw_data_item) : typ | let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 71,
"end_line": 77,
"start_col": 0,
"start_line": 76
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | i: CBOR.Spec.Type.raw_data_item -> CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.opt_precedes",
"FStar.Pervasives.Native.None",
"FStar.StrongExcludedMiddle.strong_excluded_middle",
"Prims.eq2",
"Prims.bool",
"CDDL.Spec.typ"
] | [] | false | false | false | true | false | let t_literal (i: Cbor.raw_data_item) : typ =
| (fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) | false |
CDDL.Spec.fsti | CDDL.Spec.any | val any:typ | val any:typ | let any : typ = (fun _ -> true) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 31,
"end_line": 80,
"start_col": 0,
"start_line": 80
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.opt_precedes",
"FStar.Pervasives.Native.None",
"Prims.bool"
] | [] | false | false | false | true | false | let any:typ =
| (fun _ -> true) | false |
CDDL.Spec.fsti | CDDL.Spec.t_int | val t_int:typ | val t_int:typ | let t_int : typ = uint `t_choice` nint | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 38,
"end_line": 84,
"start_col": 0,
"start_line": 84
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.t_choice",
"FStar.Pervasives.Native.None",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.uint",
"CDDL.Spec.nint"
] | [] | false | false | false | true | false | let t_int:typ =
| uint `t_choice` nint | false |
CDDL.Spec.fsti | CDDL.Spec.bytes | val bytes : CDDL.Spec.typ | let bytes = bstr | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 16,
"end_line": 87,
"start_col": 0,
"start_line": 87
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.bstr"
] | [] | false | false | false | true | false | let bytes =
| bstr | false |
|
CDDL.Spec.fsti | CDDL.Spec.opt_precedes | val opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop | val opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop | let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2 | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 23,
"end_line": 32,
"start_col": 0,
"start_line": 25
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | x1: t1 -> x2: FStar.Pervasives.Native.option t2 -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"Prims.l_True",
"Prims.precedes",
"Prims.prop"
] | [] | false | false | false | true | true | let opt_precedes (#t1 #t2: Type) (x1: t1) (x2: option t2) : Tot prop =
| match x2 with
| None -> True
| Some x2 -> x1 << x2 | false |
CDDL.Spec.fsti | CDDL.Spec.text | val text : CDDL.Spec.typ | let text = tstr | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 15,
"end_line": 89,
"start_col": 0,
"start_line": 89
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.tstr"
] | [] | false | false | false | true | false | let text =
| tstr | false |
|
CDDL.Spec.fsti | CDDL.Spec.t_false | val t_false:typ | val t_false:typ | let t_false : typ = t_simple_value_literal simple_value_false | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 61,
"end_line": 103,
"start_col": 0,
"start_line": 103
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.t_simple_value_literal",
"CDDL.Spec.simple_value_false"
] | [] | false | false | false | true | false | let t_false:typ =
| t_simple_value_literal simple_value_false | false |
CDDL.Spec.fsti | CDDL.Spec.coerce_to_bounded_typ | val coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) | val coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) | let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 47,
"start_col": 0,
"start_line": 43
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Pervasives.Native.option CBOR.Spec.Type.raw_data_item -> t: CDDL.Spec.typ
-> CDDL.Spec.bounded_typ_gen b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.typ",
"CDDL.Spec.bounded_typ_gen"
] | [] | false | false | false | false | false | let coerce_to_bounded_typ (b: option Cbor.raw_data_item) (t: typ) : Tot (bounded_typ_gen b) =
| t | false |
CDDL.Spec.fsti | CDDL.Spec.t_true | val t_true:typ | val t_true:typ | let t_true : typ = t_simple_value_literal simple_value_true | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 59,
"end_line": 104,
"start_col": 0,
"start_line": 104
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.t_simple_value_literal",
"CDDL.Spec.simple_value_true"
] | [] | false | false | false | true | false | let t_true:typ =
| t_simple_value_literal simple_value_true | false |
CDDL.Spec.fsti | CDDL.Spec.t_nil | val t_nil:typ | val t_nil:typ | let t_nil : typ = t_simple_value_literal simple_value_nil | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 57,
"end_line": 106,
"start_col": 0,
"start_line": 106
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.t_simple_value_literal",
"CDDL.Spec.simple_value_nil"
] | [] | false | false | false | true | false | let t_nil:typ =
| t_simple_value_literal simple_value_nil | false |
CDDL.Spec.fsti | CDDL.Spec.t_bool | val t_bool:typ | val t_bool:typ | let t_bool : typ = t_choice t_false t_true | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 42,
"end_line": 105,
"start_col": 0,
"start_line": 105
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.t_choice",
"FStar.Pervasives.Native.None",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.t_false",
"CDDL.Spec.t_true"
] | [] | false | false | false | true | false | let t_bool:typ =
| t_choice t_false t_true | false |
CDDL.Spec.fsti | CDDL.Spec.t_simple_value_literal | val t_simple_value_literal (s: Cbor.simple_value) : typ | val t_simple_value_literal (s: Cbor.simple_value) : typ | let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 27,
"end_line": 101,
"start_col": 0,
"start_line": 100
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: CBOR.Spec.Type.simple_value -> CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CBOR.Spec.Type.simple_value",
"CDDL.Spec.t_literal",
"CBOR.Spec.Type.Simple",
"CDDL.Spec.typ"
] | [] | false | false | false | true | false | let t_simple_value_literal (s: Cbor.simple_value) : typ =
| t_literal (Cbor.Simple s) | false |
CDDL.Spec.fsti | CDDL.Spec.t_null | val t_null:typ | val t_null:typ | let t_null : typ = t_nil | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 24,
"end_line": 107,
"start_col": 0,
"start_line": 107
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.t_nil"
] | [] | false | false | false | true | false | let t_null:typ =
| t_nil | false |
CDDL.Spec.fsti | CDDL.Spec.t_undefined | val t_undefined:typ | val t_undefined:typ | let t_undefined : typ = t_simple_value_literal simple_value_undefined | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 69,
"end_line": 108,
"start_col": 0,
"start_line": 108
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.t_simple_value_literal",
"CDDL.Spec.simple_value_undefined"
] | [] | false | false | false | true | false | let t_undefined:typ =
| t_simple_value_literal simple_value_undefined | false |
CDDL.Spec.fsti | CDDL.Spec.typ_equiv | val typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop | val typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop | let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 25,
"end_line": 54,
"start_col": 0,
"start_line": 50
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | t1: CDDL.Spec.bounded_typ_gen b -> t2: CDDL.Spec.bounded_typ_gen b -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.bounded_typ_gen",
"Prims.l_Forall",
"Prims.l_and",
"CDDL.Spec.opt_precedes",
"Prims.eq2",
"Prims.bool",
"Prims.prop"
] | [] | false | false | false | false | true | let typ_equiv (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : Tot prop =
| forall x. t1 x == t2 x | false |
CDDL.Spec.fsti | CDDL.Spec.array_group1_concat | val array_group1_concat (a1 a2: array_group1) : array_group1 | val array_group1_concat (a1 a2: array_group1) : array_group1 | let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 81,
"end_line": 121,
"start_col": 0,
"start_line": 121
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | a1: CDDL.Spec.array_group1 -> a2: CDDL.Spec.array_group1 -> CDDL.Spec.array_group1 | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.array_group1",
"Prims.list",
"CBOR.Spec.Type.raw_data_item",
"Prims.bool"
] | [] | false | false | false | true | false | let array_group1_concat (a1 a2: array_group1) : array_group1 =
| fun k -> a1 (a2 k) | false |
Steel.ST.GenElim1.fst | Steel.ST.GenElim1.compute_gen_elim_nondep_correct6 | val 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]) | val 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]) | 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 | {
"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": 577,
"start_col": 0,
"start_line": 561
} | 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 | {
"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 ->
t2: Type ->
t3: Type ->
t4: Type ->
t5: Type ->
t6: Type
-> Steel.ST.GenElim1.compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6] | 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",
"FStar.Pervasives.Native.tuple6",
"FStar.Pervasives.Native.Mktuple6",
"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_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 | false |
CDDL.Spec.fsti | CDDL.Spec.array_group1 | val array_group1 : Type0 | let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 99,
"end_line": 119,
"start_col": 0,
"start_line": 119
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"CBOR.Spec.Type.raw_data_item",
"Prims.bool"
] | [] | false | false | false | true | true | let array_group1 =
| ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool) | false |
|
CDDL.Spec.fsti | CDDL.Spec.nint | val nint:typ | val nint:typ | let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 95,
"end_line": 83,
"start_col": 0,
"start_line": 83
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.opt_precedes",
"FStar.Pervasives.Native.None",
"Prims.op_AmpAmp",
"CBOR.Spec.Type.uu___is_Int64",
"Prims.op_Equality",
"CBOR.Spec.Constants.major_type_t",
"CBOR.Spec.Type.__proj__Int64__item__typ",
"CBOR.Spec.Constants.cbor_major_type_neg_int64",
"Prims.bool"
] | [] | false | false | false | true | false | let nint:typ =
| (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64) | false |
CDDL.Spec.fsti | CDDL.Spec.array_group1_empty | val array_group1_empty:array_group1 | val array_group1_empty:array_group1 | let array_group1_empty : array_group1 = fun k -> k | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 50,
"end_line": 120,
"start_col": 0,
"start_line": 120
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.array_group1 | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"CBOR.Spec.Type.raw_data_item",
"Prims.bool"
] | [] | false | false | false | true | false | let array_group1_empty:array_group1 =
| fun k -> k | false |
CDDL.Spec.fsti | CDDL.Spec.array_group1_zero_or_more | val array_group1_zero_or_more: array_group1 -> array_group1 | val array_group1_zero_or_more: array_group1 -> array_group1 | let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 89,
"end_line": 128,
"start_col": 0,
"start_line": 128
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | _: CDDL.Spec.array_group1 -> CDDL.Spec.array_group1 | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.array_group1_zero_or_more'"
] | [] | false | false | false | true | false | let array_group1_zero_or_more: array_group1 -> array_group1 =
| array_group1_zero_or_more' | false |
CDDL.Spec.fsti | CDDL.Spec.array_group1_choice | val array_group1_choice (a1 a2: array_group1) : array_group1 | val array_group1_choice (a1 a2: array_group1) : array_group1 | let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 90,
"end_line": 122,
"start_col": 0,
"start_line": 122
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | a1: CDDL.Spec.array_group1 -> a2: CDDL.Spec.array_group1 -> CDDL.Spec.array_group1 | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.array_group1",
"Prims.list",
"CBOR.Spec.Type.raw_data_item",
"Prims.bool",
"Prims.op_BarBar"
] | [] | false | false | false | true | false | let array_group1_choice (a1 a2: array_group1) : array_group1 =
| fun k l -> a1 k l || a2 k l | false |
CDDL.Spec.fsti | CDDL.Spec.t_uint_literal | val t_uint_literal (v: U64.t) : typ | val t_uint_literal (v: U64.t) : typ | let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 54,
"end_line": 111,
"start_col": 0,
"start_line": 110
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: FStar.UInt64.t -> CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"CDDL.Spec.t_literal",
"CBOR.Spec.Type.Int64",
"CBOR.Spec.Constants.cbor_major_type_uint64",
"CDDL.Spec.typ"
] | [] | false | false | false | true | false | let t_uint_literal (v: U64.t) : typ =
| t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v) | false |
CDDL.Spec.fsti | CDDL.Spec.uint | val uint:typ | val uint:typ | let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 92,
"end_line": 82,
"start_col": 0,
"start_line": 82
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.opt_precedes",
"FStar.Pervasives.Native.None",
"Prims.op_AmpAmp",
"CBOR.Spec.Type.uu___is_Int64",
"Prims.op_Equality",
"CBOR.Spec.Constants.major_type_t",
"CBOR.Spec.Type.__proj__Int64__item__typ",
"CBOR.Spec.Constants.cbor_major_type_uint64",
"Prims.bool"
] | [] | false | false | false | true | false | let uint:typ =
| (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64) | false |
CDDL.Spec.fsti | CDDL.Spec.array_group2 | val array_group2 : Type0 | let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 120,
"end_line": 142,
"start_col": 0,
"start_line": 142
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.nat_up_to",
"FStar.Seq.Base.length",
"Prims.list"
] | [] | false | false | false | true | true | let array_group2 =
| (l: Seq.seq Cbor.raw_data_item -> i: nat_up_to (Seq.length l) -> list (nat_up_to (Seq.length l))) | false |
|
CDDL.Spec.fsti | CDDL.Spec.bstr | val bstr:typ | val bstr:typ | let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 99,
"end_line": 86,
"start_col": 0,
"start_line": 86
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.opt_precedes",
"FStar.Pervasives.Native.None",
"Prims.op_AmpAmp",
"CBOR.Spec.Type.uu___is_String",
"Prims.op_Equality",
"CBOR.Spec.Constants.major_type_t",
"CBOR.Spec.Type.__proj__String__item__typ",
"CBOR.Spec.Constants.cbor_major_type_byte_string",
"Prims.bool"
] | [] | false | false | false | true | false | let bstr:typ =
| (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) | false |
CDDL.Spec.fsti | CDDL.Spec.array_group2_empty | val array_group2_empty:array_group2 | val array_group2_empty:array_group2 | let array_group2_empty : array_group2 = (fun _ i -> [i]) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 56,
"end_line": 144,
"start_col": 0,
"start_line": 144
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.array_group2 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.nat_up_to",
"FStar.Seq.Base.length",
"Prims.Cons",
"Prims.Nil",
"Prims.list"
] | [] | false | false | false | true | false | let array_group2_empty:array_group2 =
| (fun _ i -> [i]) | false |
CDDL.Spec.fsti | CDDL.Spec.array_group2_choice | val array_group2_choice (a1 a2: array_group2) : array_group2 | val array_group2_choice (a1 a2: array_group2) : array_group2 | let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 44,
"end_line": 154,
"start_col": 0,
"start_line": 153
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | a1: CDDL.Spec.array_group2 -> a2: CDDL.Spec.array_group2 -> CDDL.Spec.array_group2 | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.array_group2",
"FStar.Seq.Base.seq",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.nat_up_to",
"FStar.Seq.Base.length",
"FStar.List.Tot.Base.append",
"Prims.list"
] | [] | false | false | false | true | false | let array_group2_choice (a1 a2: array_group2) : array_group2 =
| fun l i -> (a1 l i) `List.Tot.append` (a2 l i) | false |
CDDL.Spec.fsti | CDDL.Spec.array_group2_concat | val array_group2_concat (a1 a2: array_group2) : array_group2 | val array_group2_concat (a1 a2: array_group2) : array_group2 | let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 150,
"start_col": 0,
"start_line": 146
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i]) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | a1: CDDL.Spec.array_group2 -> a2: CDDL.Spec.array_group2 -> CDDL.Spec.array_group2 | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.array_group2",
"FStar.Seq.Base.seq",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.nat_up_to",
"FStar.Seq.Base.length",
"FStar.List.Tot.Base.concatMap",
"Prims.list"
] | [] | false | false | false | true | false | let array_group2_concat (a1 a2: array_group2) : array_group2 =
| (fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1) | false |
CDDL.Spec.fsti | CDDL.Spec.list_is_suffix_of | val list_is_suffix_of (#t: Type) (small large: list t) : Tot prop | val list_is_suffix_of (#t: Type) (small large: list t) : Tot prop | let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 57,
"end_line": 189,
"start_col": 0,
"start_line": 185
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | small: Prims.list t -> large: Prims.list t -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Prims.l_Exists",
"Prims.eq2",
"FStar.List.Tot.Base.append",
"Prims.prop"
] | [] | false | false | false | true | true | let list_is_suffix_of (#t: Type) (small large: list t) : Tot prop =
| exists prefix. large == prefix `List.Tot.append` small | false |
CDDL.Spec.fsti | CDDL.Spec.simple_value_nil | val simple_value_nil:Cbor.simple_value | val simple_value_nil:Cbor.simple_value | let simple_value_nil : Cbor.simple_value = 22uy | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 47,
"end_line": 96,
"start_col": 0,
"start_line": 96
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CBOR.Spec.Type.simple_value | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.__uint_to_t"
] | [] | false | false | false | true | false | let simple_value_nil:Cbor.simple_value =
| 22uy | false |
CDDL.Spec.fsti | CDDL.Spec.simple_value_false | val simple_value_false:Cbor.simple_value | val simple_value_false:Cbor.simple_value | let simple_value_false : Cbor.simple_value = 20uy | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 49,
"end_line": 92,
"start_col": 0,
"start_line": 92
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CBOR.Spec.Type.simple_value | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.__uint_to_t"
] | [] | false | false | false | true | false | let simple_value_false:Cbor.simple_value =
| 20uy | false |
CDDL.Spec.fsti | CDDL.Spec.tstr | val tstr:typ | val tstr:typ | let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 99,
"end_line": 88,
"start_col": 0,
"start_line": 88
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.opt_precedes",
"FStar.Pervasives.Native.None",
"Prims.op_AmpAmp",
"CBOR.Spec.Type.uu___is_String",
"Prims.op_Equality",
"CBOR.Spec.Constants.major_type_t",
"CBOR.Spec.Type.__proj__String__item__typ",
"CBOR.Spec.Constants.cbor_major_type_text_string",
"Prims.bool"
] | [] | false | false | false | true | false | let tstr:typ =
| (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string) | false |
CDDL.Spec.fsti | CDDL.Spec.array_group3_one_or_more | val array_group3_one_or_more (#b: _) (a: array_group3 b) : array_group3 b | val array_group3_one_or_more (#b: _) (a: array_group3 b) : array_group3 b | let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 53,
"end_line": 284,
"start_col": 0,
"start_line": 283
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: CDDL.Spec.array_group3 b -> CDDL.Spec.array_group3 b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.array_group3",
"CDDL.Spec.array_group3_concat",
"CDDL.Spec.array_group3_zero_or_more"
] | [] | false | false | false | false | false | let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
| a `array_group3_concat` (array_group3_zero_or_more a) | false |
CDDL.Spec.fsti | CDDL.Spec.array_group3_zero_or_more | val array_group3_zero_or_more: #b: _ -> array_group3 b -> array_group3 b | val array_group3_zero_or_more: #b: _ -> array_group3 b -> array_group3 b | let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more' | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 96,
"end_line": 281,
"start_col": 0,
"start_line": 281
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | _: CDDL.Spec.array_group3 b -> CDDL.Spec.array_group3 b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.array_group3_zero_or_more'",
"CDDL.Spec.array_group3"
] | [] | false | false | false | false | false | let array_group3_zero_or_more #b : array_group3 b -> array_group3 b =
| array_group3_zero_or_more' | false |
CDDL.Spec.fsti | CDDL.Spec.simple_value_true | val simple_value_true:Cbor.simple_value | val simple_value_true:Cbor.simple_value | let simple_value_true : Cbor.simple_value = 21uy | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 48,
"end_line": 94,
"start_col": 0,
"start_line": 94
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CBOR.Spec.Type.simple_value | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.__uint_to_t"
] | [] | false | false | false | true | false | let simple_value_true:Cbor.simple_value =
| 21uy | false |
CDDL.Spec.fsti | CDDL.Spec.array_group3_zero_or_one | val array_group3_zero_or_one (#b: _) (a: array_group3 b) : Tot (array_group3 b) | val array_group3_zero_or_one (#b: _) (a: array_group3 b) : Tot (array_group3 b) | let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 44,
"end_line": 287,
"start_col": 0,
"start_line": 286
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: CDDL.Spec.array_group3 b -> CDDL.Spec.array_group3 b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.array_group3",
"CDDL.Spec.array_group3_choice",
"CDDL.Spec.array_group3_empty"
] | [] | false | false | false | false | false | let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
| a `array_group3_choice` array_group3_empty | false |
CDDL.Spec.fsti | CDDL.Spec.match_array_group3 | val match_array_group3
(#b: option Cbor.raw_data_item)
(a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool | val match_array_group3
(#b: option Cbor.raw_data_item)
(a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool | let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 14,
"end_line": 307,
"start_col": 0,
"start_line": 302
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: CDDL.Spec.array_group3 b ->
l: Prims.list CBOR.Spec.Type.raw_data_item {CDDL.Spec.opt_precedes l b}
-> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.array_group3",
"Prims.list",
"CDDL.Spec.opt_precedes",
"Prims.uu___is_Nil",
"Prims.bool"
] | [] | false | false | false | false | false | let match_array_group3
(#b: option Cbor.raw_data_item)
(a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool =
| match a l with
| Some l' -> Nil? l'
| _ -> false | false |
CDDL.Spec.fsti | CDDL.Spec.opt_map_entry_bounded' | val opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool | val opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool | let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 70,
"end_line": 352,
"start_col": 0,
"start_line": 348
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: FStar.Pervasives.Native.option CBOR.Spec.Type.raw_data_item ->
x: (CBOR.Spec.Type.raw_data_item * CBOR.Spec.Type.raw_data_item)
-> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"FStar.Pervasives.Native.tuple2",
"FStar.StrongExcludedMiddle.strong_excluded_middle",
"CDDL.Spec.opt_precedes",
"Prims.bool"
] | [] | false | false | false | false | false | let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool =
| FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) | false |
CDDL.Spec.fsti | CDDL.Spec.simple_value_undefined | val simple_value_undefined:Cbor.simple_value | val simple_value_undefined:Cbor.simple_value | let simple_value_undefined : Cbor.simple_value = 23uy | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 53,
"end_line": 98,
"start_col": 0,
"start_line": 98
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CBOR.Spec.Type.simple_value | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.__uint_to_t"
] | [] | false | false | false | true | false | let simple_value_undefined:Cbor.simple_value =
| 23uy | false |
CDDL.Spec.fsti | CDDL.Spec.nat_up_to | val nat_up_to (n: nat) : eqtype | val nat_up_to (n: nat) : eqtype | let nat_up_to (n: nat) : eqtype = (i: nat { i <= n }) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 53,
"end_line": 139,
"start_col": 0,
"start_line": 139
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 -> Prims.eqtype | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.eqtype"
] | [] | false | false | false | true | false | let nat_up_to (n: nat) : eqtype =
| (i: nat{i <= n}) | false |
CDDL.Spec.fsti | CDDL.Spec.opt_map_entry_bounded | val opt_map_entry_bounded (b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) | val opt_map_entry_bounded (b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) | let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 38,
"end_line": 357,
"start_col": 0,
"start_line": 354
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Pervasives.Native.option CBOR.Spec.Type.raw_data_item
-> Prims.GTot (_: (CBOR.Spec.Type.raw_data_item * CBOR.Spec.Type.raw_data_item) -> Prims.bool) | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"FStar.Ghost.Pull.pull",
"FStar.Pervasives.Native.tuple2",
"Prims.bool",
"CDDL.Spec.opt_map_entry_bounded'"
] | [] | false | false | false | false | false | let opt_map_entry_bounded (b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool) =
| Pull.pull (opt_map_entry_bounded' b) | false |
CDDL.Spec.fsti | CDDL.Spec.cut_map_group_entry | val cut_map_group_entry (#b: _) (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b | val cut_map_group_entry (#b: _) (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b | let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 59,
"end_line": 401,
"start_col": 0,
"start_line": 400
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: CDDL.Spec.bounded_typ_gen b -> ge: CDDL.Spec.map_group_entry b -> CDDL.Spec.map_group_entry b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.bounded_typ_gen",
"CDDL.Spec.map_group_entry",
"CDDL.Spec.MapGroupEntry",
"CDDL.Spec.cut_map_group_entry_key",
"CDDL.Spec.__proj__MapGroupEntry__item__fst",
"CDDL.Spec.__proj__MapGroupEntry__item__snd"
] | [] | false | false | false | false | false | let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
| MapGroupEntry (cut_map_group_entry_key key ge.fst) ge.snd | false |
CDDL.Spec.fsti | CDDL.Spec.map_group_empty | val map_group_empty (#b: _) : map_group b | val map_group_empty (#b: _) : map_group b | let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
} | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 1,
"end_line": 389,
"start_col": 0,
"start_line": 385
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.map_group b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.Mkmap_group",
"Prims.Nil",
"CDDL.Spec.map_group_entry",
"CDDL.Spec.map_group"
] | [] | false | false | false | false | false | let map_group_empty #b : map_group b =
| { one = []; zero_or_one = []; zero_or_more = [] } | false |
CDDL.Spec.fsti | CDDL.Spec.array_group1_item | val array_group1_item (t: typ) : array_group1 | val array_group1_item (t: typ) : array_group1 | let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 24,
"end_line": 132,
"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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: CDDL.Spec.typ -> CDDL.Spec.array_group1 | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.typ",
"Prims.list",
"CBOR.Spec.Type.raw_data_item",
"Prims.bool",
"Prims.op_AmpAmp",
"CDDL.Spec.array_group1"
] | [] | false | false | false | true | false | let array_group1_item (t: typ) : array_group1 =
| fun k l ->
match l with
| [] -> false
| a :: q -> t a && k q | false |
CDDL.Spec.fsti | CDDL.Spec.maybe_cut_map_group | val maybe_cut_map_group (#b: _) (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b | val maybe_cut_map_group (#b: _) (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b | let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 8,
"end_line": 412,
"start_col": 0,
"start_line": 409
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | ge: CDDL.Spec.map_group_entry b -> cut: Prims.bool -> g: CDDL.Spec.map_group b
-> CDDL.Spec.map_group b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.map_group_entry",
"Prims.bool",
"CDDL.Spec.map_group",
"CDDL.Spec.cut_map_group",
"CDDL.Spec.__proj__MapGroupEntry__item__fst"
] | [] | false | false | false | false | false | let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
| if cut then cut_map_group (ge.fst) g else g | false |
CDDL.Spec.fsti | CDDL.Spec.cut_map_group_entry_key | val cut_map_group_entry_key
(#b: _)
(key t: bounded_typ_gen b)
(x: Cbor.raw_data_item{opt_precedes x b})
: GTot bool | val cut_map_group_entry_key
(#b: _)
(key t: bounded_typ_gen b)
(x: Cbor.raw_data_item{opt_precedes x b})
: GTot bool | let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 20,
"end_line": 397,
"start_col": 0,
"start_line": 391
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: CDDL.Spec.bounded_typ_gen b ->
t: CDDL.Spec.bounded_typ_gen b ->
x: CBOR.Spec.Type.raw_data_item{CDDL.Spec.opt_precedes x b}
-> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.bounded_typ_gen",
"CDDL.Spec.opt_precedes",
"Prims.op_AmpAmp",
"Prims.op_Negation",
"Prims.bool"
] | [] | false | false | false | false | false | let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item{opt_precedes x b})
: GTot bool =
| t x && not (key x) | false |
CDDL.Spec.fsti | CDDL.Spec.cut_map_group | val cut_map_group (#b: _) (key: bounded_typ_gen b) (g: map_group b) : map_group b | val cut_map_group (#b: _) (key: bounded_typ_gen b) (g: map_group b) : map_group b | let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
} | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 1,
"end_line": 407,
"start_col": 0,
"start_line": 403
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: CDDL.Spec.bounded_typ_gen b -> g: CDDL.Spec.map_group b -> CDDL.Spec.map_group b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.bounded_typ_gen",
"CDDL.Spec.map_group",
"CDDL.Spec.Mkmap_group",
"FStar.List.Tot.Base.map",
"CDDL.Spec.map_group_entry",
"CDDL.Spec.cut_map_group_entry",
"CDDL.Spec.__proj__Mkmap_group__item__one",
"CDDL.Spec.__proj__Mkmap_group__item__zero_or_one",
"CDDL.Spec.__proj__Mkmap_group__item__zero_or_more"
] | [] | false | false | false | false | false | let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b =
| {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more
} | false |
CDDL.Spec.fsti | CDDL.Spec.map_group_cons_zero_or_one | val map_group_cons_zero_or_one (#b: _) (ge: map_group_entry b) (cut: bool) (g: map_group b)
: map_group b | val map_group_cons_zero_or_one (#b: _) (ge: map_group_entry b) (cut: bool) (g: map_group b)
: map_group b | let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
} | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 424,
"start_col": 0,
"start_line": 420
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | ge: CDDL.Spec.map_group_entry b -> cut: Prims.bool -> g: CDDL.Spec.map_group b
-> CDDL.Spec.map_group b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.map_group_entry",
"Prims.bool",
"CDDL.Spec.map_group",
"CDDL.Spec.Mkmap_group",
"CDDL.Spec.__proj__Mkmap_group__item__one",
"Prims.Cons",
"CDDL.Spec.__proj__Mkmap_group__item__zero_or_one",
"CDDL.Spec.__proj__Mkmap_group__item__zero_or_more",
"CDDL.Spec.maybe_cut_map_group"
] | [] | false | false | false | false | false | let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
| let g = maybe_cut_map_group ge cut g in
{ g with zero_or_one = ge :: g.zero_or_one } | false |
CDDL.Spec.fsti | CDDL.Spec.map_group_cons_zero_or_more | val map_group_cons_zero_or_more (#b: _) (ge: map_group_entry b) (cut: bool) (g: map_group b)
: map_group b | val map_group_cons_zero_or_more (#b: _) (ge: map_group_entry b) (cut: bool) (g: map_group b)
: map_group b | let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
} | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 1,
"end_line": 430,
"start_col": 0,
"start_line": 426
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | ge: CDDL.Spec.map_group_entry b -> cut: Prims.bool -> g: CDDL.Spec.map_group b
-> CDDL.Spec.map_group b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.map_group_entry",
"Prims.bool",
"CDDL.Spec.map_group",
"CDDL.Spec.Mkmap_group",
"CDDL.Spec.__proj__Mkmap_group__item__one",
"CDDL.Spec.__proj__Mkmap_group__item__zero_or_one",
"Prims.Cons",
"CDDL.Spec.__proj__Mkmap_group__item__zero_or_more",
"CDDL.Spec.maybe_cut_map_group"
] | [] | false | false | false | false | false | let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b)
: map_group b =
| let g = maybe_cut_map_group ge cut g in
{ g with zero_or_more = ge :: g.zero_or_more } | false |
CDDL.Spec.fsti | CDDL.Spec.array_group1_zero_or_more' | val array_group1_zero_or_more'
(a: array_group1)
(k: (list Cbor.raw_data_item -> GTot bool))
(l: list Cbor.raw_data_item)
: GTot bool (decreases (List.Tot.length l)) | val array_group1_zero_or_more'
(a: array_group1)
(k: (list Cbor.raw_data_item -> GTot bool))
(l: list Cbor.raw_data_item)
: GTot bool (decreases (List.Tot.length l)) | let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 110,
"end_line": 126,
"start_col": 0,
"start_line": 124
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: CDDL.Spec.array_group1 ->
k: (_: Prims.list CBOR.Spec.Type.raw_data_item -> Prims.GTot Prims.bool) ->
l: Prims.list CBOR.Spec.Type.raw_data_item
-> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial",
""
] | [] | [
"CDDL.Spec.array_group1",
"Prims.list",
"CBOR.Spec.Type.raw_data_item",
"Prims.bool",
"Prims.op_BarBar",
"Prims.op_GreaterThanOrEqual",
"FStar.List.Tot.Base.length",
"CDDL.Spec.array_group1_zero_or_more'"
] | [
"recursion"
] | false | false | false | false | false | let rec array_group1_zero_or_more'
(a: array_group1)
(k: (list Cbor.raw_data_item -> GTot bool))
(l: list Cbor.raw_data_item)
: GTot bool (decreases (List.Tot.length l)) =
| k l ||
a (fun l' ->
if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l')
l | false |
CDDL.Spec.fsti | CDDL.Spec.t_array1 | val t_array1 (a: array_group1) : typ | val t_array1 (a: array_group1) : typ | let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 26,
"end_line": 136,
"start_col": 0,
"start_line": 134
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: CDDL.Spec.array_group1 -> CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.array_group1",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.opt_precedes",
"FStar.Pervasives.Native.None",
"Prims.op_AmpAmp",
"CBOR.Spec.Type.uu___is_Array",
"Prims.uu___is_Nil",
"CBOR.Spec.Type.__proj__Array__item__v",
"Prims.bool",
"CDDL.Spec.typ"
] | [] | false | false | false | true | false | let t_array1 (a: array_group1) : typ =
| fun x -> Cbor.Array? x && a Nil? (Cbor.Array?.v x) | false |
CDDL.Spec.fsti | CDDL.Spec.t_array2 | val t_array2 (a: array_group2) : typ | val t_array2 (a: array_group2) : typ | let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 181,
"start_col": 0,
"start_line": 177
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: CDDL.Spec.array_group2 -> CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.array_group2",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.opt_precedes",
"FStar.Pervasives.Native.None",
"Prims.op_AmpAmp",
"CBOR.Spec.Type.uu___is_Array",
"FStar.List.Tot.Base.mem",
"CDDL.Spec.nat_up_to",
"FStar.Seq.Base.length",
"FStar.Seq.Base.seq_of_list",
"FStar.List.Tot.Base.length",
"Prims.list",
"Prims.b2t",
"FStar.UInt.fits",
"CBOR.Spec.Type.__proj__Array__item__v",
"Prims.bool",
"CDDL.Spec.typ"
] | [] | false | false | false | true | false | let t_array2 (a: array_group2) : typ =
| fun x ->
Cbor.Array? x &&
(let l = Cbor.Array?.v x in
(List.Tot.length l) `List.Tot.mem` (a (Seq.seq_of_list l) 0)) | false |
CDDL.Spec.fsti | CDDL.Spec.map_group_cons_one | val map_group_cons_one (#b: _) (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b | val map_group_cons_one (#b: _) (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b | let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
} | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 418,
"start_col": 0,
"start_line": 414
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | ge: CDDL.Spec.map_group_entry b -> cut: Prims.bool -> g: CDDL.Spec.map_group b
-> CDDL.Spec.map_group b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.map_group_entry",
"Prims.bool",
"CDDL.Spec.map_group",
"CDDL.Spec.Mkmap_group",
"Prims.Cons",
"CDDL.Spec.__proj__Mkmap_group__item__one",
"CDDL.Spec.__proj__Mkmap_group__item__zero_or_one",
"CDDL.Spec.__proj__Mkmap_group__item__zero_or_more",
"CDDL.Spec.maybe_cut_map_group"
] | [] | false | false | false | false | false | let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
| let g = maybe_cut_map_group ge cut g in
{ g with one = ge :: g.one } | false |
CDDL.Spec.fsti | CDDL.Spec.is_sub_typ_of | val is_sub_typ_of (#b: _) (small large: bounded_typ_gen b) : Tot prop | val is_sub_typ_of (#b: _) (small large: bounded_typ_gen b) : Tot prop | let is_sub_typ_of
#b
(small large: bounded_typ_gen b)
: Tot prop
= forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 75,
"end_line": 466,
"start_col": 0,
"start_line": 462
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *)
noextract
let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x
noextract
let map_group_equiv
#b
(mg1 mg2: map_group b)
: Tot prop
= forall x . matches_map_group mg1 x == matches_map_group mg2 x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | small: CDDL.Spec.bounded_typ_gen b -> large: CDDL.Spec.bounded_typ_gen b -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.bounded_typ_gen",
"Prims.l_Forall",
"CDDL.Spec.opt_precedes",
"Prims.l_imp",
"Prims.b2t",
"Prims.prop"
] | [] | false | false | false | false | true | let is_sub_typ_of #b (small: bounded_typ_gen b) (large: bounded_typ_gen b) : Tot prop =
| forall (x: Cbor.raw_data_item{opt_precedes x b}). small x ==> large x | false |
CDDL.Spec.fsti | CDDL.Spec.array_group3_equiv | val array_group3_equiv (#b: _) (g1 g2: array_group3 b) : Tot prop | val array_group3_equiv (#b: _) (g1 g2: array_group3 b) : Tot prop | let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 25,
"end_line": 245,
"start_col": 0,
"start_line": 241
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | g1: CDDL.Spec.array_group3 b -> g2: CDDL.Spec.array_group3 b -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.array_group3",
"Prims.l_Forall",
"Prims.list",
"Prims.l_and",
"CDDL.Spec.opt_precedes",
"Prims.eq2",
"Prims.prop"
] | [] | false | false | false | false | true | let array_group3_equiv #b (g1: array_group3 b) (g2: array_group3 b) : Tot prop =
| forall l. g1 l == g2 l | false |
CDDL.Spec.fsti | CDDL.Spec.is_sub_map_group_entry_of | val is_sub_map_group_entry_of (#b: _) (small large: map_group_entry b) : Tot prop | val is_sub_map_group_entry_of (#b: _) (small large: map_group_entry b) : Tot prop | let is_sub_map_group_entry_of
#b
(small large: map_group_entry b)
: Tot prop
= small.fst `is_sub_typ_of` large.fst /\
small.snd `is_sub_typ_of` large.snd | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 37,
"end_line": 474,
"start_col": 0,
"start_line": 469
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *)
noextract
let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x
noextract
let map_group_equiv
#b
(mg1 mg2: map_group b)
: Tot prop
= forall x . matches_map_group mg1 x == matches_map_group mg2 x
noextract
let is_sub_typ_of
#b
(small large: bounded_typ_gen b)
: Tot prop
= forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | small: CDDL.Spec.map_group_entry b -> large: CDDL.Spec.map_group_entry b -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.map_group_entry",
"Prims.l_and",
"CDDL.Spec.is_sub_typ_of",
"CDDL.Spec.__proj__MapGroupEntry__item__fst",
"CDDL.Spec.__proj__MapGroupEntry__item__snd",
"Prims.prop"
] | [] | false | false | false | false | true | let is_sub_map_group_entry_of #b (small: map_group_entry b) (large: map_group_entry b) : Tot prop =
| small.fst `is_sub_typ_of` large.fst /\ small.snd `is_sub_typ_of` large.snd | false |
CDDL.Spec.fsti | CDDL.Spec.array_group3_choice | val array_group3_choice (#b: _) (a1 a3: array_group3 b) : array_group3 b | val array_group3_choice (#b: _) (a1 a3: array_group3 b) : array_group3 b | let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3 | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 24,
"end_line": 267,
"start_col": 0,
"start_line": 264
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | a1: CDDL.Spec.array_group3 b -> a3: CDDL.Spec.array_group3 b -> CDDL.Spec.array_group3 b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.array_group3",
"Prims.list",
"CDDL.Spec.opt_precedes",
"FStar.Pervasives.Native.Some"
] | [] | false | false | false | false | false | let array_group3_choice #b (a1: array_group3 b) (a3: array_group3 b) : array_group3 b =
| fun l ->
match a1 l with
| None -> a3 l
| Some l3 -> Some l3 | false |
CDDL.Spec.fsti | CDDL.Spec.list_is_suffix_of_precedes | val list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t)
: Lemma (requires (large << v0 /\ small `list_is_suffix_of` large))
(ensures (small << v0))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] | val list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t)
: Lemma (requires (large << v0 /\ small `list_is_suffix_of` large))
(ensures (small << v0))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] | let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 230,
"start_col": 0,
"start_line": 208
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | v0: t0 -> small: Prims.list t -> large: Prims.list t
-> FStar.Pervasives.Lemma (requires large << v0 /\ CDDL.Spec.list_is_suffix_of small large)
(ensures small << v0)
(decreases FStar.List.Tot.Base.length large)
[SMTPat [small << v0]; SMTPat [CDDL.Spec.list_is_suffix_of small large]] | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.list",
"Prims.uu___is_Nil",
"CDDL.Spec.list_nil_precedes",
"Prims.bool",
"Prims.op_Equality",
"Prims.nat",
"FStar.List.Tot.Base.length",
"CDDL.Spec.list_is_suffix_of_precedes",
"FStar.List.Tot.Base.tl",
"Prims.unit",
"FStar.List.Tot.Properties.append_length",
"Prims.eq2",
"FStar.List.Tot.Base.append",
"FStar.IndefiniteDescription.indefinite_description_ghost",
"Prims.prop",
"Prims.l_and",
"Prims.precedes",
"CDDL.Spec.list_is_suffix_of",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [
"recursion"
] | false | false | true | false | false | let rec list_is_suffix_of_precedes (#t0 #t: Type) (v0: t0) (small large: list t)
: Lemma (requires (large << v0 /\ small `list_is_suffix_of` large))
(ensures (small << v0))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]] =
| if Nil? small
then list_nil_precedes large
else
let prefix =
FStar.IndefiniteDescription.indefinite_description_ghost (list t)
(fun prefix -> large == prefix `List.Tot.append` small)
in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large) | false |
Hacl.Impl.K256.Qinv.fst | Hacl.Impl.K256.Qinv.qinv8 | val qinv8 (tmp f x_11 x_101 x_111 x_1001 x_1011 x_1101: qelem) : Stack unit
(requires fun h ->
live h tmp /\ live h f /\ live h x_11 /\
live h x_101 /\ live h x_111 /\ live h x_1001 /\
live h x_1011 /\ live h x_1101 /\
disjoint tmp f /\ disjoint tmp x_11 /\ disjoint tmp x_101 /\
disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\
disjoint tmp x_1101 /\
qe_lt_q h f /\ qe_lt_q h x_11 /\ qe_lt_q h x_101 /\
qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\
qe_lt_q h x_1101)
(ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\
qas_nat h1 tmp == SI.qinv_r0_r25 (qas_nat h0 f)
(qas_nat h0 x_11) (qas_nat h0 x_101) (qas_nat h0 x_111)
(qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\
qe_lt_q h1 tmp) | val qinv8 (tmp f x_11 x_101 x_111 x_1001 x_1011 x_1101: qelem) : Stack unit
(requires fun h ->
live h tmp /\ live h f /\ live h x_11 /\
live h x_101 /\ live h x_111 /\ live h x_1001 /\
live h x_1011 /\ live h x_1101 /\
disjoint tmp f /\ disjoint tmp x_11 /\ disjoint tmp x_101 /\
disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\
disjoint tmp x_1101 /\
qe_lt_q h f /\ qe_lt_q h x_11 /\ qe_lt_q h x_101 /\
qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\
qe_lt_q h x_1101)
(ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\
qas_nat h1 tmp == SI.qinv_r0_r25 (qas_nat h0 f)
(qas_nat h0 x_11) (qas_nat h0 x_101) (qas_nat h0 x_111)
(qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\
qe_lt_q h1 tmp) | let qinv8 tmp f x_11 x_101 x_111 x_1001 x_1011 x_1101 =
push_frame ();
let x6 = create_qelem () in
let x8 = create_qelem () in
let x14 = create_qelem () in
let h1 = ST.get () in
qinv2 x_11 x_1011 x_1101 x6 x8 x14; //x6; x8; x14
let h2 = ST.get () in
assert (modifies (loc x6 |+| loc x8 |+| loc x14) h1 h2);
qinv3 tmp x14; //x28; x56; r0; r1
let h3 = ST.get () in
assert (modifies (loc tmp) h2 h3);
qinv4 tmp x_101 x_111 x_1011; //r2; ..; r8
let h4 = ST.get () in
assert (modifies (loc tmp) h3 h4);
qinv5 tmp x_101 x_111 x_1001 x_1101; //r9; ..; r15
let h5 = ST.get () in
assert (modifies (loc tmp) h4 h5);
qinv6 tmp x8 x_11 x_1001 x_1011 x_1101; //r16; ..; r23
let h6 = ST.get () in
assert (modifies (loc tmp) h5 h6);
qinv7 tmp f x6; //r24; r25
let h7 = ST.get () in
assert (modifies (loc tmp) h6 h7);
pop_frame () | {
"file_name": "code/k256/Hacl.Impl.K256.Qinv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 464,
"start_col": 0,
"start_line": 434
} | module Hacl.Impl.K256.Qinv
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.K256.Scalar
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Spec.K256
module SI = Hacl.Spec.K256.Qinv
module SE = Spec.Exponentiation
module BE = Hacl.Impl.Exponentiation
module SD = Hacl.Spec.Bignum.Definitions
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let linv_ctx (a:LSeq.lseq uint64 0) : Type0 = True
unfold
let linv (a:LSeq.lseq uint64 4) : Type0 =
SD.bn_v #U64 #4 a < S.q
unfold
let refl (a:LSeq.lseq uint64 4{linv a}) : GTot S.qelem =
SD.bn_v #U64 #4 a
inline_for_extraction noextract
let mk_to_k256_scalar_comm_monoid : BE.to_comm_monoid U64 4ul 0ul = {
BE.a_spec = S.qelem;
BE.comm_monoid = SI.nat_mod_comm_monoid;
BE.linv_ctx = linv_ctx;
BE.linv = linv;
BE.refl = refl;
}
inline_for_extraction noextract
val one_mod : BE.lone_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid
let one_mod ctx one = make_u64_4 one (u64 1, u64 0, u64 0, u64 0)
inline_for_extraction noextract
val mul_mod : BE.lmul_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid
let mul_mod ctx x y xy = qmul xy x y
inline_for_extraction noextract
val sqr_mod : BE.lsqr_st U64 4ul 0ul mk_to_k256_scalar_comm_monoid
let sqr_mod ctx x xx = qsqr xx x
inline_for_extraction noextract
let mk_k256_scalar_concrete_ops : BE.concrete_ops U64 4ul 0ul = {
BE.to = mk_to_k256_scalar_comm_monoid;
BE.lone = one_mod;
BE.lmul = mul_mod;
BE.lsqr = sqr_mod;
}
val qsquare_times_in_place (out:qelem) (b:size_t) : Stack unit
(requires fun h ->
live h out /\ qe_lt_q h out)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 out /\
qas_nat h1 out == SI.qsquare_times (qas_nat h0 out) (v b))
[@CInline]
let qsquare_times_in_place out b =
let h0 = ST.get () in
SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 out) (v b);
BE.lexp_pow2_in_place 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) out b
val qsquare_times (out a:qelem) (b:size_t) : Stack unit
(requires fun h ->
live h out /\ live h a /\ disjoint out a /\
qe_lt_q h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\ qe_lt_q h1 a /\
qas_nat h1 out == SI.qsquare_times (qas_nat h0 a) (v b))
[@CInline]
let qsquare_times out a b =
let h0 = ST.get () in
SE.exp_pow2_lemma SI.mk_nat_mod_concrete_ops (qas_nat h0 a) (v b);
BE.lexp_pow2 4ul 0ul mk_k256_scalar_concrete_ops (null uint64) a b out
inline_for_extraction noextract
val qinv1 (f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101:qelem) : Stack unit
(requires fun h ->
live h f /\ live h x_10 /\ live h x_11 /\ live h x_101 /\
live h x_111 /\ live h x_1001 /\ live h x_1011 /\ live h x_1101 /\
disjoint f x_10 /\ disjoint f x_11 /\ disjoint f x_101 /\
disjoint f x_111 /\ disjoint f x_1001 /\ disjoint f x_1011 /\
disjoint f x_1101 /\ disjoint x_10 x_11 /\ disjoint x_10 x_101 /\
disjoint x_10 x_111 /\ disjoint x_10 x_1001 /\ disjoint x_10 x_1011 /\
disjoint x_10 x_1101 /\ disjoint x_11 x_101 /\ disjoint x_11 x_111 /\
disjoint x_11 x_1001 /\ disjoint x_11 x_1011 /\ disjoint x_11 x_1101 /\
disjoint x_101 x_111 /\ disjoint x_101 x_1001 /\ disjoint x_101 x_1011 /\
disjoint x_101 x_1101 /\ disjoint x_111 x_1001 /\ disjoint x_111 x_1011 /\
disjoint x_111 x_1101 /\ disjoint x_1001 x_1011 /\ disjoint x_1001 x_1101 /\
disjoint x_1011 x_1101 /\ qe_lt_q h f)
(ensures fun h0 _ h1 ->
modifies (loc x_10 |+| loc x_11 |+| loc x_101 |+|
loc x_111 |+| loc x_1001 |+| loc x_1011 |+| loc x_1101) h0 h1 /\
(let _x_10 = SI.qsquare_times (qas_nat h0 f) 1 in
let _x_11 = S.qmul _x_10 (qas_nat h0 f) in
let _x_101 = S.qmul _x_10 _x_11 in
let _x_111 = S.qmul _x_10 _x_101 in
let _x_1001 = S.qmul _x_10 _x_111 in
let _x_1011 = S.qmul _x_10 _x_1001 in
let _x_1101 = S.qmul _x_10 _x_1011 in
qas_nat h1 x_10 == _x_10 /\ qe_lt_q h1 x_10 /\
qas_nat h1 x_11 == _x_11 /\ qe_lt_q h1 x_11 /\
qas_nat h1 x_101 == _x_101 /\ qe_lt_q h1 x_101 /\
qas_nat h1 x_111 == _x_111 /\ qe_lt_q h1 x_111 /\
qas_nat h1 x_1001 == _x_1001 /\ qe_lt_q h1 x_1001 /\
qas_nat h1 x_1011 == _x_1011 /\ qe_lt_q h1 x_1011 /\
qas_nat h1 x_1101 == _x_1101 /\ qe_lt_q h1 x_1101))
let qinv1 f x_10 x_11 x_101 x_111 x_1001 x_1011 x_1101 =
let h0 = ST.get () in
qsquare_times x_10 f 1ul;
let h1 = ST.get () in
assert (qas_nat h1 x_10 == SI.qsquare_times (qas_nat h0 f) 1);
qmul x_11 x_10 f;
let h2 = ST.get () in
assert (qas_nat h2 x_11 == S.qmul (qas_nat h1 x_10) (qas_nat h0 f));
qmul x_101 x_10 x_11;
let h3 = ST.get () in
assert (qas_nat h3 x_101 == S.qmul (qas_nat h1 x_10) (qas_nat h2 x_11));
qmul x_111 x_10 x_101;
let h4 = ST.get () in
assert (qas_nat h4 x_111 == S.qmul (qas_nat h1 x_10) (qas_nat h3 x_101));
qmul x_1001 x_10 x_111;
let h5 = ST.get () in
assert (qas_nat h5 x_1001 == S.qmul (qas_nat h1 x_10) (qas_nat h4 x_111));
qmul x_1011 x_10 x_1001;
let h6 = ST.get () in
assert (qas_nat h6 x_1011 == S.qmul (qas_nat h1 x_10) (qas_nat h5 x_1001));
qmul x_1101 x_10 x_1011;
let h7 = ST.get () in
assert (qas_nat h7 x_1101 == S.qmul (qas_nat h1 x_10) (qas_nat h6 x_1011))
inline_for_extraction noextract
val qinv2 (x_11 x_1011 x_1101 x6 x8 x14: qelem) : Stack unit
(requires fun h ->
live h x_11 /\ live h x_1011 /\ live h x_1101 /\
live h x6 /\ live h x8 /\ live h x14 /\
disjoint x_11 x6 /\ disjoint x_11 x8 /\ disjoint x_11 x14 /\
disjoint x_1011 x6 /\ disjoint x_1011 x8 /\ disjoint x_1011 x14 /\
disjoint x_1101 x6 /\ disjoint x_1101 x8 /\ disjoint x_1101 x14 /\
disjoint x6 x8 /\ disjoint x6 x14 /\ disjoint x8 x14 /\
qe_lt_q h x_11 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101)
(ensures fun h0 _ h1 -> modifies (loc x6 |+| loc x8 |+| loc x14) h0 h1 /\
(let _x6 = S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011) in
let _x8 = S.qmul (SI.qsquare_times _x6 2) (qas_nat h0 x_11) in
let _x14 = S.qmul (SI.qsquare_times _x8 6) _x6 in
qas_nat h1 x6 == _x6 /\ qe_lt_q h1 x6 /\
qas_nat h1 x8 == _x8 /\ qe_lt_q h1 x8 /\
qas_nat h1 x14 == _x14 /\ qe_lt_q h1 x14))
let qinv2 x_11 x_1011 x_1101 x6 x8 x14 =
let h0 = ST.get () in
qsquare_times x6 x_1101 2ul;
qmul x6 x6 x_1011;
let h1 = ST.get () in
assert (qas_nat h1 x6 == S.qmul (SI.qsquare_times (qas_nat h0 x_1101) 2) (qas_nat h0 x_1011));
qsquare_times x8 x6 2ul;
qmul x8 x8 x_11;
let h2 = ST.get () in
assert (qas_nat h2 x8 == S.qmul (SI.qsquare_times (qas_nat h1 x6) 2) (qas_nat h0 x_11));
qsquare_times x14 x8 6ul;
qmul x14 x14 x6;
let h3 = ST.get () in
assert (qas_nat h3 x14 == S.qmul (SI.qsquare_times (qas_nat h2 x8) 6) (qas_nat h1 x6))
inline_for_extraction noextract
val qinv3 (tmp x14: qelem) : Stack unit
(requires fun h ->
live h tmp /\ live h x14 /\ disjoint tmp x14 /\
qe_lt_q h x14)
(ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\
qas_nat h1 tmp == SI.qinv_r0_r1 (qas_nat h0 x14) /\
qe_lt_q h1 tmp)
let qinv3 tmp x14 =
push_frame ();
let x56 = create_qelem () in
let h0 = ST.get () in
qsquare_times tmp x14 14ul;
qmul tmp tmp x14; //tmp = x28
let h1 = ST.get () in
assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 x14) 14) (qas_nat h0 x14));
qsquare_times x56 tmp 28ul;
qmul x56 x56 tmp;
let h2 = ST.get () in
assert (qas_nat h2 x56 == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 28) (qas_nat h1 tmp));
qsquare_times tmp x56 56ul; //tmp = r0
qmul tmp tmp x56;
let h3 = ST.get () in
assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 x56) 56) (qas_nat h2 x56));
qsquare_times_in_place tmp 14ul; //tmp = r1
qmul tmp tmp x14;
let h4 = ST.get () in
assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 14) (qas_nat h0 x14));
pop_frame ()
//r2; .. ;r8
inline_for_extraction noextract
val qinv4 (tmp x_101 x_111 x_1011: qelem) : Stack unit
(requires fun h ->
live h tmp /\ live h x_101 /\ live h x_111 /\ live h x_1011 /\
disjoint tmp x_101 /\ disjoint tmp x_111 /\ disjoint tmp x_1011 /\
qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\ qe_lt_q h x_1011)
(ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\
qas_nat h1 tmp == SI.qinv_r2_r8 (qas_nat h0 tmp)
(qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1011) /\
qe_lt_q h1 tmp)
let qinv4 tmp x_101 x_111 x_1011 =
let h0 = ST.get () in
qsquare_times_in_place tmp 3ul;
qmul tmp tmp x_101; //tmp = r2
let h1 = ST.get () in
assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 3) (qas_nat h0 x_101));
qsquare_times_in_place tmp 4ul;
qmul tmp tmp x_111; //tmp = r3
let h2 = ST.get () in
assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_111));
qsquare_times_in_place tmp 4ul;
qmul tmp tmp x_101; //tmp = r4
let h3 = ST.get () in
assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 4) (qas_nat h0 x_101));
qsquare_times_in_place tmp 5ul;
qmul tmp tmp x_1011; //tmp = r5
let h4 = ST.get () in
assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1011));
qsquare_times_in_place tmp 4ul;
qmul tmp tmp x_1011; //tmp = r6
let h5 = ST.get () in
assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 4) (qas_nat h0 x_1011));
qsquare_times_in_place tmp 4ul;
qmul tmp tmp x_111; //tmp = r7
let h6 = ST.get () in
assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 4) (qas_nat h0 x_111));
qsquare_times_in_place tmp 5ul;
qmul tmp tmp x_111; //tmp = r8
let h7 = ST.get () in
assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 5) (qas_nat h0 x_111))
// r9; ..; r15
inline_for_extraction noextract
val qinv5 (tmp x_101 x_111 x_1001 x_1101: qelem) : Stack unit
(requires fun h ->
live h tmp /\ live h x_101 /\ live h x_111 /\
live h x_1001 /\ live h x_1101 /\ disjoint tmp x_101 /\
disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1101 /\
qe_lt_q h tmp /\ qe_lt_q h x_101 /\ qe_lt_q h x_111 /\
qe_lt_q h x_1001 /\ qe_lt_q h x_1101)
(ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\
qas_nat h1 tmp == SI.qinv_r9_r15 (qas_nat h0 tmp)
(qas_nat h0 x_101) (qas_nat h0 x_111) (qas_nat h0 x_1001) (qas_nat h0 x_1101) /\
qe_lt_q h1 tmp)
let qinv5 tmp x_101 x_111 x_1001 x_1101 =
let h0 = ST.get () in
qsquare_times_in_place tmp 6ul;
qmul tmp tmp x_1101; //tmp = r9
let h1 = ST.get () in
assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 6) (qas_nat h0 x_1101));
qsquare_times_in_place tmp 4ul;
qmul tmp tmp x_101; //tmp = r10
let h2 = ST.get () in
assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 4) (qas_nat h0 x_101));
qsquare_times_in_place tmp 3ul;
qmul tmp tmp x_111; //tmp = r11
let h3 = ST.get () in
assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 3) (qas_nat h0 x_111));
qsquare_times_in_place tmp 5ul;
qmul tmp tmp x_1001; //tmp = r12
let h4 = ST.get () in
assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 5) (qas_nat h0 x_1001));
qsquare_times_in_place tmp 6ul;
qmul tmp tmp x_101; //tmp = r13
let h5 = ST.get () in
assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 6) (qas_nat h0 x_101));
qsquare_times_in_place tmp 10ul;
qmul tmp tmp x_111; //tmp = r14
let h6 = ST.get () in
assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 10) (qas_nat h0 x_111));
qsquare_times_in_place tmp 4ul;
qmul tmp tmp x_111; //tmp = r15
let h7 = ST.get () in
assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 4) (qas_nat h0 x_111))
// r16; ..;r23
inline_for_extraction noextract
val qinv6 (tmp x8 x_11 x_1001 x_1011 x_1101: qelem) : Stack unit
(requires fun h ->
live h tmp /\ live h x8 /\ live h x_11 /\
live h x_1001 /\ live h x_1011 /\ live h x_1101 /\
disjoint tmp x8 /\ disjoint tmp x_11 /\ disjoint tmp x_1001 /\
disjoint tmp x_1011 /\ disjoint tmp x_1101 /\
qe_lt_q h tmp /\ qe_lt_q h x8 /\ qe_lt_q h x_11 /\
qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\ qe_lt_q h x_1101)
(ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\
qas_nat h1 tmp == SI.qinv_r16_r23 (qas_nat h0 tmp)
(qas_nat h0 x8) (qas_nat h0 x_11) (qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\
qe_lt_q h1 tmp)
let qinv6 tmp x8 x_11 x_1001 x_1011 x_1101 =
let h0 = ST.get () in
qsquare_times_in_place tmp 9ul;
qmul tmp tmp x8; //tmp = r16
let h1 = ST.get () in
assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 9) (qas_nat h0 x8));
qsquare_times_in_place tmp 5ul;
qmul tmp tmp x_1001; //tmp = r17
let h2 = ST.get () in
assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 5) (qas_nat h0 x_1001));
qsquare_times_in_place tmp 6ul;
qmul tmp tmp x_1011; //tmp = r18
let h3 = ST.get () in
assert (qas_nat h3 tmp == S.qmul (SI.qsquare_times (qas_nat h2 tmp) 6) (qas_nat h0 x_1011));
qsquare_times_in_place tmp 4ul;
qmul tmp tmp x_1101; //tmp = r19
let h4 = ST.get () in
assert (qas_nat h4 tmp == S.qmul (SI.qsquare_times (qas_nat h3 tmp) 4) (qas_nat h0 x_1101));
qsquare_times_in_place tmp 5ul;
qmul tmp tmp x_11; //tmp = r20
let h5 = ST.get () in
assert (qas_nat h5 tmp == S.qmul (SI.qsquare_times (qas_nat h4 tmp) 5) (qas_nat h0 x_11));
qsquare_times_in_place tmp 6ul;
qmul tmp tmp x_1101; //tmp = r21
let h6 = ST.get () in
assert (qas_nat h6 tmp == S.qmul (SI.qsquare_times (qas_nat h5 tmp) 6) (qas_nat h0 x_1101));
qsquare_times_in_place tmp 10ul;
qmul tmp tmp x_1101; //tmp = r22
let h7 = ST.get () in
assert (qas_nat h7 tmp == S.qmul (SI.qsquare_times (qas_nat h6 tmp) 10) (qas_nat h0 x_1101));
qsquare_times_in_place tmp 4ul;
qmul tmp tmp x_1001; //tmp = r23
let h8 = ST.get () in
assert (qas_nat h8 tmp == S.qmul (SI.qsquare_times (qas_nat h7 tmp) 4) (qas_nat h0 x_1001))
//r24; r25
inline_for_extraction noextract
val qinv7 (tmp f x6: qelem) : Stack unit
(requires fun h ->
live h tmp /\ live h f /\ live h x6 /\
disjoint tmp f /\ disjoint tmp x6 /\
qe_lt_q h tmp /\ qe_lt_q h f /\ qe_lt_q h x6)
(ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\
qas_nat h1 tmp == SI.qinv_r24_r25 (qas_nat h0 tmp) (qas_nat h0 f) (qas_nat h0 x6) /\
qe_lt_q h1 tmp)
let qinv7 tmp f x6 =
let h0 = ST.get () in
qsquare_times_in_place tmp 6ul;
qmul tmp tmp f; //tmp = r23
let h1 = ST.get () in
assert (qas_nat h1 tmp == S.qmul (SI.qsquare_times (qas_nat h0 tmp) 6) (qas_nat h0 f));
qsquare_times_in_place tmp 8ul;
qmul tmp tmp x6; //tmp = r24
let h2 = ST.get () in
assert (qas_nat h2 tmp == S.qmul (SI.qsquare_times (qas_nat h1 tmp) 8) (qas_nat h0 x6))
inline_for_extraction noextract
val qinv8 (tmp f x_11 x_101 x_111 x_1001 x_1011 x_1101: qelem) : Stack unit
(requires fun h ->
live h tmp /\ live h f /\ live h x_11 /\
live h x_101 /\ live h x_111 /\ live h x_1001 /\
live h x_1011 /\ live h x_1101 /\
disjoint tmp f /\ disjoint tmp x_11 /\ disjoint tmp x_101 /\
disjoint tmp x_111 /\ disjoint tmp x_1001 /\ disjoint tmp x_1011 /\
disjoint tmp x_1101 /\
qe_lt_q h f /\ qe_lt_q h x_11 /\ qe_lt_q h x_101 /\
qe_lt_q h x_111 /\ qe_lt_q h x_1001 /\ qe_lt_q h x_1011 /\
qe_lt_q h x_1101)
(ensures fun h0 _ h1 -> modifies (loc tmp) h0 h1 /\
qas_nat h1 tmp == SI.qinv_r0_r25 (qas_nat h0 f)
(qas_nat h0 x_11) (qas_nat h0 x_101) (qas_nat h0 x_111)
(qas_nat h0 x_1001) (qas_nat h0 x_1011) (qas_nat h0 x_1101) /\
qe_lt_q h1 tmp) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"Spec.Exponentiation.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Qinv.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.Impl.Exponentiation.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.K256.Qinv.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Exponentiation",
"short_module": "BE"
},
{
"abbrev": true,
"full_module": "Spec.Exponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Qinv",
"short_module": "SI"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"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": "Hacl.K256.Scalar",
"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.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
tmp: Hacl.K256.Scalar.qelem ->
f: Hacl.K256.Scalar.qelem ->
x_11: Hacl.K256.Scalar.qelem ->
x_101: Hacl.K256.Scalar.qelem ->
x_111: Hacl.K256.Scalar.qelem ->
x_1001: Hacl.K256.Scalar.qelem ->
x_1011: Hacl.K256.Scalar.qelem ->
x_1101: Hacl.K256.Scalar.qelem
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.K256.Scalar.qelem",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Prims._assert",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint64",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.K256.Qinv.qinv7",
"Hacl.Impl.K256.Qinv.qinv6",
"Hacl.Impl.K256.Qinv.qinv5",
"Hacl.Impl.K256.Qinv.qinv4",
"Hacl.Impl.K256.Qinv.qinv3",
"Lib.Buffer.op_Bar_Plus_Bar",
"Hacl.Impl.K256.Qinv.qinv2",
"Hacl.K256.Scalar.create_qelem",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let qinv8 tmp f x_11 x_101 x_111 x_1001 x_1011 x_1101 =
| push_frame ();
let x6 = create_qelem () in
let x8 = create_qelem () in
let x14 = create_qelem () in
let h1 = ST.get () in
qinv2 x_11 x_1011 x_1101 x6 x8 x14;
let h2 = ST.get () in
assert (modifies (loc x6 |+| loc x8 |+| loc x14) h1 h2);
qinv3 tmp x14;
let h3 = ST.get () in
assert (modifies (loc tmp) h2 h3);
qinv4 tmp x_101 x_111 x_1011;
let h4 = ST.get () in
assert (modifies (loc tmp) h3 h4);
qinv5 tmp x_101 x_111 x_1001 x_1101;
let h5 = ST.get () in
assert (modifies (loc tmp) h4 h5);
qinv6 tmp x8 x_11 x_1001 x_1011 x_1101;
let h6 = ST.get () in
assert (modifies (loc tmp) h5 h6);
qinv7 tmp f x6;
let h7 = ST.get () in
assert (modifies (loc tmp) h6 h7);
pop_frame () | false |
CDDL.Spec.fsti | CDDL.Spec.array_group3_empty | val array_group3_empty (#b: _) : array_group3 b | val array_group3_empty (#b: _) : array_group3 b | let array_group3_empty #b : array_group3 b = fun x -> Some x | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 60,
"end_line": 248,
"start_col": 0,
"start_line": 248
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.array_group3 b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"Prims.list",
"CDDL.Spec.opt_precedes",
"FStar.Pervasives.Native.Some",
"CDDL.Spec.array_group3"
] | [] | false | false | false | false | false | let array_group3_empty #b : array_group3 b =
| fun x -> Some x | false |
CDDL.Spec.fsti | CDDL.Spec.array_group2_zero_or_more' | val array_group2_zero_or_more'
(a: array_group2)
(l: Seq.seq Cbor.raw_data_item)
(i: nat_up_to (Seq.length l))
: Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) | val array_group2_zero_or_more'
(a: array_group2)
(l: Seq.seq Cbor.raw_data_item)
(i: nat_up_to (Seq.length l))
: Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) | let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 166,
"start_col": 0,
"start_line": 157
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: CDDL.Spec.array_group2 ->
l: FStar.Seq.Base.seq CBOR.Spec.Type.raw_data_item ->
i: CDDL.Spec.nat_up_to (FStar.Seq.Base.length l)
-> Prims.Tot (Prims.list (CDDL.Spec.nat_up_to (FStar.Seq.Base.length l))) | Prims.Tot | [
"total",
""
] | [] | [
"CDDL.Spec.array_group2",
"FStar.Seq.Base.seq",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.nat_up_to",
"FStar.Seq.Base.length",
"Prims.Cons",
"FStar.List.Tot.Base.concatMap",
"Prims.op_LessThanOrEqual",
"Prims.Nil",
"Prims.bool",
"CDDL.Spec.array_group2_zero_or_more'",
"Prims.list"
] | [
"recursion"
] | false | false | false | false | false | let rec array_group2_zero_or_more'
(a: array_group2)
(l: Seq.seq Cbor.raw_data_item)
(i: nat_up_to (Seq.length l))
: Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
| i ::
(let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i then [] else array_group2_zero_or_more' a l i2)
r1) | false |
CDDL.Spec.fsti | CDDL.Spec.map_group_ignore_restricted_entries | val map_group_ignore_restricted_entries (#b: _) (mg: map_group b) : Tot (map_group b) | val map_group_ignore_restricted_entries (#b: _) (mg: map_group b) : Tot (map_group b) | let map_group_ignore_restricted_entries
#b
(mg: map_group b)
: Tot (map_group b)
= {mg with
one = [];
zero_or_one = [];
} | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 483,
"start_col": 0,
"start_line": 476
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *)
noextract
let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x
noextract
let map_group_equiv
#b
(mg1 mg2: map_group b)
: Tot prop
= forall x . matches_map_group mg1 x == matches_map_group mg2 x
noextract
let is_sub_typ_of
#b
(small large: bounded_typ_gen b)
: Tot prop
= forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x
noextract
let is_sub_map_group_entry_of
#b
(small large: map_group_entry b)
: Tot prop
= small.fst `is_sub_typ_of` large.fst /\
small.snd `is_sub_typ_of` large.snd | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | mg: CDDL.Spec.map_group b -> CDDL.Spec.map_group b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.map_group",
"CDDL.Spec.Mkmap_group",
"Prims.Nil",
"CDDL.Spec.map_group_entry",
"CDDL.Spec.__proj__Mkmap_group__item__zero_or_more"
] | [] | false | false | false | false | false | let map_group_ignore_restricted_entries #b (mg: map_group b) : Tot (map_group b) =
| { mg with one = []; zero_or_one = [] } | false |
CDDL.Spec.fsti | CDDL.Spec.t_array3_rec | val t_array3_rec
(phi: (b: Cbor.raw_data_item -> (bounded_typ b -> array_group3 (Some b))))
(x: Cbor.raw_data_item)
: GTot bool (decreases x) | val t_array3_rec
(phi: (b: Cbor.raw_data_item -> (bounded_typ b -> array_group3 (Some b))))
(x: Cbor.raw_data_item)
: GTot bool (decreases x) | let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 65,
"end_line": 337,
"start_col": 0,
"start_line": 330
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
phi:
(b: CBOR.Spec.Type.raw_data_item -> _: CDDL.Spec.bounded_typ b
-> CDDL.Spec.array_group3 (FStar.Pervasives.Native.Some b)) ->
x: CBOR.Spec.Type.raw_data_item
-> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial",
""
] | [] | [
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.bounded_typ",
"CDDL.Spec.array_group3",
"FStar.Pervasives.Native.Some",
"Prims.op_AmpAmp",
"CBOR.Spec.Type.uu___is_Array",
"CDDL.Spec.match_array_group3",
"CDDL.Spec.t_array3_rec",
"CBOR.Spec.Type.__proj__Array__item__v",
"Prims.bool"
] | [
"recursion"
] | false | false | false | false | false | let rec t_array3_rec
(phi: (b: Cbor.raw_data_item -> (bounded_typ b -> array_group3 (Some b))))
(x: Cbor.raw_data_item)
: GTot bool (decreases x) =
| Cbor.Array? x && match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x) | false |
CDDL.Spec.fsti | CDDL.Spec.list_nil_precedes | val list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) | val list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) | let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 33,
"end_line": 206,
"start_col": 0,
"start_line": 199
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 t -> FStar.Pervasives.Lemma (ensures [] == l \/ [] << l) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"CDDL.Spec.list_nil_precedes",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_or",
"Prims.eq2",
"Prims.Nil",
"Prims.precedes",
"FStar.Pervasives.pattern"
] | [
"recursion"
] | false | false | true | false | false | let rec list_nil_precedes (#t: Type) (l: list t) : Lemma (Nil #t == l \/ Nil #t << l) =
| match l with
| [] -> ()
| a :: q -> list_nil_precedes q | false |
CDDL.Spec.fsti | CDDL.Spec.list_ghost_forall_exists_body | val list_ghost_forall_exists_body (#t1 #t2: Type) (r: (t1 -> t2 -> prop)) (l2: list t2)
: GTot (t1 -> bool) | val list_ghost_forall_exists_body (#t1 #t2: Type) (r: (t1 -> t2 -> prop)) (l2: list t2)
: GTot (t1 -> bool) | let list_ghost_forall_exists_body
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l2: list t2)
: GTot (t1 -> bool)
= Pull.pull (fun x1 -> List.Tot.existsb
(pull_rel r x1)
l2
) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 500,
"start_col": 0,
"start_line": 492
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *)
noextract
let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x
noextract
let map_group_equiv
#b
(mg1 mg2: map_group b)
: Tot prop
= forall x . matches_map_group mg1 x == matches_map_group mg2 x
noextract
let is_sub_typ_of
#b
(small large: bounded_typ_gen b)
: Tot prop
= forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x
noextract
let is_sub_map_group_entry_of
#b
(small large: map_group_entry b)
: Tot prop
= small.fst `is_sub_typ_of` large.fst /\
small.snd `is_sub_typ_of` large.snd
let map_group_ignore_restricted_entries
#b
(mg: map_group b)
: Tot (map_group b)
= {mg with
one = [];
zero_or_one = [];
}
let pull_rel
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(x1: t1)
: GTot ((x2: t2) -> Tot bool)
= Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: (_: t1 -> _: t2 -> Prims.prop) -> l2: Prims.list t2 -> Prims.GTot (_: t1 -> Prims.bool) | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.prop",
"Prims.list",
"FStar.Ghost.Pull.pull",
"Prims.bool",
"FStar.List.Tot.Base.existsb",
"CDDL.Spec.pull_rel"
] | [] | false | false | false | false | false | let list_ghost_forall_exists_body (#t1 #t2: Type) (r: (t1 -> t2 -> prop)) (l2: list t2)
: GTot (t1 -> bool) =
| Pull.pull (fun x1 -> List.Tot.existsb (pull_rel r x1) l2) | false |
CDDL.Spec.fsti | CDDL.Spec.array_group3 | val array_group3 : bound: FStar.Pervasives.Native.option CBOR.Spec.Type.raw_data_item -> Type0 | let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
)) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 4,
"end_line": 238,
"start_col": 0,
"start_line": 233
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | bound: FStar.Pervasives.Native.option CBOR.Spec.Type.raw_data_item -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"Prims.list",
"CDDL.Spec.opt_precedes",
"Prims.l_True"
] | [] | false | false | false | true | true | let array_group3 (bound: option Cbor.raw_data_item) =
| l: list Cbor.raw_data_item {opt_precedes l bound}
-> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures
(function
| None -> True
| Some l' -> opt_precedes l' bound)) | false |
|
CDDL.Spec.fsti | CDDL.Spec.list_ghost_forall_exists | val list_ghost_forall_exists (#t1 #t2: Type) (r: (t1 -> t2 -> prop)) (l1: list t1) (l2: list t2)
: GTot bool | val list_ghost_forall_exists (#t1 #t2: Type) (r: (t1 -> t2 -> prop)) (l1: list t1) (l2: list t2)
: GTot bool | let list_ghost_forall_exists
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l1: list t1)
(l2: list t2)
: GTot bool
= List.Tot.for_all
(list_ghost_forall_exists_body r l2)
l1 | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 6,
"end_line": 510,
"start_col": 0,
"start_line": 502
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *)
noextract
let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x
noextract
let map_group_equiv
#b
(mg1 mg2: map_group b)
: Tot prop
= forall x . matches_map_group mg1 x == matches_map_group mg2 x
noextract
let is_sub_typ_of
#b
(small large: bounded_typ_gen b)
: Tot prop
= forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x
noextract
let is_sub_map_group_entry_of
#b
(small large: map_group_entry b)
: Tot prop
= small.fst `is_sub_typ_of` large.fst /\
small.snd `is_sub_typ_of` large.snd
let map_group_ignore_restricted_entries
#b
(mg: map_group b)
: Tot (map_group b)
= {mg with
one = [];
zero_or_one = [];
}
let pull_rel
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(x1: t1)
: GTot ((x2: t2) -> Tot bool)
= Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2))
let list_ghost_forall_exists_body
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l2: list t2)
: GTot (t1 -> bool)
= Pull.pull (fun x1 -> List.Tot.existsb
(pull_rel r x1)
l2
) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: (_: t1 -> _: t2 -> Prims.prop) -> l1: Prims.list t1 -> l2: Prims.list t2 -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.prop",
"Prims.list",
"FStar.List.Tot.Base.for_all",
"CDDL.Spec.list_ghost_forall_exists_body",
"Prims.bool"
] | [] | false | false | false | false | false | let list_ghost_forall_exists (#t1 #t2: Type) (r: (t1 -> t2 -> prop)) (l1: list t1) (l2: list t2)
: GTot bool =
| List.Tot.for_all (list_ghost_forall_exists_body r l2) l1 | false |
CDDL.Spec.fsti | CDDL.Spec.map_group_included_zero_or_more | val map_group_included_zero_or_more (#b: _) (small large: map_group b) : GTot bool | val map_group_included_zero_or_more (#b: _) (small large: map_group b) : GTot bool | let map_group_included_zero_or_more
#b
(small large: map_group b)
: GTot bool
= list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more &&
Nil? large.one | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 16,
"end_line": 560,
"start_col": 0,
"start_line": 553
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *)
noextract
let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x
noextract
let map_group_equiv
#b
(mg1 mg2: map_group b)
: Tot prop
= forall x . matches_map_group mg1 x == matches_map_group mg2 x
noextract
let is_sub_typ_of
#b
(small large: bounded_typ_gen b)
: Tot prop
= forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x
noextract
let is_sub_map_group_entry_of
#b
(small large: map_group_entry b)
: Tot prop
= small.fst `is_sub_typ_of` large.fst /\
small.snd `is_sub_typ_of` large.snd
let map_group_ignore_restricted_entries
#b
(mg: map_group b)
: Tot (map_group b)
= {mg with
one = [];
zero_or_one = [];
}
let pull_rel
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(x1: t1)
: GTot ((x2: t2) -> Tot bool)
= Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2))
let list_ghost_forall_exists_body
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l2: list t2)
: GTot (t1 -> bool)
= Pull.pull (fun x1 -> List.Tot.existsb
(pull_rel r x1)
l2
)
let list_ghost_forall_exists
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l1: list t1)
(l2: list t2)
: GTot bool
= List.Tot.for_all
(list_ghost_forall_exists_body r l2)
l1
noextract
let matches_map_group_entry'
(#b: _)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
(y: map_group_entry b)
: Tot prop
= opt_map_entry_bounded b x ==> matches_map_group_entry y x
val matches_map_group_no_restricted
(#b: _)
(g: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(requires (
Nil? g.one /\
Nil? g.zero_or_one
))
(ensures (
matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more
))
[SMTPat (matches_map_group g x)]
let rec list_ghost_forall2
(#t1 #t2: Type)
(f: t1 -> t2 -> GTot prop)
(l1: list t1)
(l2: list t2)
: GTot bool
(decreases l1)
= match l1, l2 with
| [], [] -> true
| a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2
| _ -> false
val list_ghost_forall_exists_is_sub_map_group_entry_of_refl
(#b: _)
(l: list (map_group_entry b))
: Lemma
(ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l))
[SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | small: CDDL.Spec.map_group b -> large: CDDL.Spec.map_group b -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.map_group",
"Prims.op_AmpAmp",
"CDDL.Spec.list_ghost_forall_exists",
"CDDL.Spec.map_group_entry",
"CDDL.Spec.is_sub_map_group_entry_of",
"CDDL.Spec.__proj__Mkmap_group__item__one",
"CDDL.Spec.__proj__Mkmap_group__item__zero_or_more",
"CDDL.Spec.__proj__Mkmap_group__item__zero_or_one",
"Prims.uu___is_Nil",
"Prims.bool"
] | [] | false | false | false | false | false | let map_group_included_zero_or_more #b (small: map_group b) (large: map_group b) : GTot bool =
| list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more &&
Nil? large.one | false |
CDDL.Spec.fsti | CDDL.Spec.t_array3 | val t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b | val t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b | let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 40,
"end_line": 311,
"start_col": 0,
"start_line": 309
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: CDDL.Spec.array_group3 b -> CDDL.Spec.bounded_typ_gen b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.array_group3",
"CDDL.Spec.opt_precedes",
"Prims.op_AmpAmp",
"CBOR.Spec.Type.uu___is_Array",
"CDDL.Spec.match_array_group3",
"CBOR.Spec.Type.__proj__Array__item__v",
"Prims.bool",
"CDDL.Spec.bounded_typ_gen"
] | [] | false | false | false | false | false | let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b =
| fun x -> Cbor.Array? x && match_array_group3 a (Cbor.Array?.v x) | false |
CDDL.Spec.fsti | CDDL.Spec.array_group3_concat | val array_group3_concat (#b: _) (a1 a3: array_group3 b) : array_group3 b | val array_group3_concat (#b: _) (a1 a3: array_group3 b) : array_group3 b | let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 3,
"end_line": 254,
"start_col": 0,
"start_line": 249
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | a1: CDDL.Spec.array_group3 b -> a3: CDDL.Spec.array_group3 b -> CDDL.Spec.array_group3 b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.array_group3",
"Prims.list",
"CDDL.Spec.opt_precedes",
"FStar.Pervasives.Native.None"
] | [] | false | false | false | false | false | let array_group3_concat #b (a1: array_group3 b) (a3: array_group3 b) : array_group3 b =
| (fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3) | false |
CDDL.Spec.fsti | CDDL.Spec.pull_rel | val pull_rel (#t1 #t2: Type) (r: (t1 -> t2 -> prop)) (x1: t1) : GTot (x2: t2 -> Tot bool) | val pull_rel (#t1 #t2: Type) (r: (t1 -> t2 -> prop)) (x1: t1) : GTot (x2: t2 -> Tot bool) | let pull_rel
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(x1: t1)
: GTot ((x2: t2) -> Tot bool)
= Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 83,
"end_line": 490,
"start_col": 0,
"start_line": 485
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *)
noextract
let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x
noextract
let map_group_equiv
#b
(mg1 mg2: map_group b)
: Tot prop
= forall x . matches_map_group mg1 x == matches_map_group mg2 x
noextract
let is_sub_typ_of
#b
(small large: bounded_typ_gen b)
: Tot prop
= forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x
noextract
let is_sub_map_group_entry_of
#b
(small large: map_group_entry b)
: Tot prop
= small.fst `is_sub_typ_of` large.fst /\
small.snd `is_sub_typ_of` large.snd
let map_group_ignore_restricted_entries
#b
(mg: map_group b)
: Tot (map_group b)
= {mg with
one = [];
zero_or_one = [];
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: (_: t1 -> _: t2 -> Prims.prop) -> x1: t1 -> Prims.GTot (x2: t2 -> Prims.bool) | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.prop",
"FStar.Ghost.Pull.pull",
"Prims.bool",
"Prims.l_iff",
"Prims.b2t",
"Prims.op_Equality",
"FStar.StrongExcludedMiddle.strong_excluded_middle"
] | [] | false | false | false | false | false | let pull_rel (#t1 #t2: Type) (r: (t1 -> t2 -> prop)) (x1: t1) : GTot (x2: t2 -> Tot bool) =
| Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2)) | false |
CDDL.Spec.fsti | CDDL.Spec.matches_map_group_entry | val matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item){opt_map_entry_bounded b x == true})
: GTot bool | val matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item){opt_map_entry_bounded b x == true})
: GTot bool | let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 34,
"end_line": 375,
"start_col": 0,
"start_line": 370
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 |
ge: CDDL.Spec.map_group_entry b ->
x:
(CBOR.Spec.Type.raw_data_item * CBOR.Spec.Type.raw_data_item)
{CDDL.Spec.opt_map_entry_bounded b x == true}
-> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.map_group_entry",
"FStar.Pervasives.Native.tuple2",
"Prims.eq2",
"Prims.bool",
"CDDL.Spec.opt_map_entry_bounded",
"Prims.op_AmpAmp",
"CDDL.Spec.__proj__MapGroupEntry__item__fst",
"FStar.Pervasives.Native.fst",
"CDDL.Spec.__proj__MapGroupEntry__item__snd",
"FStar.Pervasives.Native.snd"
] | [] | false | false | false | false | false | let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item){opt_map_entry_bounded b x == true})
: GTot bool =
| ge.fst (fst x) && ge.snd (snd x) | false |
CDDL.Spec.fsti | CDDL.Spec.array_group3_always_false | val array_group3_always_false (#b: _) : array_group3 b | val array_group3_always_false (#b: _) : array_group3 b | let array_group3_always_false #b : array_group3 b = fun _ -> None | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 65,
"end_line": 247,
"start_col": 0,
"start_line": 247
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | CDDL.Spec.array_group3 b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"Prims.list",
"CDDL.Spec.opt_precedes",
"FStar.Pervasives.Native.None",
"CDDL.Spec.array_group3"
] | [] | false | false | false | false | false | let array_group3_always_false #b : array_group3 b =
| fun _ -> None | false |
CDDL.Spec.fsti | CDDL.Spec.opt_precedes_map_for_all_opt_map_entry_bounded | val opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma (requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] | val opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma (requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] | let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 64,
"end_line": 368,
"start_col": 0,
"start_line": 359
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: FStar.Pervasives.Native.option CBOR.Spec.Type.raw_data_item ->
l: Prims.list (CBOR.Spec.Type.raw_data_item * CBOR.Spec.Type.raw_data_item)
-> FStar.Pervasives.Lemma (requires CDDL.Spec.opt_precedes l b)
(ensures FStar.List.Tot.Base.for_all (CDDL.Spec.opt_map_entry_bounded b) l)
[SMTPat (FStar.List.Tot.Base.for_all (CDDL.Spec.opt_map_entry_bounded b) l)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"CDDL.Spec.opt_precedes_map_for_all_opt_map_entry_bounded",
"Prims.unit",
"CDDL.Spec.opt_precedes",
"Prims.squash",
"Prims.b2t",
"FStar.List.Tot.Base.for_all",
"CDDL.Spec.opt_map_entry_bounded",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.bool",
"Prims.Nil"
] | [
"recursion"
] | false | false | true | false | false | let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma (requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)] =
| match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q | false |
CDDL.Spec.fsti | CDDL.Spec.array_group3_zero_or_more' | val array_group3_zero_or_more'
(#b: _)
(a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures
(function
| None -> True
| Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l)) | val array_group3_zero_or_more'
(#b: _)
(a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures
(function
| None -> True
| Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l)) | let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l' | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 40,
"end_line": 279,
"start_col": 0,
"start_line": 269
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: CDDL.Spec.array_group3 b ->
l: Prims.list CBOR.Spec.Type.raw_data_item {CDDL.Spec.opt_precedes l b}
-> Prims.Ghost (FStar.Pervasives.Native.option (Prims.list CBOR.Spec.Type.raw_data_item)) | Prims.Ghost | [
""
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.array_group3",
"Prims.list",
"CDDL.Spec.opt_precedes",
"FStar.Pervasives.Native.Some",
"Prims.op_GreaterThanOrEqual",
"FStar.List.Tot.Base.length",
"Prims.bool",
"CDDL.Spec.array_group3_zero_or_more'",
"Prims.l_True"
] | [
"recursion"
] | false | false | false | false | false | let rec array_group3_zero_or_more'
#b
(a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures
(function
| None -> True
| Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l)) =
| match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l then Some l else array_group3_zero_or_more' a l' | false |
CDDL.Spec.fsti | CDDL.Spec.list_is_suffix_of_refl | val list_is_suffix_of_refl (#t: Type) (l: list t)
: Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] | val list_is_suffix_of_refl (#t: Type) (l: list t)
: Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] | let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 38,
"end_line": 197,
"start_col": 0,
"start_line": 191
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 t
-> FStar.Pervasives.Lemma (ensures CDDL.Spec.list_is_suffix_of l l)
[SMTPat (CDDL.Spec.list_is_suffix_of l l)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Prims._assert",
"Prims.eq2",
"FStar.List.Tot.Base.append",
"Prims.Nil",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"CDDL.Spec.list_is_suffix_of",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.prop"
] | [] | true | false | true | false | false | let list_is_suffix_of_refl (#t: Type) (l: list t)
: Lemma (l `list_is_suffix_of` l) [SMTPat (l `list_is_suffix_of` l)] =
| assert (l == [] `List.Tot.append` l) | false |
CDDL.Spec.fsti | CDDL.Spec.map_group_included_pointwise | val map_group_included_pointwise (#b: _) (small large: map_group b) : GTot bool | val map_group_included_pointwise (#b: _) (small large: map_group b) : GTot bool | let map_group_included_pointwise
#b
(small large: map_group b)
: GTot bool
= list_ghost_forall2 is_sub_map_group_entry_of small.one large.one &&
list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one &&
list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 84,
"end_line": 601,
"start_col": 0,
"start_line": 595
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *)
noextract
let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x
noextract
let map_group_equiv
#b
(mg1 mg2: map_group b)
: Tot prop
= forall x . matches_map_group mg1 x == matches_map_group mg2 x
noextract
let is_sub_typ_of
#b
(small large: bounded_typ_gen b)
: Tot prop
= forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x
noextract
let is_sub_map_group_entry_of
#b
(small large: map_group_entry b)
: Tot prop
= small.fst `is_sub_typ_of` large.fst /\
small.snd `is_sub_typ_of` large.snd
let map_group_ignore_restricted_entries
#b
(mg: map_group b)
: Tot (map_group b)
= {mg with
one = [];
zero_or_one = [];
}
let pull_rel
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(x1: t1)
: GTot ((x2: t2) -> Tot bool)
= Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2))
let list_ghost_forall_exists_body
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l2: list t2)
: GTot (t1 -> bool)
= Pull.pull (fun x1 -> List.Tot.existsb
(pull_rel r x1)
l2
)
let list_ghost_forall_exists
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l1: list t1)
(l2: list t2)
: GTot bool
= List.Tot.for_all
(list_ghost_forall_exists_body r l2)
l1
noextract
let matches_map_group_entry'
(#b: _)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
(y: map_group_entry b)
: Tot prop
= opt_map_entry_bounded b x ==> matches_map_group_entry y x
val matches_map_group_no_restricted
(#b: _)
(g: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(requires (
Nil? g.one /\
Nil? g.zero_or_one
))
(ensures (
matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more
))
[SMTPat (matches_map_group g x)]
let rec list_ghost_forall2
(#t1 #t2: Type)
(f: t1 -> t2 -> GTot prop)
(l1: list t1)
(l2: list t2)
: GTot bool
(decreases l1)
= match l1, l2 with
| [], [] -> true
| a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2
| _ -> false
val list_ghost_forall_exists_is_sub_map_group_entry_of_refl
(#b: _)
(l: list (map_group_entry b))
: Lemma
(ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l))
[SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)]
let map_group_included_zero_or_more
#b
(small large: map_group b)
: GTot bool
= list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more &&
Nil? large.one
val map_group_included_zero_or_more_correct
(#b: _)
(small large: map_group b)
: Lemma
(requires (map_group_included_zero_or_more small large))
(ensures (is_sub_map_group_of small large))
val map_group_ignore_restricted_entries_sub
(#b: _)
(mg: map_group b)
: Lemma
(requires (
list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more
))
(ensures (
mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg
))
let map_group_ignore_restricted_entries_no_one_equiv
#b
(mg: map_group b)
: Lemma
(requires (
Nil? mg.one /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more
))
(ensures (
map_group_equiv mg (map_group_ignore_restricted_entries mg)
))
= map_group_ignore_restricted_entries_sub mg;
map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | small: CDDL.Spec.map_group b -> large: CDDL.Spec.map_group b -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.map_group",
"Prims.op_AmpAmp",
"CDDL.Spec.list_ghost_forall2",
"CDDL.Spec.map_group_entry",
"CDDL.Spec.is_sub_map_group_entry_of",
"CDDL.Spec.__proj__Mkmap_group__item__one",
"CDDL.Spec.__proj__Mkmap_group__item__zero_or_one",
"CDDL.Spec.__proj__Mkmap_group__item__zero_or_more",
"Prims.bool"
] | [] | false | false | false | false | false | let map_group_included_pointwise #b (small: map_group b) (large: map_group b) : GTot bool =
| list_ghost_forall2 is_sub_map_group_entry_of small.one large.one &&
list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one &&
list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more | false |
CDDL.Spec.fsti | CDDL.Spec.map_key_neq' | val map_key_neq' (#t1 t2: Type) (k: t1) (x: (t1 & t2)) : GTot bool | val map_key_neq' (#t1 t2: Type) (k: t1) (x: (t1 & t2)) : GTot bool | let map_key_neq'
(#t1 t2: Type)
(k: t1)
(x: (t1 & t2))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (~ (fst x == k)) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 68,
"end_line": 665,
"start_col": 0,
"start_line": 660
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *)
noextract
let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x
noextract
let map_group_equiv
#b
(mg1 mg2: map_group b)
: Tot prop
= forall x . matches_map_group mg1 x == matches_map_group mg2 x
noextract
let is_sub_typ_of
#b
(small large: bounded_typ_gen b)
: Tot prop
= forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x
noextract
let is_sub_map_group_entry_of
#b
(small large: map_group_entry b)
: Tot prop
= small.fst `is_sub_typ_of` large.fst /\
small.snd `is_sub_typ_of` large.snd
let map_group_ignore_restricted_entries
#b
(mg: map_group b)
: Tot (map_group b)
= {mg with
one = [];
zero_or_one = [];
}
let pull_rel
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(x1: t1)
: GTot ((x2: t2) -> Tot bool)
= Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2))
let list_ghost_forall_exists_body
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l2: list t2)
: GTot (t1 -> bool)
= Pull.pull (fun x1 -> List.Tot.existsb
(pull_rel r x1)
l2
)
let list_ghost_forall_exists
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l1: list t1)
(l2: list t2)
: GTot bool
= List.Tot.for_all
(list_ghost_forall_exists_body r l2)
l1
noextract
let matches_map_group_entry'
(#b: _)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
(y: map_group_entry b)
: Tot prop
= opt_map_entry_bounded b x ==> matches_map_group_entry y x
val matches_map_group_no_restricted
(#b: _)
(g: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(requires (
Nil? g.one /\
Nil? g.zero_or_one
))
(ensures (
matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more
))
[SMTPat (matches_map_group g x)]
let rec list_ghost_forall2
(#t1 #t2: Type)
(f: t1 -> t2 -> GTot prop)
(l1: list t1)
(l2: list t2)
: GTot bool
(decreases l1)
= match l1, l2 with
| [], [] -> true
| a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2
| _ -> false
val list_ghost_forall_exists_is_sub_map_group_entry_of_refl
(#b: _)
(l: list (map_group_entry b))
: Lemma
(ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l))
[SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)]
let map_group_included_zero_or_more
#b
(small large: map_group b)
: GTot bool
= list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more &&
Nil? large.one
val map_group_included_zero_or_more_correct
(#b: _)
(small large: map_group b)
: Lemma
(requires (map_group_included_zero_or_more small large))
(ensures (is_sub_map_group_of small large))
val map_group_ignore_restricted_entries_sub
(#b: _)
(mg: map_group b)
: Lemma
(requires (
list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more
))
(ensures (
mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg
))
let map_group_ignore_restricted_entries_no_one_equiv
#b
(mg: map_group b)
: Lemma
(requires (
Nil? mg.one /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more
))
(ensures (
map_group_equiv mg (map_group_ignore_restricted_entries mg)
))
= map_group_ignore_restricted_entries_sub mg;
map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg
let map_group_included_pointwise
#b
(small large: map_group b)
: GTot bool
= list_ghost_forall2 is_sub_map_group_entry_of small.one large.one &&
list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one &&
list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more
val map_group_included_pointwise_correct
(#b: _)
(small large: map_group b)
: Lemma
(requires (map_group_included_pointwise small large))
(ensures (is_sub_map_group_of small large))
let rec list_ghost_forall2_map_l
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(f: t2 -> t1)
(l: list t2)
: Lemma
(requires (forall x . r (f x) x))
(ensures (list_ghost_forall2 r (List.Tot.map f l) l))
= match l with
| [] -> ()
| _ :: q -> list_ghost_forall2_map_l r f q
let rec list_ghost_forall2_map_r
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(f: t1 -> t2)
(l: list t1)
: Lemma
(requires (forall x . r x (f x)))
(ensures (list_ghost_forall2 r l (List.Tot.map f l)))
= match l with
| [] -> ()
| _ :: q -> list_ghost_forall2_map_r r f q
let cut_map_group_sub
#b
(key: bounded_typ_gen b)
(mg: map_group b)
: Lemma
(cut_map_group key mg `is_sub_map_group_of` mg)
= list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one;
list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one;
list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more;
map_group_included_pointwise_correct (cut_map_group key mg) mg
(* Proving matches_map_group for sorted maps and map groups where key constraints specify whole elements *)
let rec list_for_all_filter_invariant
(#t: Type)
(p: t -> bool)
(f: t -> bool)
(l: list t)
: Lemma
(requires (List.Tot.for_all p l == true))
(ensures (List.Tot.for_all p (List.Tot.filter f l) == true))
[SMTPat (List.Tot.for_all p (List.Tot.filter f l))]
= match l with
| [] -> ()
| _ :: q -> list_for_all_filter_invariant p f q | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | t2: Type -> k: t1 -> x: (t1 * t2) -> Prims.GTot Prims.bool | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"FStar.StrongExcludedMiddle.strong_excluded_middle",
"Prims.l_not",
"Prims.eq2",
"FStar.Pervasives.Native.fst",
"Prims.bool"
] | [] | false | false | false | false | false | let map_key_neq' (#t1 t2: Type) (k: t1) (x: (t1 & t2)) : GTot bool =
| FStar.StrongExcludedMiddle.strong_excluded_middle (~(fst x == k)) | false |
CDDL.Spec.fsti | CDDL.Spec.map_key_neq | val map_key_neq (#t1 t2: Type) (k: t1) : GTot ((t1 & t2) -> bool) | val map_key_neq (#t1 t2: Type) (k: t1) : GTot ((t1 & t2) -> bool) | let map_key_neq
(#t1 t2: Type)
(k: t1)
: GTot ((t1 & t2) -> bool)
= Pull.pull (map_key_neq' t2 k) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 31,
"end_line": 671,
"start_col": 0,
"start_line": 667
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *)
noextract
let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x
noextract
let map_group_equiv
#b
(mg1 mg2: map_group b)
: Tot prop
= forall x . matches_map_group mg1 x == matches_map_group mg2 x
noextract
let is_sub_typ_of
#b
(small large: bounded_typ_gen b)
: Tot prop
= forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x
noextract
let is_sub_map_group_entry_of
#b
(small large: map_group_entry b)
: Tot prop
= small.fst `is_sub_typ_of` large.fst /\
small.snd `is_sub_typ_of` large.snd
let map_group_ignore_restricted_entries
#b
(mg: map_group b)
: Tot (map_group b)
= {mg with
one = [];
zero_or_one = [];
}
let pull_rel
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(x1: t1)
: GTot ((x2: t2) -> Tot bool)
= Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2))
let list_ghost_forall_exists_body
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l2: list t2)
: GTot (t1 -> bool)
= Pull.pull (fun x1 -> List.Tot.existsb
(pull_rel r x1)
l2
)
let list_ghost_forall_exists
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l1: list t1)
(l2: list t2)
: GTot bool
= List.Tot.for_all
(list_ghost_forall_exists_body r l2)
l1
noextract
let matches_map_group_entry'
(#b: _)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
(y: map_group_entry b)
: Tot prop
= opt_map_entry_bounded b x ==> matches_map_group_entry y x
val matches_map_group_no_restricted
(#b: _)
(g: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(requires (
Nil? g.one /\
Nil? g.zero_or_one
))
(ensures (
matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more
))
[SMTPat (matches_map_group g x)]
let rec list_ghost_forall2
(#t1 #t2: Type)
(f: t1 -> t2 -> GTot prop)
(l1: list t1)
(l2: list t2)
: GTot bool
(decreases l1)
= match l1, l2 with
| [], [] -> true
| a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2
| _ -> false
val list_ghost_forall_exists_is_sub_map_group_entry_of_refl
(#b: _)
(l: list (map_group_entry b))
: Lemma
(ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l))
[SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)]
let map_group_included_zero_or_more
#b
(small large: map_group b)
: GTot bool
= list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more &&
Nil? large.one
val map_group_included_zero_or_more_correct
(#b: _)
(small large: map_group b)
: Lemma
(requires (map_group_included_zero_or_more small large))
(ensures (is_sub_map_group_of small large))
val map_group_ignore_restricted_entries_sub
(#b: _)
(mg: map_group b)
: Lemma
(requires (
list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more
))
(ensures (
mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg
))
let map_group_ignore_restricted_entries_no_one_equiv
#b
(mg: map_group b)
: Lemma
(requires (
Nil? mg.one /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more
))
(ensures (
map_group_equiv mg (map_group_ignore_restricted_entries mg)
))
= map_group_ignore_restricted_entries_sub mg;
map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg
let map_group_included_pointwise
#b
(small large: map_group b)
: GTot bool
= list_ghost_forall2 is_sub_map_group_entry_of small.one large.one &&
list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one &&
list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more
val map_group_included_pointwise_correct
(#b: _)
(small large: map_group b)
: Lemma
(requires (map_group_included_pointwise small large))
(ensures (is_sub_map_group_of small large))
let rec list_ghost_forall2_map_l
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(f: t2 -> t1)
(l: list t2)
: Lemma
(requires (forall x . r (f x) x))
(ensures (list_ghost_forall2 r (List.Tot.map f l) l))
= match l with
| [] -> ()
| _ :: q -> list_ghost_forall2_map_l r f q
let rec list_ghost_forall2_map_r
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(f: t1 -> t2)
(l: list t1)
: Lemma
(requires (forall x . r x (f x)))
(ensures (list_ghost_forall2 r l (List.Tot.map f l)))
= match l with
| [] -> ()
| _ :: q -> list_ghost_forall2_map_r r f q
let cut_map_group_sub
#b
(key: bounded_typ_gen b)
(mg: map_group b)
: Lemma
(cut_map_group key mg `is_sub_map_group_of` mg)
= list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one;
list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one;
list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more;
map_group_included_pointwise_correct (cut_map_group key mg) mg
(* Proving matches_map_group for sorted maps and map groups where key constraints specify whole elements *)
let rec list_for_all_filter_invariant
(#t: Type)
(p: t -> bool)
(f: t -> bool)
(l: list t)
: Lemma
(requires (List.Tot.for_all p l == true))
(ensures (List.Tot.for_all p (List.Tot.filter f l) == true))
[SMTPat (List.Tot.for_all p (List.Tot.filter f l))]
= match l with
| [] -> ()
| _ :: q -> list_for_all_filter_invariant p f q
let map_key_neq'
(#t1 t2: Type)
(k: t1)
(x: (t1 & t2))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (~ (fst x == k)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | t2: Type -> k: t1 -> Prims.GTot (_: (t1 * t2) -> Prims.bool) | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Ghost.Pull.pull",
"FStar.Pervasives.Native.tuple2",
"Prims.bool",
"CDDL.Spec.map_key_neq'"
] | [] | false | false | false | false | false | let map_key_neq (#t1 t2: Type) (k: t1) : GTot ((t1 & t2) -> bool) =
| Pull.pull (map_key_neq' t2 k) | false |
CDDL.Spec.fsti | CDDL.Spec.string64 | val string64 : Type0 | let string64 = (s: Seq.seq U8.t {FStar.UInt.fits (Seq.length s) 64}) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 68,
"end_line": 784,
"start_col": 0,
"start_line": 784
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *)
noextract
let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x
noextract
let map_group_equiv
#b
(mg1 mg2: map_group b)
: Tot prop
= forall x . matches_map_group mg1 x == matches_map_group mg2 x
noextract
let is_sub_typ_of
#b
(small large: bounded_typ_gen b)
: Tot prop
= forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x
noextract
let is_sub_map_group_entry_of
#b
(small large: map_group_entry b)
: Tot prop
= small.fst `is_sub_typ_of` large.fst /\
small.snd `is_sub_typ_of` large.snd
let map_group_ignore_restricted_entries
#b
(mg: map_group b)
: Tot (map_group b)
= {mg with
one = [];
zero_or_one = [];
}
let pull_rel
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(x1: t1)
: GTot ((x2: t2) -> Tot bool)
= Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2))
let list_ghost_forall_exists_body
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l2: list t2)
: GTot (t1 -> bool)
= Pull.pull (fun x1 -> List.Tot.existsb
(pull_rel r x1)
l2
)
let list_ghost_forall_exists
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l1: list t1)
(l2: list t2)
: GTot bool
= List.Tot.for_all
(list_ghost_forall_exists_body r l2)
l1
noextract
let matches_map_group_entry'
(#b: _)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
(y: map_group_entry b)
: Tot prop
= opt_map_entry_bounded b x ==> matches_map_group_entry y x
val matches_map_group_no_restricted
(#b: _)
(g: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(requires (
Nil? g.one /\
Nil? g.zero_or_one
))
(ensures (
matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more
))
[SMTPat (matches_map_group g x)]
let rec list_ghost_forall2
(#t1 #t2: Type)
(f: t1 -> t2 -> GTot prop)
(l1: list t1)
(l2: list t2)
: GTot bool
(decreases l1)
= match l1, l2 with
| [], [] -> true
| a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2
| _ -> false
val list_ghost_forall_exists_is_sub_map_group_entry_of_refl
(#b: _)
(l: list (map_group_entry b))
: Lemma
(ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l))
[SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)]
let map_group_included_zero_or_more
#b
(small large: map_group b)
: GTot bool
= list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more &&
Nil? large.one
val map_group_included_zero_or_more_correct
(#b: _)
(small large: map_group b)
: Lemma
(requires (map_group_included_zero_or_more small large))
(ensures (is_sub_map_group_of small large))
val map_group_ignore_restricted_entries_sub
(#b: _)
(mg: map_group b)
: Lemma
(requires (
list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more
))
(ensures (
mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg
))
let map_group_ignore_restricted_entries_no_one_equiv
#b
(mg: map_group b)
: Lemma
(requires (
Nil? mg.one /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more
))
(ensures (
map_group_equiv mg (map_group_ignore_restricted_entries mg)
))
= map_group_ignore_restricted_entries_sub mg;
map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg
let map_group_included_pointwise
#b
(small large: map_group b)
: GTot bool
= list_ghost_forall2 is_sub_map_group_entry_of small.one large.one &&
list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one &&
list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more
val map_group_included_pointwise_correct
(#b: _)
(small large: map_group b)
: Lemma
(requires (map_group_included_pointwise small large))
(ensures (is_sub_map_group_of small large))
let rec list_ghost_forall2_map_l
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(f: t2 -> t1)
(l: list t2)
: Lemma
(requires (forall x . r (f x) x))
(ensures (list_ghost_forall2 r (List.Tot.map f l) l))
= match l with
| [] -> ()
| _ :: q -> list_ghost_forall2_map_l r f q
let rec list_ghost_forall2_map_r
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(f: t1 -> t2)
(l: list t1)
: Lemma
(requires (forall x . r x (f x)))
(ensures (list_ghost_forall2 r l (List.Tot.map f l)))
= match l with
| [] -> ()
| _ :: q -> list_ghost_forall2_map_r r f q
let cut_map_group_sub
#b
(key: bounded_typ_gen b)
(mg: map_group b)
: Lemma
(cut_map_group key mg `is_sub_map_group_of` mg)
= list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one;
list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one;
list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more;
map_group_included_pointwise_correct (cut_map_group key mg) mg
(* Proving matches_map_group for sorted maps and map groups where key constraints specify whole elements *)
let rec list_for_all_filter_invariant
(#t: Type)
(p: t -> bool)
(f: t -> bool)
(l: list t)
: Lemma
(requires (List.Tot.for_all p l == true))
(ensures (List.Tot.for_all p (List.Tot.filter f l) == true))
[SMTPat (List.Tot.for_all p (List.Tot.filter f l))]
= match l with
| [] -> ()
| _ :: q -> list_for_all_filter_invariant p f q
let map_key_neq'
(#t1 t2: Type)
(k: t1)
(x: (t1 & t2))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (~ (fst x == k))
let map_key_neq
(#t1 t2: Type)
(k: t1)
: GTot ((t1 & t2) -> bool)
= Pull.pull (map_key_neq' t2 k)
let map_group_entry_for
#b
(k: Cbor.raw_data_item)
(ty: bounded_typ_gen b)
: Tot (map_group_entry b)
= MapGroupEntry (coerce_to_bounded_typ _ (t_literal k)) ty
let rec list_ghost_assoc_for_all
(#key: Type)
(#value: Type)
(p: (key & value) -> bool)
(k: key)
(m: list (key & value))
: Lemma
(requires (List.Tot.for_all p m == true))
(ensures (match Cbor.list_ghost_assoc k m with
| None -> True
| Some y -> p (k, y)
))
(decreases m)
[SMTPat (List.Tot.for_all p m); SMTPat (Cbor.list_ghost_assoc k m)]
= match m with
| [] -> ()
| (k', _) :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_for_all p k m'
let rec list_assoc_none_for_all_map_key_neq
(k: Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (None? (Cbor.list_ghost_assoc k l)))
(ensures (List.Tot.for_all (map_key_neq _ k) l == true))
= match l with
| [] -> ()
| _ :: q -> list_assoc_none_for_all_map_key_neq k q
val matches_map_group_map_group_cons_zero_or_one_no_repeats
(#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(requires (List.Tot.no_repeats_p (List.Tot.map fst x)))
(ensures (
begin match Cbor.list_ghost_assoc k x with
| None -> True
| Some y -> opt_precedes y b
end /\
matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x ==
begin match Cbor.list_ghost_assoc k x with
| None -> matches_map_group g x
| Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x)
end
))
val matches_map_group_map_group_cons_one_no_repeats
(#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(requires (List.Tot.no_repeats_p (List.Tot.map fst x)))
(ensures (
begin match Cbor.list_ghost_assoc k x with
| None -> True
| Some y -> opt_precedes y b
end /\
matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x ==
begin match Cbor.list_ghost_assoc k x with
| None -> false
| Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x)
end
))
val matches_map_group_map_group_cons_zero_or_one_deterministically_encoded_cbor_map_key_order
(#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x))
(ensures (
begin match Cbor.list_ghost_assoc k x with
| None -> True
| Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x)
end /\
matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x ==
begin match Cbor.list_ghost_assoc k x with
| None -> matches_map_group g x
| Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x)
end
))
[SMTPat (matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x)]
val matches_map_group_map_group_cons_one_deterministically_encoded_cbor_map_key_order
(#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x))
(ensures (
begin match Cbor.list_ghost_assoc k x with
| None -> True
| Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x)
end /\
matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x ==
begin match Cbor.list_ghost_assoc k x with
| None -> false
| Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x)
end
))
[SMTPat (matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x)]
// 2.1 specifies "names that turn into the map key text string" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Seq.Base.seq",
"FStar.UInt8.t",
"Prims.b2t",
"FStar.UInt.fits",
"FStar.Seq.Base.length"
] | [] | false | false | false | true | true | let string64 =
| (s: Seq.seq U8.t {FStar.UInt.fits (Seq.length s) 64}) | false |
|
CDDL.Spec.fsti | CDDL.Spec.map_group_entry_for | val map_group_entry_for (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b)
: Tot (map_group_entry b) | val map_group_entry_for (#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b)
: Tot (map_group_entry b) | let map_group_entry_for
#b
(k: Cbor.raw_data_item)
(ty: bounded_typ_gen b)
: Tot (map_group_entry b)
= MapGroupEntry (coerce_to_bounded_typ _ (t_literal k)) ty | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 58,
"end_line": 678,
"start_col": 0,
"start_line": 673
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *)
noextract
let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x
noextract
let map_group_equiv
#b
(mg1 mg2: map_group b)
: Tot prop
= forall x . matches_map_group mg1 x == matches_map_group mg2 x
noextract
let is_sub_typ_of
#b
(small large: bounded_typ_gen b)
: Tot prop
= forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x
noextract
let is_sub_map_group_entry_of
#b
(small large: map_group_entry b)
: Tot prop
= small.fst `is_sub_typ_of` large.fst /\
small.snd `is_sub_typ_of` large.snd
let map_group_ignore_restricted_entries
#b
(mg: map_group b)
: Tot (map_group b)
= {mg with
one = [];
zero_or_one = [];
}
let pull_rel
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(x1: t1)
: GTot ((x2: t2) -> Tot bool)
= Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2))
let list_ghost_forall_exists_body
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l2: list t2)
: GTot (t1 -> bool)
= Pull.pull (fun x1 -> List.Tot.existsb
(pull_rel r x1)
l2
)
let list_ghost_forall_exists
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l1: list t1)
(l2: list t2)
: GTot bool
= List.Tot.for_all
(list_ghost_forall_exists_body r l2)
l1
noextract
let matches_map_group_entry'
(#b: _)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
(y: map_group_entry b)
: Tot prop
= opt_map_entry_bounded b x ==> matches_map_group_entry y x
val matches_map_group_no_restricted
(#b: _)
(g: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(requires (
Nil? g.one /\
Nil? g.zero_or_one
))
(ensures (
matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more
))
[SMTPat (matches_map_group g x)]
let rec list_ghost_forall2
(#t1 #t2: Type)
(f: t1 -> t2 -> GTot prop)
(l1: list t1)
(l2: list t2)
: GTot bool
(decreases l1)
= match l1, l2 with
| [], [] -> true
| a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2
| _ -> false
val list_ghost_forall_exists_is_sub_map_group_entry_of_refl
(#b: _)
(l: list (map_group_entry b))
: Lemma
(ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l))
[SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)]
let map_group_included_zero_or_more
#b
(small large: map_group b)
: GTot bool
= list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more &&
Nil? large.one
val map_group_included_zero_or_more_correct
(#b: _)
(small large: map_group b)
: Lemma
(requires (map_group_included_zero_or_more small large))
(ensures (is_sub_map_group_of small large))
val map_group_ignore_restricted_entries_sub
(#b: _)
(mg: map_group b)
: Lemma
(requires (
list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more
))
(ensures (
mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg
))
let map_group_ignore_restricted_entries_no_one_equiv
#b
(mg: map_group b)
: Lemma
(requires (
Nil? mg.one /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more
))
(ensures (
map_group_equiv mg (map_group_ignore_restricted_entries mg)
))
= map_group_ignore_restricted_entries_sub mg;
map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg
let map_group_included_pointwise
#b
(small large: map_group b)
: GTot bool
= list_ghost_forall2 is_sub_map_group_entry_of small.one large.one &&
list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one &&
list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more
val map_group_included_pointwise_correct
(#b: _)
(small large: map_group b)
: Lemma
(requires (map_group_included_pointwise small large))
(ensures (is_sub_map_group_of small large))
let rec list_ghost_forall2_map_l
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(f: t2 -> t1)
(l: list t2)
: Lemma
(requires (forall x . r (f x) x))
(ensures (list_ghost_forall2 r (List.Tot.map f l) l))
= match l with
| [] -> ()
| _ :: q -> list_ghost_forall2_map_l r f q
let rec list_ghost_forall2_map_r
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(f: t1 -> t2)
(l: list t1)
: Lemma
(requires (forall x . r x (f x)))
(ensures (list_ghost_forall2 r l (List.Tot.map f l)))
= match l with
| [] -> ()
| _ :: q -> list_ghost_forall2_map_r r f q
let cut_map_group_sub
#b
(key: bounded_typ_gen b)
(mg: map_group b)
: Lemma
(cut_map_group key mg `is_sub_map_group_of` mg)
= list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one;
list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one;
list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more;
map_group_included_pointwise_correct (cut_map_group key mg) mg
(* Proving matches_map_group for sorted maps and map groups where key constraints specify whole elements *)
let rec list_for_all_filter_invariant
(#t: Type)
(p: t -> bool)
(f: t -> bool)
(l: list t)
: Lemma
(requires (List.Tot.for_all p l == true))
(ensures (List.Tot.for_all p (List.Tot.filter f l) == true))
[SMTPat (List.Tot.for_all p (List.Tot.filter f l))]
= match l with
| [] -> ()
| _ :: q -> list_for_all_filter_invariant p f q
let map_key_neq'
(#t1 t2: Type)
(k: t1)
(x: (t1 & t2))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (~ (fst x == k))
let map_key_neq
(#t1 t2: Type)
(k: t1)
: GTot ((t1 & t2) -> bool)
= Pull.pull (map_key_neq' t2 k) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: CBOR.Spec.Type.raw_data_item -> ty: CDDL.Spec.bounded_typ_gen b -> CDDL.Spec.map_group_entry b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.bounded_typ_gen",
"CDDL.Spec.MapGroupEntry",
"CDDL.Spec.coerce_to_bounded_typ",
"CDDL.Spec.t_literal",
"CDDL.Spec.map_group_entry"
] | [] | false | false | false | false | false | let map_group_entry_for #b (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) : Tot (map_group_entry b) =
| MapGroupEntry (coerce_to_bounded_typ _ (t_literal k)) ty | false |
CDDL.Spec.fsti | CDDL.Spec.array_group3_item | val array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b | val array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b | let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 42,
"end_line": 292,
"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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: CDDL.Spec.bounded_typ_gen b -> CDDL.Spec.array_group3 b | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.bounded_typ_gen",
"Prims.list",
"CDDL.Spec.opt_precedes",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.Some",
"Prims.bool",
"CDDL.Spec.array_group3"
] | [] | false | false | false | false | false | let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b =
| function
| [] -> None
| a :: q -> if t a then Some q else None | false |
CDDL.Spec.fsti | CDDL.Spec.is_sub_map_group_of | val is_sub_map_group_of (#b: _) (small large: map_group b) : Tot prop | val is_sub_map_group_of (#b: _) (small large: map_group b) : Tot prop | let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 68,
"end_line": 452,
"start_col": 0,
"start_line": 448
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | small: CDDL.Spec.map_group b -> large: CDDL.Spec.map_group b -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.map_group",
"Prims.l_Forall",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.l_and",
"Prims.b2t",
"FStar.List.Tot.Base.for_all",
"CDDL.Spec.opt_map_entry_bounded",
"Prims.l_imp",
"CDDL.Spec.matches_map_group",
"Prims.prop"
] | [] | false | false | false | false | true | let is_sub_map_group_of #b (small: map_group b) (large: map_group b) : Tot prop =
| forall x. matches_map_group small x ==> matches_map_group large x | false |
CDDL.Spec.fsti | CDDL.Spec.name_as_text_string | val name_as_text_string (s: string64) : typ | val name_as_text_string (s: string64) : typ | let name_as_text_string (s: string64) : typ =
t_literal (Cbor.String Cbor.cbor_major_type_text_string s) | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 60,
"end_line": 787,
"start_col": 0,
"start_line": 786
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *)
noextract
let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x
noextract
let map_group_equiv
#b
(mg1 mg2: map_group b)
: Tot prop
= forall x . matches_map_group mg1 x == matches_map_group mg2 x
noextract
let is_sub_typ_of
#b
(small large: bounded_typ_gen b)
: Tot prop
= forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x
noextract
let is_sub_map_group_entry_of
#b
(small large: map_group_entry b)
: Tot prop
= small.fst `is_sub_typ_of` large.fst /\
small.snd `is_sub_typ_of` large.snd
let map_group_ignore_restricted_entries
#b
(mg: map_group b)
: Tot (map_group b)
= {mg with
one = [];
zero_or_one = [];
}
let pull_rel
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(x1: t1)
: GTot ((x2: t2) -> Tot bool)
= Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2))
let list_ghost_forall_exists_body
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l2: list t2)
: GTot (t1 -> bool)
= Pull.pull (fun x1 -> List.Tot.existsb
(pull_rel r x1)
l2
)
let list_ghost_forall_exists
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l1: list t1)
(l2: list t2)
: GTot bool
= List.Tot.for_all
(list_ghost_forall_exists_body r l2)
l1
noextract
let matches_map_group_entry'
(#b: _)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
(y: map_group_entry b)
: Tot prop
= opt_map_entry_bounded b x ==> matches_map_group_entry y x
val matches_map_group_no_restricted
(#b: _)
(g: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(requires (
Nil? g.one /\
Nil? g.zero_or_one
))
(ensures (
matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more
))
[SMTPat (matches_map_group g x)]
let rec list_ghost_forall2
(#t1 #t2: Type)
(f: t1 -> t2 -> GTot prop)
(l1: list t1)
(l2: list t2)
: GTot bool
(decreases l1)
= match l1, l2 with
| [], [] -> true
| a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2
| _ -> false
val list_ghost_forall_exists_is_sub_map_group_entry_of_refl
(#b: _)
(l: list (map_group_entry b))
: Lemma
(ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l))
[SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)]
let map_group_included_zero_or_more
#b
(small large: map_group b)
: GTot bool
= list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more &&
Nil? large.one
val map_group_included_zero_or_more_correct
(#b: _)
(small large: map_group b)
: Lemma
(requires (map_group_included_zero_or_more small large))
(ensures (is_sub_map_group_of small large))
val map_group_ignore_restricted_entries_sub
(#b: _)
(mg: map_group b)
: Lemma
(requires (
list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more
))
(ensures (
mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg
))
let map_group_ignore_restricted_entries_no_one_equiv
#b
(mg: map_group b)
: Lemma
(requires (
Nil? mg.one /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more
))
(ensures (
map_group_equiv mg (map_group_ignore_restricted_entries mg)
))
= map_group_ignore_restricted_entries_sub mg;
map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg
let map_group_included_pointwise
#b
(small large: map_group b)
: GTot bool
= list_ghost_forall2 is_sub_map_group_entry_of small.one large.one &&
list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_one large.zero_or_one &&
list_ghost_forall2 is_sub_map_group_entry_of small.zero_or_more large.zero_or_more
val map_group_included_pointwise_correct
(#b: _)
(small large: map_group b)
: Lemma
(requires (map_group_included_pointwise small large))
(ensures (is_sub_map_group_of small large))
let rec list_ghost_forall2_map_l
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(f: t2 -> t1)
(l: list t2)
: Lemma
(requires (forall x . r (f x) x))
(ensures (list_ghost_forall2 r (List.Tot.map f l) l))
= match l with
| [] -> ()
| _ :: q -> list_ghost_forall2_map_l r f q
let rec list_ghost_forall2_map_r
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(f: t1 -> t2)
(l: list t1)
: Lemma
(requires (forall x . r x (f x)))
(ensures (list_ghost_forall2 r l (List.Tot.map f l)))
= match l with
| [] -> ()
| _ :: q -> list_ghost_forall2_map_r r f q
let cut_map_group_sub
#b
(key: bounded_typ_gen b)
(mg: map_group b)
: Lemma
(cut_map_group key mg `is_sub_map_group_of` mg)
= list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.one;
list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_one;
list_ghost_forall2_map_l is_sub_map_group_entry_of (cut_map_group_entry key) mg.zero_or_more;
map_group_included_pointwise_correct (cut_map_group key mg) mg
(* Proving matches_map_group for sorted maps and map groups where key constraints specify whole elements *)
let rec list_for_all_filter_invariant
(#t: Type)
(p: t -> bool)
(f: t -> bool)
(l: list t)
: Lemma
(requires (List.Tot.for_all p l == true))
(ensures (List.Tot.for_all p (List.Tot.filter f l) == true))
[SMTPat (List.Tot.for_all p (List.Tot.filter f l))]
= match l with
| [] -> ()
| _ :: q -> list_for_all_filter_invariant p f q
let map_key_neq'
(#t1 t2: Type)
(k: t1)
(x: (t1 & t2))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (~ (fst x == k))
let map_key_neq
(#t1 t2: Type)
(k: t1)
: GTot ((t1 & t2) -> bool)
= Pull.pull (map_key_neq' t2 k)
let map_group_entry_for
#b
(k: Cbor.raw_data_item)
(ty: bounded_typ_gen b)
: Tot (map_group_entry b)
= MapGroupEntry (coerce_to_bounded_typ _ (t_literal k)) ty
let rec list_ghost_assoc_for_all
(#key: Type)
(#value: Type)
(p: (key & value) -> bool)
(k: key)
(m: list (key & value))
: Lemma
(requires (List.Tot.for_all p m == true))
(ensures (match Cbor.list_ghost_assoc k m with
| None -> True
| Some y -> p (k, y)
))
(decreases m)
[SMTPat (List.Tot.for_all p m); SMTPat (Cbor.list_ghost_assoc k m)]
= match m with
| [] -> ()
| (k', _) :: m' ->
if FStar.StrongExcludedMiddle.strong_excluded_middle (k == k')
then ()
else list_ghost_assoc_for_all p k m'
let rec list_assoc_none_for_all_map_key_neq
(k: Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (None? (Cbor.list_ghost_assoc k l)))
(ensures (List.Tot.for_all (map_key_neq _ k) l == true))
= match l with
| [] -> ()
| _ :: q -> list_assoc_none_for_all_map_key_neq k q
val matches_map_group_map_group_cons_zero_or_one_no_repeats
(#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(requires (List.Tot.no_repeats_p (List.Tot.map fst x)))
(ensures (
begin match Cbor.list_ghost_assoc k x with
| None -> True
| Some y -> opt_precedes y b
end /\
matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x ==
begin match Cbor.list_ghost_assoc k x with
| None -> matches_map_group g x
| Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x)
end
))
val matches_map_group_map_group_cons_one_no_repeats
(#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(requires (List.Tot.no_repeats_p (List.Tot.map fst x)))
(ensures (
begin match Cbor.list_ghost_assoc k x with
| None -> True
| Some y -> opt_precedes y b
end /\
matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x ==
begin match Cbor.list_ghost_assoc k x with
| None -> false
| Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x)
end
))
val matches_map_group_map_group_cons_zero_or_one_deterministically_encoded_cbor_map_key_order
(#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x))
(ensures (
begin match Cbor.list_ghost_assoc k x with
| None -> True
| Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x)
end /\
matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x ==
begin match Cbor.list_ghost_assoc k x with
| None -> matches_map_group g x
| Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x)
end
))
[SMTPat (matches_map_group (map_group_cons_zero_or_one (map_group_entry_for k ty) true g) x)]
val matches_map_group_map_group_cons_one_deterministically_encoded_cbor_map_key_order
(#b: _) (k: Cbor.raw_data_item) (ty: bounded_typ_gen b) (g: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(requires (List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) x))
(ensures (
begin match Cbor.list_ghost_assoc k x with
| None -> True
| Some y -> opt_precedes y b /\ List.Tot.sorted (Cbor.map_entry_order Cbor.deterministically_encoded_cbor_map_key_order _) (List.Tot.filter (map_key_neq _ k) x)
end /\
matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x ==
begin match Cbor.list_ghost_assoc k x with
| None -> false
| Some y -> ty y && matches_map_group g (List.Tot.filter (map_key_neq _ k) x)
end
))
[SMTPat (matches_map_group (map_group_cons_one (map_group_entry_for k ty) true g) x)]
// 2.1 specifies "names that turn into the map key text string"
noextract
let string64 = (s: Seq.seq U8.t {FStar.UInt.fits (Seq.length s) 64}) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: CDDL.Spec.string64 -> CDDL.Spec.typ | Prims.Tot | [
"total"
] | [] | [
"CDDL.Spec.string64",
"CDDL.Spec.t_literal",
"CBOR.Spec.Type.String",
"CBOR.Spec.Constants.cbor_major_type_text_string",
"CDDL.Spec.typ"
] | [] | false | false | false | true | false | let name_as_text_string (s: string64) : typ =
| t_literal (Cbor.String Cbor.cbor_major_type_text_string s) | false |
CDDL.Spec.fsti | CDDL.Spec.map_group_equiv | val map_group_equiv (#b: _) (mg1 mg2: map_group b) : Tot prop | val map_group_equiv (#b: _) (mg1 mg2: map_group b) : Tot prop | let map_group_equiv
#b
(mg1 mg2: map_group b)
: Tot prop
= forall x . matches_map_group mg1 x == matches_map_group mg2 x | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 63,
"end_line": 459,
"start_col": 0,
"start_line": 455
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *)
noextract
let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | mg1: CDDL.Spec.map_group b -> mg2: CDDL.Spec.map_group b -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.map_group",
"Prims.l_Forall",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.l_and",
"Prims.b2t",
"FStar.List.Tot.Base.for_all",
"CDDL.Spec.opt_map_entry_bounded",
"Prims.eq2",
"Prims.bool",
"CDDL.Spec.matches_map_group",
"Prims.prop"
] | [] | false | false | false | false | true | let map_group_equiv #b (mg1: map_group b) (mg2: map_group b) : Tot prop =
| forall x. matches_map_group mg1 x == matches_map_group mg2 x | false |
FStar.Int.fsti | FStar.Int.fits | val fits (x: int) (n: pos) : Tot bool | val fits (x: int) (n: pos) : Tot bool | let fits (x:int) (n:pos) : Tot bool = min_int n <= x && x <= max_int n | {
"file_name": "ulib/FStar.Int.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 70,
"end_line": 44,
"start_col": 0,
"start_line": 44
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
val pow2_values: x:nat -> Lemma
(let p = pow2 x in
match x with
| 0 -> p=1
| 1 -> p=2
| 8 -> p=256
| 16 -> p=65536
| 31 -> p=2147483648
| 32 -> p=4294967296
| 63 -> p=9223372036854775808
| 64 -> p=18446744073709551616
| _ -> True)
[SMTPat (pow2 x)]
/// Specs
let max_int (n:pos) : Tot int = pow2 (n-1) - 1
let min_int (n:pos) : Tot int = - (pow2 (n-1)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Int.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"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.int -> n: Prims.pos -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Prims.pos",
"Prims.op_AmpAmp",
"Prims.op_LessThanOrEqual",
"FStar.Int.min_int",
"FStar.Int.max_int",
"Prims.bool"
] | [] | false | false | false | true | false | let fits (x: int) (n: pos) : Tot bool =
| min_int n <= x && x <= max_int n | false |
CDDL.Spec.fsti | CDDL.Spec.matches_map_group_entry' | val matches_map_group_entry'
(#b: _)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
(y: map_group_entry b)
: Tot prop | val matches_map_group_entry'
(#b: _)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
(y: map_group_entry b)
: Tot prop | let matches_map_group_entry'
(#b: _)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
(y: map_group_entry b)
: Tot prop
= opt_map_entry_bounded b x ==> matches_map_group_entry y x | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 59,
"end_line": 518,
"start_col": 0,
"start_line": 513
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *)
noextract
let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x
noextract
let map_group_equiv
#b
(mg1 mg2: map_group b)
: Tot prop
= forall x . matches_map_group mg1 x == matches_map_group mg2 x
noextract
let is_sub_typ_of
#b
(small large: bounded_typ_gen b)
: Tot prop
= forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x
noextract
let is_sub_map_group_entry_of
#b
(small large: map_group_entry b)
: Tot prop
= small.fst `is_sub_typ_of` large.fst /\
small.snd `is_sub_typ_of` large.snd
let map_group_ignore_restricted_entries
#b
(mg: map_group b)
: Tot (map_group b)
= {mg with
one = [];
zero_or_one = [];
}
let pull_rel
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(x1: t1)
: GTot ((x2: t2) -> Tot bool)
= Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2))
let list_ghost_forall_exists_body
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l2: list t2)
: GTot (t1 -> bool)
= Pull.pull (fun x1 -> List.Tot.existsb
(pull_rel r x1)
l2
)
let list_ghost_forall_exists
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l1: list t1)
(l2: list t2)
: GTot bool
= List.Tot.for_all
(list_ghost_forall_exists_body r l2)
l1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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: (CBOR.Spec.Type.raw_data_item * CBOR.Spec.Type.raw_data_item) -> y: CDDL.Spec.map_group_entry b
-> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"FStar.Pervasives.Native.tuple2",
"CDDL.Spec.map_group_entry",
"Prims.l_imp",
"Prims.b2t",
"CDDL.Spec.opt_map_entry_bounded",
"CDDL.Spec.matches_map_group_entry",
"Prims.prop"
] | [] | false | false | false | false | true | let matches_map_group_entry'
(#b: _)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
(y: map_group_entry b)
: Tot prop =
| opt_map_entry_bounded b x ==> matches_map_group_entry y x | false |
CDDL.Spec.fsti | CDDL.Spec.map_group_ignore_restricted_entries_no_one_equiv | val map_group_ignore_restricted_entries_no_one_equiv (#b: _) (mg: map_group b)
: Lemma
(requires
(Nil? mg.one /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more))
(ensures (map_group_equiv mg (map_group_ignore_restricted_entries mg))) | val map_group_ignore_restricted_entries_no_one_equiv (#b: _) (mg: map_group b)
: Lemma
(requires
(Nil? mg.one /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more))
(ensures (map_group_equiv mg (map_group_ignore_restricted_entries mg))) | let map_group_ignore_restricted_entries_no_one_equiv
#b
(mg: map_group b)
: Lemma
(requires (
Nil? mg.one /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more
))
(ensures (
map_group_equiv mg (map_group_ignore_restricted_entries mg)
))
= map_group_ignore_restricted_entries_sub mg;
map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg | {
"file_name": "share/steel/examples/pulse/dice/cbor/CDDL.Spec.fsti",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 85,
"end_line": 593,
"start_col": 0,
"start_line": 581
} | (*
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 CDDL.Spec
module Cbor = CBOR.Spec
module U8 = FStar.UInt8
module U64 = FStar.UInt64
// Concise Data Definition Language (RFC 8610)
noextract
let opt_precedes
(#t1 #t2: Type)
(x1: t1)
(x2: option t2)
: Tot prop
= match x2 with
| None -> True
| Some x2 -> x1 << x2
[@@noextract_to "krml"]
let bounded_typ_gen (e: option Cbor.raw_data_item) = (e': Cbor.raw_data_item { opt_precedes e' e }) -> GTot bool // GTot needed because of the .cbor control (staged serialization)
[@@noextract_to "krml"]
let typ = bounded_typ_gen None
[@@noextract_to "krml"]
let bounded_typ (e: Cbor.raw_data_item) = bounded_typ_gen (Some e)
let coerce_to_bounded_typ
(b: option Cbor.raw_data_item)
(t: typ)
: Tot (bounded_typ_gen b)
= t
noextract
let typ_equiv
(#b: option Cbor.raw_data_item)
(t1 t2: bounded_typ_gen b)
: Tot prop
= forall x . t1 x == t2 x
let t_choice (#b: option Cbor.raw_data_item) (t1 t2: bounded_typ_gen b) : bounded_typ_gen b = (fun x -> t1 x || t2 x)
let t_choice_equiv
#b
(t1 t1' t2 t2' : bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t1' /\ t2 `typ_equiv` t2'))
(ensures ((t1 `t_choice` t2) `typ_equiv` (t1' `t_choice` t2')))
= ()
// etc.
let t_choice_simpl
#b
(t: bounded_typ_gen b)
: Lemma
((t `t_choice` t) `typ_equiv` t)
= ()
let t_always_false : typ = (fun _ -> false)
let t_literal (i: Cbor.raw_data_item) : typ =
(fun x -> FStar.StrongExcludedMiddle.strong_excluded_middle (x == i))
// Appendix D
let any : typ = (fun _ -> true)
let uint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_uint64)
let nint : typ = (fun x -> Cbor.Int64? x && Cbor.Int64?.typ x = Cbor.cbor_major_type_neg_int64)
let t_int : typ = uint `t_choice` nint
let bstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_byte_string)
let bytes = bstr
let tstr : typ = (fun x -> Cbor.String? x && Cbor.String?.typ x = Cbor.cbor_major_type_text_string)
let text = tstr
[@@CMacro]
let simple_value_false : Cbor.simple_value = 20uy
[@@CMacro]
let simple_value_true : Cbor.simple_value = 21uy
[@@CMacro]
let simple_value_nil : Cbor.simple_value = 22uy
[@@CMacro]
let simple_value_undefined : Cbor.simple_value = 23uy
let t_simple_value_literal (s: Cbor.simple_value) : typ =
t_literal (Cbor.Simple s)
let t_false : typ = t_simple_value_literal simple_value_false
let t_true : typ = t_simple_value_literal simple_value_true
let t_bool : typ = t_choice t_false t_true
let t_nil : typ = t_simple_value_literal simple_value_nil
let t_null : typ = t_nil
let t_undefined : typ = t_simple_value_literal simple_value_undefined
let t_uint_literal (v: U64.t) : typ =
t_literal (Cbor.Int64 Cbor.cbor_major_type_uint64 v)
// Section 2.1: Groups
// Groups in array context (Section 3.4)
// General semantics, which would imply backtracking
[@@erasable; noextract_to "krml"]
let array_group1 = ((list Cbor.raw_data_item -> GTot bool) -> list Cbor.raw_data_item -> GTot bool)
let array_group1_empty : array_group1 = fun k -> k
let array_group1_concat (a1 a2: array_group1) : array_group1 = fun k -> a1 (a2 k)
let array_group1_choice (a1 a2: array_group1) : array_group1 = fun k l -> a1 k l || a2 k l
let rec array_group1_zero_or_more' (a: array_group1) (k: (list Cbor.raw_data_item -> GTot bool)) (l: list Cbor.raw_data_item) : GTot bool (decreases (List.Tot.length l)) =
k l ||
a (fun l' -> if List.Tot.length l' >= List.Tot.length l then false else array_group1_zero_or_more' a k l') l
let array_group1_zero_or_more : array_group1 -> array_group1 = array_group1_zero_or_more'
let array_group1_item (t: typ) : array_group1 = fun k l -> match l with
| [] -> false
| a :: q -> t a && k q
let t_array1 (a: array_group1) : typ = fun x ->
Cbor.Array? x &&
a Nil? (Cbor.Array?.v x)
[@@noextract_to "krml"]
let nat_up_to (n: nat) : eqtype = (i: nat { i <= n })
[@@noextract_to "krml"]
let array_group2 = ((l: Seq.seq Cbor.raw_data_item) -> (i: nat_up_to (Seq.length l)) -> list (nat_up_to (Seq.length l)))
[@@noextract_to "krml"]
let array_group2_empty : array_group2 = (fun _ i -> [i])
[@@noextract_to "krml"]
let array_group2_concat (a1 a2: array_group2) : array_group2 =
(fun l i1 ->
let res1 = a1 l i1 in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) -> a2 l i2) res1
)
[@@noextract_to "krml"]
let array_group2_choice (a1 a2: array_group2) : array_group2 =
fun l i -> a1 l i `List.Tot.append` a2 l i
[@@noextract_to "krml"]
let rec array_group2_zero_or_more' (a: array_group2) (l: Seq.seq Cbor.raw_data_item) (i: nat_up_to (Seq.length l)) : Tot (list (nat_up_to (Seq.length l))) (decreases (Seq.length l - i)) =
i :: begin
let r1 = a l i in
List.Tot.concatMap (fun (i2: nat_up_to (Seq.length l)) ->
if i2 <= i
then []
else array_group2_zero_or_more' a l i2
)
r1
end
(*
[@@noextract_to "krml"]
let array_group2_item (t: typ) : array_group2 = fun l i ->
if i = Seq.length l then [] else
if t (Seq.index l i) then [i + 1] else
[]
*)
[@@noextract_to "krml"]
let t_array2 (a: array_group2) : typ = fun x ->
Cbor.Array? x &&
begin let l = Cbor.Array?.v x in
List.Tot.length l `List.Tot.mem` a (Seq.seq_of_list l) 0
end
// Greedy semantics (Appendix A?)
let list_is_suffix_of
(#t: Type)
(small large: list t)
: Tot prop
= exists prefix . large == prefix `List.Tot.append` small
let list_is_suffix_of_refl
(#t: Type)
(l: list t)
: Lemma
(l `list_is_suffix_of` l)
[SMTPat (l `list_is_suffix_of` l)]
= assert (l == [] `List.Tot.append` l)
let rec list_nil_precedes
(#t: Type)
(l: list t)
: Lemma
(Nil #t == l \/ Nil #t << l)
= match l with
| [] -> ()
| a :: q -> list_nil_precedes q
let rec list_is_suffix_of_precedes
(#t0 #t: Type)
(v0: t0)
(small large: list t)
: Lemma
(requires (
large << v0 /\
small `list_is_suffix_of` large
))
(ensures (
small << v0
))
(decreases (List.Tot.length large))
[SMTPat [small << v0]; SMTPat [small `list_is_suffix_of` large]]
= if Nil? small
then list_nil_precedes large
else begin
let prefix = FStar.IndefiniteDescription.indefinite_description_ghost (list t) (fun prefix -> large == prefix `List.Tot.append` small) in
List.Tot.append_length prefix small;
if List.Tot.length small = List.Tot.length large
then ()
else list_is_suffix_of_precedes v0 small (List.Tot.tl large)
end
[@@erasable; noextract_to "krml"]
let array_group3 (bound: option Cbor.raw_data_item) = (l: list Cbor.raw_data_item { opt_precedes l bound }) -> Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with
| None -> True
| Some l' -> opt_precedes l' bound
))
noextract
let array_group3_equiv
#b
(g1 g2: array_group3 b)
: Tot prop
= forall l . g1 l == g2 l
let array_group3_always_false #b : array_group3 b = fun _ -> None
let array_group3_empty #b : array_group3 b = fun x -> Some x
let array_group3_concat #b (a1 a3: array_group3 b) : array_group3 b =
(fun l ->
match a1 l with
| None -> None
| Some l3 -> a3 l3
)
let array_group3_concat_equiv
#b
(a1 a1' a2 a2' : array_group3 b)
: Lemma
(requires ((a1 `array_group3_equiv` a1') /\ (a2 `array_group3_equiv` a2')))
(ensures ((a1 `array_group3_concat` a2) `array_group3_equiv` (a1' `array_group3_concat` a2')))
= ()
let array_group3_choice #b (a1 a3: array_group3 b) : array_group3 b =
fun l -> match a1 l with
| None -> a3 l
| Some l3 -> Some l3
let rec array_group3_zero_or_more' #b (a: array_group3 b) (l: list Cbor.raw_data_item { opt_precedes l b }) : Ghost (option (list Cbor.raw_data_item))
(requires True)
(ensures (fun l' -> match l' with None -> True | Some l' -> opt_precedes l' b))
(decreases (List.Tot.length l))
=
match a l with
| None -> Some l
| Some l' ->
if List.Tot.length l' >= List.Tot.length l
then Some l
else array_group3_zero_or_more' a l'
let array_group3_zero_or_more #b : array_group3 b -> array_group3 b = array_group3_zero_or_more'
let array_group3_one_or_more #b (a: array_group3 b) : array_group3 b =
a `array_group3_concat` array_group3_zero_or_more a
let array_group3_zero_or_one #b (a: array_group3 b) : Tot (array_group3 b) =
a `array_group3_choice` array_group3_empty
let array_group3_item (#b: option Cbor.raw_data_item) (t: bounded_typ_gen b) : array_group3 b = fun l ->
match l with
| [] -> None
| a :: q -> if t a then Some q else None
let array_group3_item_equiv
#b
(t1 t2: bounded_typ_gen b)
: Lemma
(requires (t1 `typ_equiv` t2))
(ensures (array_group3_item t1 `array_group3_equiv` array_group3_item t2))
= ()
let match_array_group3 (#b: option Cbor.raw_data_item) (a: array_group3 b)
(l: list Cbor.raw_data_item {opt_precedes l b})
: GTot bool
= match a l with
| Some l' -> Nil? l'
| _ -> false
let t_array3 (#b: option Cbor.raw_data_item) (a: array_group3 b) : bounded_typ_gen b = fun x ->
Cbor.Array? x &&
match_array_group3 a (Cbor.Array?.v x)
let t_array3_equiv
#b
(a1 a2: array_group3 b)
: Lemma
(requires (array_group3_equiv a1 a2))
(ensures (typ_equiv (t_array3 a1) (t_array3 a2)))
= ()
// Recursive type (needed by COSE Section 5.1 "Recipient")
// Inspiring from Barthe et al., Type-Based Termination with Sized
// Products (CSL 2008): we allow recursion only at the level of
// destructors. In other words, instead of having a generic recursion
// combinator, we provide a recursion-enabled version only for each
// destructor combinator. We need to annotate it with a bound b (akin
// to the "size" annotation in a sized type.)
let rec t_array3_rec
(phi: (b: Cbor.raw_data_item) -> (bounded_typ b -> array_group3 (Some b)))
(x: Cbor.raw_data_item)
: GTot bool
(decreases x)
=
Cbor.Array? x &&
match_array_group3 (phi x (t_array3_rec phi)) (Cbor.Array?.v x)
// Groups in map context (Section 3.5)
[@@erasable]
noeq
type map_group_entry (b: option Cbor.raw_data_item) = | MapGroupEntry: (fst: bounded_typ_gen b) -> (snd: bounded_typ_gen b) -> map_group_entry b
module Pull = FStar.Ghost.Pull
noextract
let opt_map_entry_bounded'
(b: option Cbor.raw_data_item)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
: GTot bool
= FStar.StrongExcludedMiddle.strong_excluded_middle (opt_precedes x b)
let opt_map_entry_bounded
(b: option Cbor.raw_data_item)
: GTot ((Cbor.raw_data_item & Cbor.raw_data_item) -> bool)
= Pull.pull (opt_map_entry_bounded' b)
let rec opt_precedes_map_for_all_opt_map_entry_bounded
(b: option Cbor.raw_data_item)
(l: list (Cbor.raw_data_item & Cbor.raw_data_item))
: Lemma
(requires (opt_precedes l b))
(ensures (List.Tot.for_all (opt_map_entry_bounded b) l))
[SMTPat (List.Tot.for_all (opt_map_entry_bounded b) l)]
= match l with
| [] -> ()
| _ :: q -> opt_precedes_map_for_all_opt_map_entry_bounded b q
let matches_map_group_entry
(#b: option Cbor.raw_data_item)
(ge: map_group_entry b)
(x: (Cbor.raw_data_item & Cbor.raw_data_item) { opt_map_entry_bounded b x == true })
: GTot bool
= ge.fst (fst x) && ge.snd (snd x)
[@@erasable]
noeq
type map_group (b: option Cbor.raw_data_item) = {
one: list (map_group_entry b);
zero_or_one: list (map_group_entry b);
zero_or_more: list (map_group_entry b);
}
let map_group_empty #b : map_group b = {
one = [];
zero_or_one = [];
zero_or_more = [];
}
let cut_map_group_entry_key
#b
(key: bounded_typ_gen b)
(t: bounded_typ_gen b)
(x: Cbor.raw_data_item { opt_precedes x b })
: GTot bool
= t x && not (key x)
// Section 3.5.4: Cut
let cut_map_group_entry #b (key: bounded_typ_gen b) (ge: map_group_entry b) : map_group_entry b =
cut_map_group_entry_key key ge.fst `MapGroupEntry` ge.snd
let cut_map_group #b (key: bounded_typ_gen b) (g: map_group b) : map_group b = {
one = List.Tot.map (cut_map_group_entry key) g.one;
zero_or_one = List.Tot.map (cut_map_group_entry key) g.zero_or_one;
zero_or_more = List.Tot.map (cut_map_group_entry key) g.zero_or_more;
}
let maybe_cut_map_group #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
if cut
then cut_map_group (ge.fst) g
else g
let map_group_cons_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
one = ge :: g.one;
}
let map_group_cons_zero_or_one #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_one = ge :: g.zero_or_one;
}
let map_group_cons_zero_or_more #b (ge: map_group_entry b) (cut: bool) (g: map_group b) : map_group b =
let g = maybe_cut_map_group ge cut g in {
g with
zero_or_more = ge :: g.zero_or_more;
}
val matches_map_group
(#b: option Cbor.raw_data_item)
(m: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) {List.Tot.for_all (opt_map_entry_bounded b) x })
: GTot bool
val matches_map_group_empty
(b: option Cbor.raw_data_item)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(ensures (matches_map_group (map_group_empty #b) x == Nil? x))
[SMTPat (matches_map_group (map_group_empty #b) x)]
(* Inclusion and equivalence proofs for map groups. Those are meant as the main proof devices for matches_map_group *)
noextract
let is_sub_map_group_of
#b
(small large: map_group b)
: Tot prop
= forall x . matches_map_group small x ==> matches_map_group large x
noextract
let map_group_equiv
#b
(mg1 mg2: map_group b)
: Tot prop
= forall x . matches_map_group mg1 x == matches_map_group mg2 x
noextract
let is_sub_typ_of
#b
(small large: bounded_typ_gen b)
: Tot prop
= forall (x: Cbor.raw_data_item { opt_precedes x b }) . small x ==> large x
noextract
let is_sub_map_group_entry_of
#b
(small large: map_group_entry b)
: Tot prop
= small.fst `is_sub_typ_of` large.fst /\
small.snd `is_sub_typ_of` large.snd
let map_group_ignore_restricted_entries
#b
(mg: map_group b)
: Tot (map_group b)
= {mg with
one = [];
zero_or_one = [];
}
let pull_rel
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(x1: t1)
: GTot ((x2: t2) -> Tot bool)
= Pull.pull (fun x2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (r x1 x2))
let list_ghost_forall_exists_body
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l2: list t2)
: GTot (t1 -> bool)
= Pull.pull (fun x1 -> List.Tot.existsb
(pull_rel r x1)
l2
)
let list_ghost_forall_exists
(#t1 #t2: Type)
(r: t1 -> t2 -> prop)
(l1: list t1)
(l2: list t2)
: GTot bool
= List.Tot.for_all
(list_ghost_forall_exists_body r l2)
l1
noextract
let matches_map_group_entry'
(#b: _)
(x: (Cbor.raw_data_item & Cbor.raw_data_item))
(y: map_group_entry b)
: Tot prop
= opt_map_entry_bounded b x ==> matches_map_group_entry y x
val matches_map_group_no_restricted
(#b: _)
(g: map_group b)
(x: list (Cbor.raw_data_item & Cbor.raw_data_item) { List.Tot.for_all (opt_map_entry_bounded b) x })
: Lemma
(requires (
Nil? g.one /\
Nil? g.zero_or_one
))
(ensures (
matches_map_group g x <==> list_ghost_forall_exists matches_map_group_entry' x g.zero_or_more
))
[SMTPat (matches_map_group g x)]
let rec list_ghost_forall2
(#t1 #t2: Type)
(f: t1 -> t2 -> GTot prop)
(l1: list t1)
(l2: list t2)
: GTot bool
(decreases l1)
= match l1, l2 with
| [], [] -> true
| a1 :: q1, a2 :: q2 -> FStar.StrongExcludedMiddle.strong_excluded_middle (f a1 a2) && list_ghost_forall2 f q1 q2
| _ -> false
val list_ghost_forall_exists_is_sub_map_group_entry_of_refl
(#b: _)
(l: list (map_group_entry b))
: Lemma
(ensures (list_ghost_forall_exists is_sub_map_group_entry_of l l))
[SMTPat (list_ghost_forall_exists is_sub_map_group_entry_of l l)]
let map_group_included_zero_or_more
#b
(small large: map_group b)
: GTot bool
= list_ghost_forall_exists is_sub_map_group_entry_of small.one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_one large.zero_or_more &&
list_ghost_forall_exists is_sub_map_group_entry_of small.zero_or_more large.zero_or_more &&
Nil? large.one
val map_group_included_zero_or_more_correct
(#b: _)
(small large: map_group b)
: Lemma
(requires (map_group_included_zero_or_more small large))
(ensures (is_sub_map_group_of small large))
val map_group_ignore_restricted_entries_sub
(#b: _)
(mg: map_group b)
: Lemma
(requires (
list_ghost_forall_exists is_sub_map_group_entry_of mg.one mg.zero_or_more /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more
))
(ensures (
mg `is_sub_map_group_of` map_group_ignore_restricted_entries mg
)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.StrongExcludedMiddle.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Ghost.Pull.fsti.checked",
"CBOR.Spec.fsti.checked"
],
"interface_file": false,
"source_file": "CDDL.Spec.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.Ghost.Pull",
"short_module": "Pull"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "CBOR.Spec",
"short_module": "Cbor"
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "CDDL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "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 | mg: CDDL.Spec.map_group b
-> FStar.Pervasives.Lemma
(requires
Nil? (Mkmap_group?.one mg) /\
CDDL.Spec.list_ghost_forall_exists CDDL.Spec.is_sub_map_group_entry_of
(Mkmap_group?.zero_or_one mg)
(Mkmap_group?.zero_or_more mg))
(ensures CDDL.Spec.map_group_equiv mg (CDDL.Spec.map_group_ignore_restricted_entries mg)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Pervasives.Native.option",
"CBOR.Spec.Type.raw_data_item",
"CDDL.Spec.map_group",
"CDDL.Spec.map_group_included_zero_or_more_correct",
"CDDL.Spec.map_group_ignore_restricted_entries",
"Prims.unit",
"CDDL.Spec.map_group_ignore_restricted_entries_sub",
"Prims.l_and",
"Prims.b2t",
"Prims.uu___is_Nil",
"CDDL.Spec.map_group_entry",
"CDDL.Spec.__proj__Mkmap_group__item__one",
"CDDL.Spec.list_ghost_forall_exists",
"CDDL.Spec.is_sub_map_group_entry_of",
"CDDL.Spec.__proj__Mkmap_group__item__zero_or_one",
"CDDL.Spec.__proj__Mkmap_group__item__zero_or_more",
"Prims.squash",
"CDDL.Spec.map_group_equiv",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let map_group_ignore_restricted_entries_no_one_equiv #b (mg: map_group b)
: Lemma
(requires
(Nil? mg.one /\
list_ghost_forall_exists is_sub_map_group_entry_of mg.zero_or_one mg.zero_or_more))
(ensures (map_group_equiv mg (map_group_ignore_restricted_entries mg))) =
| map_group_ignore_restricted_entries_sub mg;
map_group_included_zero_or_more_correct (map_group_ignore_restricted_entries mg) mg | false |
FStar.Int.fsti | FStar.Int.size | val size (x: int) (n: pos) : Tot Type0 | val size (x: int) (n: pos) : Tot Type0 | let size (x:int) (n:pos) : Tot Type0 = b2t(fits x n) | {
"file_name": "ulib/FStar.Int.fsti",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 52,
"end_line": 45,
"start_col": 0,
"start_line": 45
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fsti], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
val pow2_values: x:nat -> Lemma
(let p = pow2 x in
match x with
| 0 -> p=1
| 1 -> p=2
| 8 -> p=256
| 16 -> p=65536
| 31 -> p=2147483648
| 32 -> p=4294967296
| 63 -> p=9223372036854775808
| 64 -> p=18446744073709551616
| _ -> True)
[SMTPat (pow2 x)]
/// Specs
let max_int (n:pos) : Tot int = pow2 (n-1) - 1
let min_int (n:pos) : Tot int = - (pow2 (n-1)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": false,
"source_file": "FStar.Int.fsti"
} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"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.int -> n: Prims.pos -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"Prims.pos",
"Prims.b2t",
"FStar.Int.fits"
] | [] | false | false | false | true | true | let size (x: int) (n: pos) : Tot Type0 =
| b2t (fits x n) | 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.