Library QedkConcrete.vmrun

Concrete VM loop invariants

The generated loop contains an arbitrary fallback if an instruction continues without decreasing gas. The pinned opcode-progress proof rules that branch out below the signed gas limit. Thus an invariant proved for each actual instruction carries through the loop, including error exits; no behavioral assumption about the whole VM is needed for this step.
From Stdlib Require Import NArith ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadExecutionSpecs.Termination.VmDispatchProgress.
Set Default Goal Selector "!".

Section Run.
  Context {Host_t : Set} {F : @MonadVM.Vm.Make.FArgs Host_t}.
  Context {E : @MonadVM.Vm.Make.Executor.FArgs Host_t F}.

  Let State := @MonadVM.Vm.Make.MachineState.t Host_t F.

  Local Abbreviation run := (@generated_run Host_t F E).
  Local Abbreviation step := (fun state : State ⇒
    @dispatch Host_t F E

      (@run_selected_opcode Host_t F E state) state).
  Local Abbreviation progress := (@run_selected_dispatch_guard_true Host_t F E).

This premise is an instruction-level proof obligation, not a new VM axiom. It will be discharged from Host effects and machine-local steps.
  Lemma run_preserves (invariant : State → Prop) (state : State) :
    ((@Vm.Make.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eight ∨
     (@Vm.Make.Params Host_t F).(Vm.Make_Params_signature.revision) = Support.Variants.Revision.Eleven) →
    (∀ before, (Z.of_N (Vm.Make.MachineState.t.gas before) < 2^63)%Z →
      invariant before → invariant (snd (step before))) →
    (Z.of_N (Vm.Make.MachineState.t.gas state) < 2^63)%Z →
    invariant state → invariant (snd (run state)).
  Proof.
    intros Hrevision Hstep.
    remember (Vm.Make.MachineState.t.gas state) as budget eqn:Hbudget.
    revert state Hbudget.
    induction budget as [budget IH] using (well_founded_induction N.lt_wf_0).
    intros state Hbudget Hbound Hinitial.
    rewrite Hbudget in Hbound.
    rewrite generated_run_step_eq. unfold generated_run_step.
    pose proof (Hstep state Hbound Hinitial) as Hafter.
    destruct (step state) as [[continue|err] next] eqn:Hdispatch.
    - destruct continue.
      + destruct (progress state next ltac:(tauto) Hbound Hdispatch) as [Hguard HnextBound].
        rewrite Hguard.
        apply (IH (Vm.Make.MachineState.t.gas next)).
        × unfold Gas.op_lt, Support.UintN.op_lt in Hguard. apply N.ltb_lt in Hguard. lia.
        × reflexivity.
        × exact HnextBound.
        × exact Hafter.
      + exact Hafter.
    - exact Hafter.
  Qed.
End Run.

Print Assumptions run_preserves.