Library QedkConcrete.transactionpersistentcode

Existing system-contract code through complete user transactions

Non-delegated code cannot be replaced by EIP-7702. The VM's CREATE collision check then prevents recreation, and EIP-6780 prevents deletion of an account not created in this transaction. Thus prescribed initial system code remains prescribed without a VM code-preservation assumption.
From Stdlib Require Import List String ZArith.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import QedkConcrete.transactioncode QedkConcrete.authorizationnonces
  QedkConcrete.executionpersistentcode.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
  (apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Import ListNotations.
Import authorization authorizationcode transactionhistory transactionstage persistentcode.
Local Open Scope Z_scope.
Module E := Execution.Make.
Module S := State.TransactionState.
Module B := State.BlockState.
Module W := State.WorldState.
Module A := Chain.Ethereum.Account.
Module T := Chain.Ethereum.Transaction.

Section Authorization.
Context {F : E.FArgs}.
Local Abbreviation readAccount := (fun world addr ⇒
  State.op_pointcaretlparenrparen world (@W.account None addr)).

Lemma authorization_rejects_contract s auth query :
  @A.is_smart_contract (readAccount (S.t.world_state s) query) = true →
  fst (@E.process_authorization F s auth) ≠ Some query.
Proof.
  intro Hsc. rewrite authorization_nonce_decision. unfold authorizationNonceStep.
  match goal with |- context [if ?test then _ else _] ⇒ destruct test end; [discriminate|].
  match goal with |- context [match ?recovered with Some _ ⇒ _ | None ⇒ _ end] ⇒
    destruct recovered as [authority|] end; [|discriminate].
  match goal with |- context [if ?test then _ else _] ⇒ destruct test eqn:Hvalid end; [|discriminate].
  intro Heq. injection Heq as <-.
  apply Bool.andb_true_iff in Hvalid as [Heligible _].
  rewrite Hsc in Heligible. discriminate.
Qed.

Lemma authorization_preserves_contract_code s auth query :
  stringmaps.WellFormed (W.t.accounts (S.t.world_state s)) →
  @A.is_smart_contract (readAccount (S.t.world_state s) query) = true →
  A.t.code (readAccount (S.t.world_state (snd (@E.process_authorization F s auth))) query) =
    A.t.code (readAccount (S.t.world_state s) query).
Proof.
  intros Hmap Hsc. pose proof (authorization_rejects_contract s auth query Hsc) as Hreject.
  pose proof (@authorization_code_effect F s auth query Hmap) as Hcode.
  cbv beta zeta in Hcode |- ×. rewrite Hcode.
  destruct (fst (@E.process_authorization F s auth)) as [authority|]; [|reflexivity].
  destruct (String.eqb authority query) eqn:Heq; [|reflexivity].
  apply String.eqb_eq in Heq. subst authority. contradiction.
Qed.

Lemma authorizations_preserve_contract_code auths authorities s query :
  stringmaps.WellFormed (W.t.accounts (S.t.world_state s)) →
  @A.is_smart_contract (readAccount (S.t.world_state s) query) = true →
  let result := Result.List.fold_left
    (fun '(applied, state) auth ⇒
      match @E.process_authorization F state auth with
      | (None, next) ⇒ (applied, next)
      | (Some authority, next) ⇒ (authority :: applied, next)
      end) (authorities, s) auths in
  A.t.code (readAccount (S.t.world_state (snd result)) query) =
    A.t.code (readAccount (S.t.world_state s) query).
Proof.
  revert authorities s. induction auths as [|auth auths IH]; intros authorities s Hmap Hsc.
  - reflexivity.
  - change (@Result.List.fold_left) with (@OCamlList.fold_left). cbn [OCamlList.fold_left].
    pose proof (@authorization_preserves_wellformed F s auth Hmap) as HnextMap.
    pose proof (authorization_preserves_contract_code s auth query Hmap Hsc) as Hcode.
    assert (HnextSc : @A.is_smart_contract (readAccount (S.t.world_state (snd (@E.process_authorization F s auth))) query) = true).
    { etransitivity; [apply (@executionreserve.contract_test_same_code); exact Hcode|exact Hsc]. }
    destruct (@E.process_authorization F s auth) as [[authority|] next];
      cbn beta iota zeta delta [fst snd] in HnextMap, Hcode, HnextSc |- ×.
    all: etransitivity; [apply IH; assumption|exact Hcode].
Qed.
End Authorization.

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

Local Abbreviation args := (@E.Instantiation_fargs F).
Local Abbreviation params := args.(Host.Instantiate.ChainParams).

Context {UI0 : Basics.Unreachable Support.UintN.Impl.t}
  {UB : Basics.Unreachable Bloom.t}
  {U8 : Basics.Unreachable Byte_string.B8.(Byte_string.Fixed.Fixed_result.t)}.

Local Abbreviation prefix := (@transactionPrefix F).
Local Abbreviation vmInput := (@transactionVmInput F).
Local Abbreviation callFromEoa := (@E.Host.call_from_eoa F).
Local Abbreviation processTransaction := (@E.process_transaction F).
Local Abbreviation readAccount := (fun world addr ⇒ State.op_pointcaretlparenrparen
  world (@W.account None addr)).

Lemma transaction_prefix_contract_code block tx validation query :
  stringmaps.WellFormed (W.t.accounts (B.t.world_state block)) →
  @A.is_smart_contract (readAccount (B.t.world_state block) query) = true →
  A.t.code (readAccount (S.t.world_state (snd (prefix block tx validation))) query) =
    A.t.code (readAccount (B.t.world_state block) query).
Proof.
  intros Hmap Hsc. unfold transactionPrefix.
  etransitivity; [apply authorizations_preserve_contract_code|].
  - apply worldaccounts.account_write_wellformed. exact Hmap.
  - etransitivity; [apply (@executionreserve.contract_test_same_code);
      apply fee_nonce_write_preserves_code; exact Hmap|exact Hsc].
  - apply fee_nonce_write_preserves_code. exact Hmap.
Qed.

Lemma transaction_vm_input_contract_code block tx validation query :
  stringmaps.WellFormed (W.t.accounts (B.t.world_state block)) →
  @A.is_smart_contract (readAccount (B.t.world_state block) query) = true →
  A.t.code (readAccount (S.t.world_state (snd (vmInput block tx validation))) query) =
    A.t.code (readAccount (B.t.world_state block) query).
Proof.
  intros Hmap Hsc.
  pose proof (transaction_prefix_contract_code block tx validation query Hmap Hsc) as Hprefix.
  unfold transactionVmInput. destruct (prefix block tx validation) as [authorities prepared].
  cbn beta iota zeta delta [fst snd] in Hprefix |- ×.
  change (A.t.code (readAccount
    (S.t.world_state (@E.bump_emptying_transaction_counters F authorities prepared)) query) =
    A.t.code (readAccount (B.t.world_state block) query)).
  unfold State.op_pointcaretlparenrparen, W.account, W.account_opt.
  cbn -[E.bump_emptying_transaction_counters Chain.Ethereum.Address.Map.find_opt].
  rewrite transactionsupply.bump_counters_accounts. exact Hprefix.
Qed.

Lemma authorization_preserves_creation_set s auth :
  S.t.accounts_created_in_current_transaction (snd (@E.process_authorization F s auth)) = S.t.accounts_created_in_current_transaction s.
Proof.
  unfold E.process_authorization.
  match goal with |- context [if ?b then _ else _] ⇒ destruct b end.
  { reflexivity. }
  match goal with |- context [match ?a with Some _ ⇒ _ | None ⇒ _ end] ⇒
    destruct a as [authority|] end.
  2: reflexivity.
  cbn beta iota zeta.
  match goal with |- context [if ?b then _ else _] ⇒ destruct b end.
  2: reflexivity.
  match goal with |- context [if ?b then _ else _] ⇒ destruct b end; reflexivity.
Qed.

Lemma authorizations_preserve_creation_set auths authorities s :
  S.t.accounts_created_in_current_transaction (snd (Result.List.fold_left
    (fun '(applied, state) auth ⇒
      match @E.process_authorization F state auth with
      | (None, next) ⇒ (applied, next)
      | (Some authority, next) ⇒ (authority :: applied, next)
      end) (authorities, s) auths)) = S.t.accounts_created_in_current_transaction s.
Proof.
  revert authorities s. induction auths as [|auth auths IH]; intros authorities s.
  - reflexivity.
  - change (@Result.List.fold_left) with (@OCamlList.fold_left).
    cbn [OCamlList.fold_left].
    pose proof (authorization_preserves_creation_set s auth) as Hdes.
    destruct (@E.process_authorization F s auth) as [[authority|] next]; cbn [snd] in Hdes.
    all: rewrite IH; exact Hdes.
Qed.

Lemma transaction_vm_input_no_creation block tx validation :
  S.t.accounts_created_in_current_transaction (snd (vmInput block tx validation)) = [].
Proof.
  assert (Hcreated : S.t.accounts_created_in_current_transaction
    (snd (prefix block tx validation)) = []).
  { unfold transactionPrefix. rewrite authorizations_preserve_creation_set. reflexivity. }
  unfold transactionVmInput. destruct (prefix block tx validation) as [authorities prepared].
  cbn beta iota zeta delta [fst snd] in Hcreated |- ×.
  exact Hcreated.
Qed.

Local Opaque Evmc.Instantiate._recursive_modules_Host_Vm.

This covers the entire transaction, including EIP-7702, nested calls, failed calls, fee credits and SELFDESTRUCT finalization. No signer or cryptographic creation premise is needed for an existing contract.
Theorem process_transaction_contract_code block tx validation post query :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  stringmaps.WellFormed (W.t.accounts (B.t.world_state block)) →
  @E.validate_transaction F block tx = inl validation →
  processTransaction block tx = inl post →
  @A.is_smart_contract (readAccount (B.t.world_state block) query) = true →
  A.t.code (readAccount (B.t.world_state post) query) =
    A.t.code (readAccount (B.t.world_state block) query).
Proof.
  intros Hrevision Hmap Hvalidation Hrun Hsc.
  pose proof (transaction_vm_input_contract_code block tx validation query Hmap Hsc) as Hcode.
  pose proof (@transaction_vm_input_wellformed F block tx validation Hmap) as HentryMap.
  pose proof (@transaction_vm_input_metadata F block tx validation) as Hmetadata.
  pose proof (transaction_vm_input_no_creation block tx validation) as Hcreation.
  assert (Hgas : 0 ≤ Evmc.Message.t.gas (fst (vmInput block tx validation)) < 2^63).
  { unfold transactionVmInput. destruct (prefix block tx validation) as [authorities prepared].
    cbn beta iota zeta delta [fst snd]. eapply validation.validated_message_gas. exact Hvalidation. }
  assert (Hnonempty : A.t.code (readAccount (B.t.world_state block) query) ≠ Byte_string.Bytes.empty).
  { unfold A.is_smart_contract in Hsc. apply Bool.andb_true_iff in Hsc as [HcodePresent _].
    intro Heq. cbv beta in Heq, HcodePresent.
    match type of Heq with ?code = _ ⇒
      change (Byte_string.Bytes.op_ltgt code Byte_string.Bytes.empty = true) in HcodePresent
    end.
    rewrite Heq in HcodePresent. discriminate. }
  pose proof (process_transaction_retains_host_code block tx validation post
    Hrevision Hmap Hvalidation Hrun) as Hfinal.
  destruct (vmInput block tx validation) as [msg entry].
  cbn beta iota zeta delta [fst snd] in HentryMap, Hmetadata, Hcreation, Hcode, Hgas, Hfinal.
  assert (Hentry : @persistentCode query
    (A.t.code (readAccount (B.t.world_state block) query)) entry).
  { constructor; [exact HentryMap|exact Hcode|rewrite Hcreation; tauto|
      rewrite (proj2 (proj2 (proj2 Hmetadata))); tauto]. }
  pose proof (@execution_call_from_eoa_preserves_existing_code F
    query (A.t.code (readAccount (B.t.world_state block) query))
    tx msg Hnonempty Hrevision Hgas entry Hentry) as Hafter.
  etransitivity.
  - apply Hfinal. exact (persistent_code_undestroyed _ _ _ Hafter).
  - exact (persistent_code_value _ _ _ Hafter).
Qed.

Lemma delete_accounts_map block addresses :
  stringmaps.WellFormed (W.t.accounts (B.t.world_state block)) →
  stringmaps.WellFormed (W.t.accounts (B.t.world_state (OCamlSeq.fold_left
    (fun s addr ⇒ State.op_pointcaretlparenrparenltminus s
      (@B.account_opt None addr) None) block (OCamlSeq.of_list addresses)))).
Proof.
  revert block. induction addresses as [|addr addresses IH]; intros block Hmap.
  - exact Hmap.
  - cbn [OCamlSeq.of_list OCamlSeq.fold_left]. apply IH.
    apply stringmaps.remove_wellformed. exact Hmap.
Qed.

Lemma process_transaction_account_map block tx validation post :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  stringmaps.WellFormed (W.t.accounts (B.t.world_state block)) →
  @E.validate_transaction F block tx = inl validation →
  processTransaction block tx = inl post →
  stringmaps.WellFormed (W.t.accounts (B.t.world_state post)).
Proof.
  intros Hrevision Hmap Hvalidation Hrun.
  pose proof (@transaction_vm_input_wellformed F block tx validation Hmap) as Hbefore.
  unfold E.process_transaction in Hrun. rewrite Hvalidation in Hrun.
  change (@Result.op_letdollar) with
    (fun (A B C : Set) (r : A + B) (f : A → C + B) ⇒
      match r with inl value ⇒ f value | inr error ⇒ inr error end) in Hrun.
  cbn beta iota zeta delta [E.transaction_validation.sender E.transaction_validation.total_fee
    E.transaction_validation.intrinsic_gas E.transaction_validation.effective_gas_price] in Hrun.
  match type of Hrun with context [Result.List.fold_left ?f ?start (T.authorization_list tx)] ⇒
    change (Result.List.fold_left f start (T.authorization_list tx)) with (prefix block tx validation) in Hrun
  end.
  unfold transactionVmInput in Hbefore |- ×.
  destruct (prefix block tx validation) as [authorities prepared].
  cbn beta iota zeta delta [fst snd] in Hbefore, Hrun |- ×.
  match type of Hrun with context [@S.initialize_access_sets tx ?s ?precompiles] ⇒
    set (beforeVm := @S.initialize_access_sets tx s precompiles) in ×
  end.
  match type of Hrun with context [E.Host.call_from_eoa tx ?message beforeVm] ⇒
    set (msg := message) in ×
  end.
  pose proof (@validation.validated_message_gas F block tx validation (S.t.world_state beforeVm) Hvalidation) as Hgas.
  change (0 ≤ Evmc.Message.t.gas msg < 2^63) in Hgas.
  pose proof (@executioncreation.execution_call_from_eoa_preserves_creation F
    tx msg Hrevision Hgas beforeVm Hbefore) as Hafter.

  destruct (callFromEoa tx msg beforeVm) as [result afterVm].
  cbn beta iota zeta delta [fst snd] in Hafter, Hrun |- ×.
  change (@Result._return) with (fun (A B : Set) (value : A) ⇒ @inl A B value) in Hrun.
  injection Hrun as <-.
  cbn beta iota zeta delta [B.t.with_transactions_processed B.t.with_gas_used B.t.world_state].
  change (@Result.Seq.fold_left) with (@OCamlSeq.fold_left).
  apply delete_accounts_map. apply stringmaps.update_wellformed. exact (proj1 Hafter).
Qed.

Theorem transactions_contract_code query txs :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  ∀ block post,
  stringmaps.WellFormed (W.t.accounts (B.t.world_state block)) →
  @A.is_smart_contract (readAccount (B.t.world_state block) query) = true →
  Result.List.fold_leftM processTransaction block txs = inl post →
  stringmaps.WellFormed (W.t.accounts (B.t.world_state post)) ∧
  A.t.code (readAccount (B.t.world_state post) query) =
    A.t.code (readAccount (B.t.world_state block) query).
Proof.
  intro Hrevision. induction txs as [|tx rest IH]; intros block post Hmap Hsc Hrun.
  - cbn [Result.List.fold_leftM] in Hrun. injection Hrun as <-. split; [exact Hmap|reflexivity].
  - change (Result.op_letdollar (processTransaction block tx)
      (fun next ⇒ Result.List.fold_leftM processTransaction next rest) = inl post) in Hrun.
    destruct (processTransaction block tx) as [next|error] eqn:Hstep; [|discriminate Hrun].
    assert (Hvalid : ∃ validation, @E.validate_transaction F block tx = inl validation).
    { unfold E.process_transaction in Hstep.
      destruct (@E.validate_transaction F block tx) as [validation|failure];
        [∃ validation; reflexivity|discriminate Hstep]. }
    destruct Hvalid as [validation Hvalidation].
    pose proof (process_transaction_contract_code block tx validation next query
      Hrevision Hmap Hvalidation Hstep Hsc) as Hcode.
    pose proof (process_transaction_account_map block tx validation next
      Hrevision Hmap Hvalidation Hstep) as HnextMap.
    assert (HnextSc : @A.is_smart_contract (readAccount (B.t.world_state next) query) = true).
    { etransitivity; [apply (@executionreserve.contract_test_same_code); exact Hcode|exact Hsc]. }
    destruct (IH next post HnextMap HnextSc Hrun) as [HpostMap HpostCode].
    split; [exact HpostMap|etransitivity; eassumption].
Qed.

Local Lemma bind_success {A B Error : Set}
    (first : A + Error) (next : A → B + Error) value :
  MonadVM.Result.op_letdollar first next = inl value →
  ∃ intermediate, first = inl intermediate ∧ next intermediate = inl value.
Proof.
  destruct first; cbn; [intro H; eexists; split; [reflexivity|exact H]|discriminate].
Qed.

Local Lemma validated_monad_system_transaction_call_kind block tx sender available_gas world :
  @E.validate_monad_system_transaction F block tx sender = inl tt →
  Evmc.Message.t.kind (@E.prepare_message F sender available_gas tx world) =
    Evmc.Message.CallKind.Call.
Proof.
  intro Hvalidated. unfold E.validate_monad_system_transaction in Hvalidated.
  cbn zeta in Hvalidated.
  do 3 (apply bind_success in Hvalidated;
    let step := fresh "step" in let Hstep := fresh "Hstep" in
    destruct Hvalidated as [step [Hstep Hvalidated]];
    cbn beta iota zeta in Hvalidated).
  destruct tx as [tx_impl| | |]; [|cbn in Hstep0; discriminate Hstep0..].
  cbn in Hstep0. injection Hstep0 as <-.
  destruct tx_impl. cbn in Hstep1 |- ×.
  match type of Hstep1 with match ?o with Some _ ⇒ _ | None ⇒ _ end = inl _ ⇒
    destruct o; [reflexivity|discriminate Hstep1]
  end.
Qed.

Theorem process_monad_system_transaction_contract_code block tx post query :
  stringmaps.WellFormed (W.t.accounts (B.t.world_state block)) →
  @A.is_smart_contract (readAccount (B.t.world_state block) query) = true →
  @E.process_monad_system_transaction F block tx = inl post →
  stringmaps.WellFormed (W.t.accounts (B.t.world_state post)) ∧
  A.t.code (readAccount (B.t.world_state post) query) =
    A.t.code (readAccount (B.t.world_state block) query).
Proof.
  intros Hmap Hsc Hrun. unfold E.process_monad_system_transaction in Hrun.
  destruct (@E.validate_monad_system_transaction F block tx Chain.Monad.system_sender)
    as [[]|error] eqn:Hvalidation; [|discriminate Hrun].
  change (@Result.op_letdollar) with
    (fun (A B C : Set) (r : A + B) (f : A → C + B) ⇒
      match r with inl value ⇒ f value | inr error ⇒ inr error end) in Hrun.
  cbn beta iota zeta in Hrun.
  set (sender := Chain.Monad.system_sender) in ×.
  match type of Hrun with context [@S.initialize_access_sets tx ?charged ?precompiles] ⇒
    set (beforeVm := @S.initialize_access_sets tx charged precompiles) in ×
  end.
  assert (HbeforeMap : stringmaps.WellFormed (W.t.accounts (S.t.world_state beforeVm))).
  { apply worldaccounts.account_write_wellformed. exact Hmap. }
  assert (HbeforeCode : A.t.code (readAccount (S.t.world_state beforeVm) query) =
    A.t.code (readAccount (B.t.world_state block) query)).
  { eapply hostcode.account_write_same_code; [exact Hmap|reflexivity]. }
  assert (Hentry : @persistentCode query
    (A.t.code (readAccount (B.t.world_state block) query)) beforeVm).
  { constructor; [exact HbeforeMap|exact HbeforeCode|cbn; tauto|cbn; tauto]. }
  match type of Hrun with context [E.Host.call_from_monad_system_transaction ?message beforeVm] ⇒
    pose proof (validated_monad_system_transaction_call_kind block tx sender Gas.zero
      (S.t.world_state beforeVm) Hvalidation) as Hkind;
    pose proof (@execution_call_from_monad_system_transaction_preserves_existing_code F
      query (A.t.code (readAccount (B.t.world_state block) query))
      message Hkind beforeVm Hentry) as Hafter;
    destruct (E.Host.call_from_monad_system_transaction message beforeVm) as [result afterVm]
  end.
  cbn [snd] in Hafter.
  unfold Result.when_ in Hrun.
  destruct (negb (Evmc.Result.StatusCode.is_success (Evmc.Result.t.status_code result)));
    [discriminate Hrun|].
  injection Hrun as <-.
  split; [exact (persistent_code_map _ _ _ Hafter)|exact (persistent_code_value _ _ _ Hafter)].
Qed.

Theorem dispatch_transaction_contract_code block tx post query :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  stringmaps.WellFormed (W.t.accounts (B.t.world_state block)) →
  @A.is_smart_contract (readAccount (B.t.world_state block) query) = true →
  @E.dispatch_transaction F block tx = inl post →
  stringmaps.WellFormed (W.t.accounts (B.t.world_state post)) ∧
  A.t.code (readAccount (B.t.world_state post) query) =
    A.t.code (readAccount (B.t.world_state block) query).
Proof.
  intros Hrevision Hmap Hsc Hrun.
  destruct (transactionformat.dispatch_transaction_cases block tx post Hrun)
    as [[sender [_ Hstep]] | [_ Hstep]].
  - assert (Hvalid : ∃ validation, @E.validate_transaction F block tx = inl validation).
    { unfold E.process_transaction in Hstep.
      destruct (@E.validate_transaction F block tx) as [validation|failure];
        [∃ validation; reflexivity|discriminate Hstep]. }
    destruct Hvalid as [validation Hvalidation].
    split.
    + exact (process_transaction_account_map block tx validation post Hrevision Hmap Hvalidation Hstep).
    + exact (process_transaction_contract_code block tx validation post query Hrevision Hmap Hvalidation Hstep Hsc).
  - exact (process_monad_system_transaction_contract_code block tx post query Hmap Hsc Hstep).
Qed.

Theorem dispatched_transactions_contract_code query txs :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  ∀ block post,
  stringmaps.WellFormed (W.t.accounts (B.t.world_state block)) →
  @A.is_smart_contract (readAccount (B.t.world_state block) query) = true →
  Result.List.fold_leftM (@E.dispatch_transaction F) block txs = inl post →
  stringmaps.WellFormed (W.t.accounts (B.t.world_state post)) ∧
  A.t.code (readAccount (B.t.world_state post) query) =
    A.t.code (readAccount (B.t.world_state block) query).
Proof.
  intro Hrevision. induction txs as [|tx rest IH]; intros block post Hmap Hsc Hrun.
  - cbn [Result.List.fold_leftM] in Hrun. injection Hrun as <-. split; [exact Hmap|reflexivity].
  - change (Result.op_letdollar (@E.dispatch_transaction F block tx)
      (fun next ⇒ Result.List.fold_leftM (@E.dispatch_transaction F) next rest) = inl post) in Hrun.
    destruct (@E.dispatch_transaction F block tx) as [next|error] eqn:Hstep; [|discriminate Hrun].
    destruct (dispatch_transaction_contract_code block tx next query Hrevision Hmap Hsc Hstep)
      as [HnextMap Hcode].
    assert (HnextSc : @A.is_smart_contract (readAccount (B.t.world_state next) query) = true).
    { etransitivity; [apply (@executionreserve.contract_test_same_code); exact Hcode|exact Hsc]. }
    destruct (IH next post HnextMap HnextSc Hrun) as [HpostMap HpostCode].
    split; [exact HpostMap|etransitivity; eassumption].
Qed.
End Execution.
Print Assumptions process_transaction_contract_code.
Print Assumptions transactions_contract_code.