Ltac start :=
    red; unfold append_entries_leaderLogs; intros;
    subst; simpl in *; find_higher_order_rewrite;
    update_destruct; subst; rewrite_update; eauto; simpl in *.Ltac prove_in :=
    match goal with
      | [ _ : nwPackets ?net = _,
              _ : In (?p : packet) _ |- _] =>
        assert (In p (nwPackets net)) by (repeat find_rewrite; do_in_app; intuition)
      | [ _ : nwPackets ?net = _,
              _ : pBody ?p = _ |- _] =>
        assert (In p (nwPackets net)) by (repeat find_rewrite; intuition)
    end.

(* Specifications: *)
Lemma append_entries_leaderLogs_appendEntries : refined_raft_net_invariant_append_entries append_entries_leaderLogs.
Lemma append_entries_leaderLogs_appendEntriesReply : refined_raft_net_invariant_append_entries_reply append_entries_leaderLogs.
Lemma append_entries_leaderLogs_requestVote : refined_raft_net_invariant_request_vote append_entries_leaderLogs.
Lemma append_entries_leaderLogs_requestVoteReply : refined_raft_net_invariant_request_vote_reply append_entries_leaderLogs.
Lemma append_entries_leaderLogs_clientRequest : refined_raft_net_invariant_client_request append_entries_leaderLogs.
Lemma append_entries_leaderLogs_timeout : refined_raft_net_invariant_timeout append_entries_leaderLogs.
Lemma append_entries_leaderLogs_doGenericServer : refined_raft_net_invariant_do_generic_server append_entries_leaderLogs.
Lemma doLeader_spec : forall st h os st' ms m t n pli plt es ci, doLeader st h = (os, st', ms) -> In m ms -> snd m = AppendEntries t n pli plt es ci -> t = currentTerm st /\ log st' = log st /\ type st = Leader /\ ((pli = 0 /\ plt = 0 /\ es = findGtIndex (log st) 0) \/ ((exists e, findAtIndex (log st) pli = Some e /\ eTerm e = plt) /\ es = findGtIndex (log st) pli) \/ exists h', pred (getNextIndex st h') <> 0 /\ findAtIndex (log st) (pred (getNextIndex st h')) = None).
Lemma lift_nextIndex_safety : forall net, refined_raft_intermediate_reachable net -> nextIndex_safety (deghost net).
Lemma nextIndex_sanity : forall net h h', refined_raft_intermediate_reachable net -> type (snd (nwState net h)) = Leader -> pred (getNextIndex (snd (nwState net h)) h') <> 0 -> exists e, findAtIndex (log (snd (nwState net h))) (pred (getNextIndex (snd (nwState net h)) h')) = Some e.
Lemma sorted_findGtIndex_0 : forall l, (forall e, In e l -> eIndex e > 0) -> sorted l -> findGtIndex l 0 = l.
Lemma entries_gt_0 : forall net h e, refined_raft_intermediate_reachable net -> In e (log (snd (nwState net h))) -> eIndex e > 0.
Lemma Prefix_refl : forall A (l : list A), Prefix l l.
Lemma findGtIndex_app_in_1 : forall l1 l2 e, sorted (l1 ++ l2) -> In e l1 -> exists l', findGtIndex (l1 ++ l2) (eIndex e) = l' /\ forall x, In x l' -> In x l1.
Lemma sorted_app_in_1 : forall l1 l2 e, sorted (l1 ++ l2) -> eIndex e > 0 -> In e l1 -> eIndex e > maxIndex l2.
Lemma findGtIndex_Prefix : forall l i, Prefix (findGtIndex l i) l.
Lemma findGtIndex_app_in_2 : forall l1 l2 e, sorted (l1 ++ l2) -> In e l2 -> exists l', findGtIndex (l1 ++ l2) (eIndex e) = l1 ++ l' /\ Prefix l' l2.
Lemma findGtIndex_app_eq : forall l1 l2 e, sorted (l1 ++ l2) -> In e l2 -> findGtIndex (l1 ++ l2) (eIndex e) = l1 -> eIndex e = maxIndex l2.
Lemma append_entries_leaderLogs_doLeader : refined_raft_net_invariant_do_leader append_entries_leaderLogs.
Lemma append_entries_leaderLogs_init : refined_raft_net_invariant_init append_entries_leaderLogs.
Lemma append_entries_leaderLogs_state_same_packets_subset : refined_raft_net_invariant_state_same_packet_subset append_entries_leaderLogs.
Lemma append_entries_leaderLogs_reboot : refined_raft_net_invariant_reboot append_entries_leaderLogs.
Theorem append_entries_leaderLogs_invariant : forall net, refined_raft_intermediate_reachable net -> append_entries_leaderLogs net.