Proof using.
intros. induction l; simpl in *; auto.
repeat (break_match; simpl in *); do_bool; intuition; try omega; try congruence.
f_equal. repeat find_reverse_rewrite.
rewrite removeAfterIndex_eq; auto.
intros. find_apply_hyp_hyp. omega.
Qed.
Fixpoint log_to_ks' (l : list entry) (ks : list (clientId * nat)) : list (clientId * nat) :=
match l with
| e :: l' =>
if (assoc_default clientId_eq_dec ks (eClient e) 0) <=? eId e then
log_to_ks' l' (assoc_set clientId_eq_dec ks (eClient e) (eId e))
else
log_to_ks' l' ks
| [] => ks
end.
Definition log_to_ks l := log_to_ks' l [].
Definition client_cache_keys_correct net :=
forall h,
a_equiv clientId_eq_dec
(clientCache_to_ks (clientCache (nwState net h)))
(log_to_ks'
(rev
(removeAfterIndex (log (nwState net h))
(lastApplied (nwState net h)))) []).

(* Specifications: *)
Lemma log_to_ks'_app :
forall l1 l2 ks,
log_to_ks' (l1 ++ l2) ks = log_to_ks' l2 (log_to_ks' l1 ks).