val lemma_valid_descendent_hash_valid_voption: #rrel: _ -> #rel: _ -> s:LL.slice rrel rel -> pos:U32.t -> h:HyperStack.mem -> Lemma
  (requires LL.valid descendent_hash_parser h s pos)
  (ensures (LL.valid voption_parser h s pos /\ LL.contents voption_parser h s pos == tag_of_descendent_hash (LL.contents descendent_hash_parser h s pos)))
  [SMTPat (LL.valid descendent_hash_parser h s pos)]
val lemma_valid_descendent_hash_valid_voption: #rrel: _ -> #rel: _ -> s:LL.slice rrel rel -> pos:U32.t -> h:HyperStack.mem -> Lemma
  (requires LL.valid descendent_hash_parser h s pos)
  (ensures (LL.valid voption_parser h s pos /\ LL.contents voption_parser h s pos == tag_of_descendent_hash (LL.contents descendent_hash_parser h s pos)))
  [SMTPat (LL.valid descendent_hash_parser h s pos)]
let lemma_valid_descendent_hash_valid_voption #_ #_ s pos h =
  assert_norm (LP.parse_sum_kind (LP.get_parser_kind voption_repr_parser) descendent_hash_sum parse_descendent_hash_cases == descendent_hash_parser_kind);
  LL.valid_sum_elim_tag h descendent_hash_sum voption_repr_parser parse_descendent_hash_cases s pos;
  lemma_synth_voption_inj ();
  LL.valid_synth h parse_voption_key synth_voption s pos
module Zeta.Formats.Aux.Descendent_hash

(* This file has been automatically generated by EverParse. *)
open FStar.Bytes
module U8 = FStar.UInt8
module U16 = FStar.UInt16
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module LP = LowParse.Spec
module LT = LowParse.TacLib
module LSZ = LowParse.SLow
module LPI = LowParse.Spec.AllIntegers
module LL = LowParse.Low
module L = FStar.List.Tot
module B = LowStar.Buffer
module BY = FStar.Bytes
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST

#reset-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection' --z3rlimit 16 --z3cliopt smt.arith.nl=false --max_fuel 2 --max_ifuel 2"

friend Zeta.Formats.Aux.Voption

// Need high Z3 limits for large sum types
#set-options "--z3rlimit 120"

inline_for_extraction unfold let voption_as_enum_key (x:voption) : Pure (LP.enum_key voption_enum)
  (requires norm [delta; zeta; iota; primops] (LP.list_mem x (LP.list_map fst voption_enum)) == true) (ensures fun _ -> True) =
  [@inline_let] let _ = norm_spec [delta; zeta; iota; primops] (LP.list_mem x (LP.list_map fst voption_enum)) in x

inline_for_extraction let key_of_descendent_hash (x:descendent_hash) : LP.enum_key voption_enum =
  match x with
  | Dh_vnone _ -> voption_as_enum_key Vnone
  | Dh_vsome _ -> voption_as_enum_key Vsome

inline_for_extraction let descendent_hash_case_of_voption (x:voption) : Type0 =
  match x with
  | Vnone -> unit
  | Vsome -> descendent_hash_desc

