Proof using overlay_map_congr new_msg_map_congr name_map_bijective multi_map_congr fail_msg_map_congr.
move => net net' failed failed' tr H_nd H_step.
invcs H_step.
- rewrite /tot_map_odnet /=.
apply (@StepOrderedDynamicFailure_start _ _ _ _ _ _ _ _ (tot_map_name h)) => /=; first exact: not_in_failed_not_in.
set p1 := fun _ _ => _.
set p2 := collate_ls _ _ _ _ _.
set s1 := fun _ => _.
set s2 := update _ _ _ _.
have H_eq_s: s1 = s2.
rewrite /s1 /s2 /update {s1 s2}.
apply functional_extensionality => n.
rewrite -tot_init_handlers_eq.
break_match_goal.
break_if; break_if; try by congruence.
- by repeat find_rewrite; repeat find_rewrite_lem tot_map_name_inv_inverse.
- by find_reverse_rewrite; find_rewrite_lem tot_map_name_inverse_inv.
- by find_rewrite.
break_if; break_if; (try by congruence); last by find_rewrite.
by repeat find_rewrite; repeat find_rewrite_lem tot_map_name_inv_inverse.
rewrite H_eq_s /s2 {s1 s2 H_eq_s}.
have H_eq_p: p1 = p2.
rewrite /p1 /p2 {p1 p2}.
rewrite collate_ls_tot_map_eq /=.
rewrite collate_tot_map_eq.
rewrite tot_new_msg_fst_snd.
set f1 := fun _ _ => _.
set c1 := collate _ _ _ _.
set c2 := collate _ _ _ _.
set f'1 := map tot_map_name _.
set f'2 := filter_rel _ (tot_map_name h) _.
have H_c: c1 = c2.
rewrite /c1 /c2 {c1 c2}.
apply: NoDup_Permutation_collate_eq; last first.
rewrite /tot_map_name_msgs.
by apply: nodup_perm_map_map_pair_perm; last exact: Permutation_refl.
rewrite /tot_map_name_msgs /=.
apply: NoDup_map_snd_fst => //.
apply (@nodup_tot_map msg_new); first exact: in_map2snd_snd.
apply: NoDup_map2snd.
exact: NoDup_remove_all.
move => nm nm' H_in H_in'.
apply tot_map_in_snd in H_in.
apply tot_map_in_snd in H_in'.
by rewrite H_in H_in'.
rewrite H_c {H_c}.
suff H_suff: f'1 = f'2 by rewrite H_suff.
rewrite /f'1 /f'2.
elim (odnwNodes net) => /=; first by rewrite 2!remove_all_nil.
move => n ns.
set mn := tot_map_name n.
set mns := map _ ns.
set mfailed' := map _ failed'.
move => IH.
have H_cn := remove_all_cons name_eq_dec failed' n ns.
have H_cn' := remove_all_cons name_eq_dec mfailed' mn mns.
unfold mn, mns, mfailed' in *.
repeat break_or_hyp; repeat break_and; repeat find_rewrite => //=.
* by find_apply_lem_hyp not_in_failed_not_in.
* by find_apply_lem_hyp in_failed_in.
* case adjacent_to_dec => H_dec; case adjacent_to_dec => H_dec' => //=.
+ by rewrite IH.
+ by find_apply_lem_hyp tot_adjacent_to_fst_snd.
+ by find_apply_lem_hyp tot_adjacent_to_fst_snd.
by rewrite H_eq_p.
- rewrite /tot_map_odnet /=.
apply (@StepOrderedDynamicFailure_deliver _ _ _ _ _ _ _ _ _ (tot_map_msg m) (map tot_map_msg ms) (map tot_map_output out) (tot_map_data d) (tot_map_data d') (tot_map_name_msgs l) (tot_map_name from) (tot_map_name to)) => //=.
* exact: not_in_failed_not_in.
* exact: in_failed_in.
* rewrite tot_map_name_inv_inverse.
by break_match; congruence.
* rewrite 2!tot_map_name_inv_inverse.
by find_rewrite.
* rewrite -tot_net_handlers_eq /tot_mapped_net_handlers.
repeat break_let.
by repeat tuple_inversion.
* set u1 := fun _ => match _ with | _ => _ end.
set u2 := update _ _ _ _.
rewrite collate_tot_map_update2_eq.
suff H_suff: u1 = u2 by rewrite H_suff.
rewrite /u1 /u2 /update /=.
apply functional_extensionality => n.
repeat break_if; try by congruence.
rewrite -(tot_map_name_inverse_inv n) in n0.
by rewrite e in n0.
find_rewrite.
by find_rewrite_lem tot_map_name_inv_inverse.
* by rewrite map_tot_map_trace_eq.
- rewrite /tot_map_odnet /=.
apply (@StepOrderedDynamicFailure_input _ _ _ _ _ (tot_map_name h) _ _ _ _ (map tot_map_output out) (tot_map_input inp) (tot_map_data d) (tot_map_data d') (tot_map_name_msgs l)) => //=.
* exact: not_in_failed_not_in.
* exact: in_failed_in.
* rewrite tot_map_name_inv_inverse.
by break_match; congruence.
* rewrite /= -tot_input_handlers_eq /tot_mapped_input_handlers.
repeat break_let.
by repeat tuple_inversion.
* rewrite collate_tot_map_eq.
set u1 := fun _ => match _ with | _ => _ end.
set u2 := update _ _ _ _.
suff H_suff: u1 = u2 by rewrite H_suff.
rewrite /u1 /u2 /update /=.
apply functional_extensionality => n.
repeat break_if; try by congruence.
rewrite -(tot_map_name_inverse_inv n) in n0.
by rewrite e in n0.
find_rewrite.
by find_rewrite_lem tot_map_name_inv_inverse.
* by rewrite map_tot_map_trace_eq.
- rewrite /tot_map_odnet /=.
set l := map2snd _ _.
have H_nd': NoDup (map (fun nm => fst nm) (tot_map_name_msgs l)).
rewrite /tot_map_name_msgs /=.
rewrite /l {l}.
apply NoDup_map_snd_fst.
apply (@nodup_tot_map msg_fail); first exact: in_map2snd_snd.
apply NoDup_map2snd.
exact: NoDup_remove_all.
move => nm nm' H_in H_in'.
have H_fail := tot_map_in_snd _ _ _ _ H_in.
have H_fail' := tot_map_in_snd _ _ _ _ H_in'.
by rewrite H_fail H_fail'.
have H_pm := map_msg_fail_eq_nodup h failed H_nd (Permutation_refl (map tot_map_name (odnwNodes net))).
have H_eq := NoDup_Permutation_collate_eq  _ _ name_eq_dec _ _ _ _ H_nd' H_pm.
rewrite /l /tot_map_name_msgs in H_eq.
apply: StepOrderedDynamicFailure_fail.
* exact: not_in_failed_not_in.
* exact: in_failed_in.
* rewrite /=.
rewrite /l collate_tot_map_eq /tot_map_name_msgs.
by rewrite H_eq.
Qed.

(* Specifications: *)
Corollary step_ordered_dynamic_failure_tot_mapped_simulation_star_1 :
forall net failed tr,
@step_ordered_dynamic_failure_star _ _ overlay_fst new_msg_fst fail_msg_fst step_ordered_dynamic_failure_init (failed, net) tr ->
@step_ordered_dynamic_failure_star _ _ overlay_snd new_msg_snd fail_msg_snd step_ordered_dynamic_failure_init (map tot_map_name failed, tot_map_odnet net) (map tot_map_trace tr).