Library MonadExecutionSpecs.Termination.Staking

Termination of staking's bounded traversals. The countdown is positive at every recursive call, so subtraction never selects its fallback.
From Stdlib Require Import NArith Lia.
Require Import MonadExecutionSpecs.Termination.Natural.
Require Import MonadVM.Support.UintN.

Lemma uint_countdown_decreases count :
  count ≠ 0%N →
  (n_rank (UintN.op_minus count UintN.one) < n_rank count)%nat.
Proof.
  intro Hcount. apply n_rank_strict.
  unfold UintN.op_minus, UintN.one.
  destruct (N.leb_spec 1 count); lia.
Qed.

Ltac solve_countdown_decrease :=
  Natural.expose_generated_measure;
  Natural.simplify_uintn;
  Natural.derive_n_boolean_facts;
  apply uint_countdown_decreases;
  match goal with
  | guard : UintN.op_eq ?count UintN.zero = false |- ?count ≠ 0%N ⇒
      apply N.eqb_neq; exact guard
  | guard : ?count ≠ 0%N |- ?count ≠ 0%N ⇒ exact guard
  end.

Print Assumptions uint_countdown_decreases.