unfold inline_for_extraction let to_descendent_hash_case_of_voption (x:voption) (#x':voption) (y:descendent_hash_case_of_voption x')  : Pure (norm [delta_only [(`%descendent_hash_case_of_voption)]; iota] (descendent_hash_case_of_voption x))
  (requires (x == x')) (ensures (fun y' -> y' == y)) =
  [@inline_let] let _ = norm_spec [delta_only [(`%descendent_hash_case_of_voption)] ; iota] (descendent_hash_case_of_voption x) in y

unfold inline_for_extraction let descendent_hash_refine (k:LP.enum_key voption_enum) (x:descendent_hash)
  : Pure (LP.refine_with_tag key_of_descendent_hash k)  (requires norm [delta; iota; zeta] (key_of_descendent_hash x) == k) (ensures (fun y -> y == x)) =
  [@inline_let] let _ = norm_spec [delta; iota; zeta] (key_of_descendent_hash x) in x

inline_for_extraction let synth_descendent_hash_cases (x:LP.enum_key voption_enum) (y:descendent_hash_case_of_voption x)
  : LP.refine_with_tag key_of_descendent_hash x =
  match x with
  | Vnone -> descendent_hash_refine x (Dh_vnone (to_descendent_hash_case_of_voption Vnone y))
  | Vsome -> descendent_hash_refine x (Dh_vsome (to_descendent_hash_case_of_voption Vsome y))

unfold inline_for_extraction let from_descendent_hash_case_of_voption (#x':voption) (x:voption)
  (y: norm [delta_only [(`%descendent_hash_case_of_voption)]; iota] (descendent_hash_case_of_voption x))
  : Pure (descendent_hash_case_of_voption x') (requires (x == x')) (ensures (fun y' -> y' == y)) =
  [@inline_let] let _ = norm_spec [delta_only [(`%descendent_hash_case_of_voption)] ; iota] (descendent_hash_case_of_voption x) in y

let synth_descendent_hash_cases_recip_pre (k:LP.enum_key voption_enum)
  (x:LP.refine_with_tag key_of_descendent_hash k) : GTot bool =
  match k with
  | Vnone -> Dh_vnone? x
  | Vsome -> Dh_vsome? x

let synth_descendent_hash_cases_recip_pre_intro (k:LP.enum_key voption_enum) (x:LP.refine_with_tag key_of_descendent_hash k)
  : Lemma (synth_descendent_hash_cases_recip_pre k x == true) =
  norm_spec [delta; iota] (synth_descendent_hash_cases_recip_pre k x)

inline_for_extraction let synth_descendent_hash_cases_recip (k:LP.enum_key voption_enum)
  (x:LP.refine_with_tag key_of_descendent_hash k) : (descendent_hash_case_of_voption k) =
  match k with
  | Vnone -> [@inline_let] let _ = synth_descendent_hash_cases_recip_pre_intro Vnone x in
    (match x with Dh_vnone y -> (from_descendent_hash_case_of_voption Vnone y))
  | Vsome -> [@inline_let] let _ = synth_descendent_hash_cases_recip_pre_intro Vsome x in
    (match x with Dh_vsome y -> (from_descendent_hash_case_of_voption Vsome y))

inline_for_extraction let descendent_hash_sum = LP.make_sum' voption_enum key_of_descendent_hash
  descendent_hash_case_of_voption synth_descendent_hash_cases synth_descendent_hash_cases_recip
  (_ by (LP.make_sum_synth_case_recip_synth_case_tac ()))
  (_ by (LP.synth_case_synth_case_recip_tac ()))

noextract let parse_descendent_hash_cases (x:LP.sum_key descendent_hash_sum)
  : k:LP.parser_kind & LP.parser k (descendent_hash_case_of_voption x) =
  match x with
  | Vnone -> [@inline_let] let u : (k: LP.parser_kind & LP.parser k (descendent_hash_case_of_voption Vnone)) = (| _, LP.parse_empty |) in u
  | Vsome -> [@inline_let] let u : (k: LP.parser_kind & LP.parser k (descendent_hash_case_of_voption Vsome)) = (| _, descendent_hash_desc_parser |) in u
  | _ -> (| _, LP.parse_false |)

noextract let serialize_descendent_hash_cases (x:LP.sum_key descendent_hash_sum)
  : LP.serializer (dsnd (parse_descendent_hash_cases x)) =
  match x with
  | Vnone -> [@inline_let] let u : LP.serializer (dsnd (parse_descendent_hash_cases Vnone)) = LP.serialize_empty in u
  | Vsome -> [@inline_let] let u : LP.serializer (dsnd (parse_descendent_hash_cases Vsome)) = descendent_hash_desc_serializer in u
  | _ -> LP.serialize_false

inline_for_extraction noextract let size32_descendent_hash_cases (x:LP.sum_key descendent_hash_sum)
  : LSZ.size32 (serialize_descendent_hash_cases x) =
  match x with
  | Vnone -> [@inline_let] let u : LSZ.size32 (serialize_descendent_hash_cases Vnone) = LSZ.size32_empty in u
  | Vsome -> [@inline_let] let u : LSZ.size32 (serialize_descendent_hash_cases Vsome) = descendent_hash_desc_size32 in u
  | _ -> LSZ.size32_false

inline_for_extraction noextract let validate_descendent_hash_cases (x:LP.sum_key descendent_hash_sum)
  : LL.validator (dsnd (parse_descendent_hash_cases x)) =
  match x with
  | Vnone -> [@inline_let] let u : LL.validator (dsnd (parse_descendent_hash_cases Vnone)) = (LL.validate_empty ()) in u
  | Vsome -> [@inline_let] let u : LL.validator (dsnd (parse_descendent_hash_cases Vsome)) = descendent_hash_desc_validator in u
  | _ -> LL.validate_false ()

inline_for_extraction noextract let jump_descendent_hash_cases (x:LP.sum_key descendent_hash_sum)
  : LL.jumper (dsnd (parse_descendent_hash_cases x)) =
  match x with
  | Vnone -> [@inline_let] let u : LL.jumper (dsnd (parse_descendent_hash_cases Vnone)) = LL.jump_empty in u
  | Vsome -> [@inline_let] let u : LL.jumper (dsnd (parse_descendent_hash_cases Vsome)) = descendent_hash_desc_jumper in u
  | _ -> LL.jump_false

inline_for_extraction noextract let read_descendent_hash_cases (x:LP.sum_key descendent_hash_sum)
  : LL.leaf_reader (dsnd (parse_descendent_hash_cases x)) =
  match x with
  | Vnone -> [@inline_let] let u : LL.leaf_reader (dsnd (parse_descendent_hash_cases Vnone)) = LL.read_empty in u
  | Vsome -> [@inline_let] let u : LL.leaf_reader (dsnd (parse_descendent_hash_cases Vsome)) = descendent_hash_desc_reader in u
  | _ -> LL.read_false

inline_for_extraction noextract let lserialize_descendent_hash_cases (x:LP.sum_key descendent_hash_sum)
  : LL.serializer32 (serialize_descendent_hash_cases x) =
  match x with
  | Vnone -> [@inline_let] let u : LL.serializer32 (serialize_descendent_hash_cases Vnone) = LL.serialize32_empty in u
  | Vsome -> [@inline_let] let u : LL.serializer32 (serialize_descendent_hash_cases Vsome) = descendent_hash_desc_lserializer in u
  | _ -> LL.serialize32_false

let descendent_hash_parser =
  assert_norm (LP.parse_sum_kind (LP.get_parser_kind voption_repr_parser) descendent_hash_sum parse_descendent_hash_cases == descendent_hash_parser_kind);
  LP.parse_sum descendent_hash_sum voption_repr_parser parse_descendent_hash_cases

let descendent_hash_serializer =
  assert_norm (LP.parse_sum_kind (LP.get_parser_kind voption_repr_parser) descendent_hash_sum parse_descendent_hash_cases == descendent_hash_parser_kind);
  LP.serialize_sum descendent_hash_sum voption_repr_serializer serialize_descendent_hash_cases

let descendent_hash_bytesize (x:descendent_hash) : GTot nat = Seq.length (descendent_hash_serializer x)

let descendent_hash_bytesize_eq x = ()

let descendent_hash_size32 =
  assert_norm (LP.parse_sum_kind (LP.get_parser_kind voption_repr_parser) descendent_hash_sum parse_descendent_hash_cases == descendent_hash_parser_kind);
  assert_norm (LSZ.size32_sum_gen_precond (LP.get_parser_kind voption_repr_parser) (LP.weaken_parse_cases_kind descendent_hash_sum parse_descendent_hash_cases));
  LSZ.size32_sum2 descendent_hash_sum voption_repr_serializer voption_repr_size32 serialize_descendent_hash_cases size32_descendent_hash_cases (_ by (LP.dep_enum_destr_tac ())) (_ by (LP.enum_repr_of_key_tac voption_enum)) ()

let descendent_hash_validator =
  assert_norm (LP.parse_sum_kind (LP.get_parser_kind voption_repr_parser) descendent_hash_sum parse_descendent_hash_cases == descendent_hash_parser_kind);
  LL.validate_sum descendent_hash_sum voption_repr_validator voption_repr_reader parse_descendent_hash_cases validate_descendent_hash_cases (_ by (LP.dep_maybe_enum_destr_t_tac ()))

let descendent_hash_jumper =
  assert_norm (LP.parse_sum_kind (LP.get_parser_kind voption_repr_parser) descendent_hash_sum parse_descendent_hash_cases == descendent_hash_parser_kind);
  LL.jump_sum descendent_hash_sum voption_repr_jumper voption_repr_reader parse_descendent_hash_cases jump_descendent_hash_cases (_ by (LP.dep_maybe_enum_destr_t_tac ()))

let descendent_hash_reader =
  assert_norm (LP.parse_sum_kind (LP.get_parser_kind voption_repr_parser) descendent_hash_sum parse_descendent_hash_cases == descendent_hash_parser_kind);
  LL.read_sum descendent_hash_sum voption_repr_parser read_voption_key voption_repr_jumper parse_descendent_hash_cases read_descendent_hash_cases (_ by (LP.dep_enum_destr_tac ()))

let descendent_hash_lserializer =
  assert_norm (LP.parse_sum_kind (LP.get_parser_kind voption_repr_parser) descendent_hash_sum parse_descendent_hash_cases == descendent_hash_parser_kind);
  LL.serialize32_sum descendent_hash_sum voption_repr_serializer lserialize_voption_key serialize_descendent_hash_cases lserialize_descendent_hash_cases (_ by (LP.dep_enum_destr_tac ()))
/
Zeta.Formats.Aux.Voption.fst.checked prims.fst.checked LowStar.Buffer.fst.checked LowParse.TacLib.fst.checked LowParse.Spec.AllIntegers.fst.checked LowParse.Spec.fst.checked LowParse.SLow.fst.checked LowParse.Low.fst.checked FStar.UInt8.fsti.checked FStar.UInt64.fsti.checked FStar.UInt32.fsti.checked FStar.UInt16.fsti.checked FStar.Tactics.Effect.fsti.checked FStar.Seq.fst.checked FStar.Pervasives.fsti.checked FStar.List.Tot.fst.checked FStar.HyperStack.ST.fsti.checked FStar.HyperStack.fst.checked FStar.Bytes.fsti.checked
Zeta.Formats.Aux.Descendent_hash.fst
s: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> h: FStar.Monotonic.HyperStack.mem
  -> FStar.Pervasives.Lemma
      (requires
        LowParse.Low.Base.Spec.valid Zeta.Formats.Aux.Descendent_hash.descendent_hash_parser h s pos
      )
      (ensures
        LowParse.Low.Base.Spec.valid Zeta.Formats.Aux.Voption.voption_parser h s pos /\
        LowParse.Low.Base.Spec.contents Zeta.Formats.Aux.Voption.voption_parser h s pos ==
        Zeta.Formats.Aux.Descendent_hash.tag_of_descendent_hash (LowParse.Low.Base.Spec.contents Zeta.Formats.Aux.Descendent_hash.descendent_hash_parser
              h
              s
              pos))
      [
        SMTPat (LowParse.Low.Base.Spec.valid Zeta.Formats.Aux.Descendent_hash.descendent_hash_parser
              h
              s
              pos)
      ]
LowParse.Slice.srel LowParse.Bytes.byte LowParse.Slice.slice FStar.UInt32.t FStar.Monotonic.HyperStack.mem LowParse.Low.Combinators.valid_synth LowParse.Spec.Combinators.parse_filter_kind LowParse.Spec.Int.parse_u8_kind LowParse.Spec.Enum.enum_key Zeta.Formats.Aux.Voption.voption FStar.UInt8.t Zeta.Formats.Aux.Voption.voption_enum Zeta.Formats.Aux.Voption.parse_voption_key Zeta.Formats.Aux.Voption.synth_voption Prims.unit Zeta.Formats.Aux.Voption.lemma_synth_voption_inj LowParse.Low.Sum.valid_sum_elim_tag Zeta.Formats.Aux.Descendent_hash.descendent_hash_sum Zeta.Formats.Aux.Voption.voption_repr_parser Zeta.Formats.Aux.Descendent_hash.parse_descendent_hash_cases FStar.Pervasives.assert_norm Prims.eq2 LowParse.Spec.Base.parser_kind LowParse.Spec.Sum.parse_sum_kind LowParse.Spec.Base.get_parser_kind Zeta.Formats.Aux.Descendent_hash.descendent_hash_parser_kind
let lemma_valid_descendent_hash_valid_voption #_ #_ s pos h =
  
assert_norm (LP.parse_sum_kind (LP.get_parser_kind voption_repr_parser)
      descendent_hash_sum
      parse_descendent_hash_cases ==
    descendent_hash_parser_kind);
LL.valid_sum_elim_tag h descendent_hash_sum voption_repr_parser parse_descendent_hash_cases s pos;
lemma_synth_voption_inj ();
LL.valid_synth h parse_voption_key synth_voption s pos