Library QedkConcrete.contexthostinstance

Concrete Host obligations for the recursive VM proof

We extract the Host constructor supplied to the generated recursive-module assembly, rather than restating its callbacks in a replacement model.
Only the recursive VM invocation remains a premise; the concrete Host implementation, its precompiles and rollback have been discharged.
Lemma concrete_call_preserves_context vm msg :
  F.(Host.Instantiate.ChainParams).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
  (∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
    preservesContext (vm.(Evmc.Vm.SIG.execute) nested code)) →
  (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
  preservesContext ((HostF vm).(Evmc.HOST.call) msg).
Proof.
  intros Hrevision Hvm Hgas.
  exact (@call_preserves_context (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm) msg Hrevision Hvm Hgas).
Qed.

Lemma concrete_context_read_only vm s :
  snd ((HostF vm).(Evmc.HOST.get_tx_context) s) = s.
Proof. reflexivity. Qed.

Lemma concrete_primitives_preserve_format vm : PrimitiveHostFrame (HostF vm) hostFormat.
Proof.
  constructor; unfold preservesCallback; intros.
  all: cbn -[H.account_exists H.get_balance H.access_account H.get_storage
    H.set_storage H.access_storage H.get_transient_storage H.set_transient_storage
    H.get_code_size H.get_code_hash H.copy_code H.get_block_hash H.emit_log
    H.selfdestruct hostFormat].
  all: try assumption.
  all: try (rewrite copy_code_read_only; assumption).
  all: lazymatch goal with
  | |- hostFormat (snd (@H.set_storage _ _ _ _ _)) ⇒
    apply set_storage_preserves_format; assumption
  | |- hostFormat (snd (@H.set_transient_storage _ _ _ _ _)) ⇒
    apply set_transient_storage_preserves_format; assumption
  | |- hostFormat (snd (@H.selfdestruct _ _ _ _)) ⇒
    apply selfdestruct_preserves_format; assumption
  | _ ⇒ unfold H.access_account, H.access_storage;
    cbn -[hostFormat];
    match goal with |- context [if ?accessed then _ else _] ⇒ destruct accessed end;
    assumption
  end.
Qed.
Lemma concrete_call_preserves_format vm msg :
  F.(Host.Instantiate.ChainParams).(Chain.Monad.PARAMS.revision) = Support.Variants.Revision.Eleven →
  (∀ nested code, (0 ≤ Evmc.Message.t.gas nested < 2^63)%Z →
    preservesCallback hostFormat (vm.(Evmc.Vm.SIG.execute) nested code)) →
  (0 ≤ Evmc.Message.t.gas msg < 2^63)%Z →
  preservesCallback hostFormat ((HostF vm).(Evmc.HOST.call) msg).
Proof.
  intros Hrevision Hvm Hgas.
  exact (@call_preserves_format (H.Build_FArgs F.(Host.Instantiate.ChainParams) vm) msg Hrevision Hvm Hgas).
Qed.

End Instance.

Print Assumptions concrete_primitives_preserve_context.
Print Assumptions concrete_call_preserves_context.

Print Assumptions concrete_primitives_preserve_format.
Print Assumptions concrete_call_preserves_format.