Library QedkConcrete.executionchecked

Supply safety of Execution's recursive VM and Host

This closes the recursive-call obligations using the generated module assembly. Native-output bounds remain a separate obligation; the corrected integer allocation guard eliminates the former comparison alternative.
From Stdlib Require Import ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Execution MonadVM.Vm QedkConcrete.hostframe
  QedkConcrete.contexthostinstance QedkConcrete.executioncontext
  QedkConcrete.assemblychecked QedkConcrete.vmsupplyentry QedkConcrete.hostchecked
  QedkConcrete.hostcallchecked QedkConcrete.vmsupplywords QedkConcrete.vmcallchecked QedkConcrete.hashwords.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
  (apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.

Module E := Execution.Make.
Module V := Vm.Make.

Section Execution.
Context {F : E.FArgs}.

Local Abbreviation args := (@E.Instantiation_fargs F).

Context (limit : Z).
Local Abbreviation HostF := (@Evmc.Instantiate.HostF S.t (@recursiveArgs args)).
Local Abbreviation VmF := (@Evmc.Instantiate.VmF S.t (@recursiveArgs args)).

Lemma execution_vm_constructor_checked vm :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  keccak256OutputSize → @nativeOutputBounds args →
  @checkedVm args limit vm → @checkedVm args limit (VmF (HostF vm)).
Proof.
  intros Hrevision Hhash Hnative Hvm msg code Hmsg Hcode initial Hinitial.
  cbn -[V.execute hostSupplyContext resultOutputBound].
  eapply (@execute_preserves_supply_context_from_child args vm _ limit);
    try solve [lazymatch goal with |- Basics.Unreachable _ ⇒
      apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat end].
  - exact Hrevision.
  - reflexivity.
  - exact Hhash.
  - exact Hmsg.
  - exact Hcode.
  - intros child Hchild before Hbefore.
    exact (@host_constructor_checked args limit vm Hrevision Hnative Hvm child Hchild before Hbefore).
  - exact Hinitial.
Qed.

Theorem execution_vm_checked :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  keccak256OutputSize → @nativeOutputBounds args →
  @checkedVm args limit (@Evmc.Instantiate.Vm S.t (@recursiveArgs args)).
Proof.
  intros Hrevision Hhash Hnative.
  apply (proj1 (@recursive_assembly_checked args limit Hrevision Hnative
    (fun vm ⇒ execution_vm_constructor_checked vm Hrevision Hhash Hnative))).
Qed.
Local Opaque Evmc.Instantiate._recursive_modules_Host_Vm.
Local Abbreviation invariant := (hostSupplyContext args.(Host.Instantiate.ChainParams) limit).

Covers the external transaction entry, including its reserve-check rollback, rather than only calls made by VM instructions.
Theorem execution_call_from_eoa_checked tx msg :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  keccak256OutputSize → @nativeOutputBounds args →
  @vmMessageBounds msg →
  hostChecked invariant resultOutputBound (@E.Host.call_from_eoa F
    tx msg).
Proof.
  intros Hrevision Hhash Hnative Hmsg.
  unfold E.Host.call_from_eoa.
  cbv beta iota zeta delta [E.Instantiation Host.Instantiate.functor
    Host.Instantiate.Instantiate_result.Host Host.Instantiate.Host
    H.functor H.Make_result.call_from_eoa H.call_from_eoa].
  eapply (@call_impl_preserves_checked args
    (@H.Vm (@Host.Instantiate.Host_fargs args)) limit (Some tx) msg).
  - exact Hrevision.
  - exact (execution_vm_checked Hrevision Hhash Hnative).
  - intros nested addr action Hnested Hselected before [[[_ _] Hformat] _].
    exact (Hnative _ nested addr action Hnested Hselected before Hformat).
  - exact Hmsg.
Qed.

System messages call this entry without the outer transaction wrapper.
Theorem execution_call_checked msg :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  keccak256OutputSize → @nativeOutputBounds args →
  @vmMessageBounds msg →
  hostChecked invariant resultOutputBound (@E.Host.call F
    msg).
Proof.
  intros Hrevision Hhash Hnative Hmsg.
  unfold E.Host.call.
  cbv beta iota zeta delta [E.Instantiation Host.Instantiate.functor
    Host.Instantiate.Instantiate_result.Host Host.Instantiate.Host
    H.functor H.Make_result.call].
  eapply (@call_preserves_checked args
    (@H.Vm (@Host.Instantiate.Host_fargs args)) limit).
  - exact Hrevision.
  - exact (execution_vm_checked Hrevision Hhash Hnative).
  - intros nested addr action Hnested Hselected before [[[_ _] Hformat] _].
    exact (Hnative _ nested addr action Hnested Hselected before Hformat).
  - exact Hmsg.
Qed.
No recursive-call or memory-comparison premise remains here. Native output lengths still need to be discharged before using this as an unconditional conservation theorem.
Theorem execution_call_from_eoa_supply_and_output tx msg initial :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  keccak256OutputSize → @nativeOutputBounds args →
  @vmMessageBounds msg → invariant initial →
  let result := @E.Host.call_from_eoa F
    tx msg initial in
  invariant (snd result) ∧ resultOutputBound (fst result).
Proof.
  intros Hrevision Hhash Hnative Hmsg Hinitial.
  eapply host_checked_sound; [|exact Hinitial].
  exact (execution_call_from_eoa_checked tx msg Hrevision Hhash Hnative Hmsg).
Qed.

Theorem execution_call_supply_and_output msg initial :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  keccak256OutputSize → @nativeOutputBounds args →
  @vmMessageBounds msg → invariant initial →
  let result := @E.Host.call F
    msg initial in
  invariant (snd result) ∧ resultOutputBound (fst result).
Proof.
  intros Hrevision Hhash Hnative Hmsg Hinitial.
  eapply host_checked_sound; [|exact Hinitial].
  exact (execution_call_checked msg Hrevision Hhash Hnative Hmsg).
Qed.
End Execution.

Print Assumptions execution_vm_checked.

Print Assumptions execution_call_from_eoa_checked.
Print Assumptions execution_call_checked.

Print Assumptions execution_call_from_eoa_supply_and_output.
Print Assumptions execution_call_supply_and_output.