Library QedkConcrete.transactioncode

Signer code through concrete transaction finalization

The VM may install contract code only at recorded creation addresses. Authorization processing, beneficiary credits and SELFDESTRUCT deletion must also be accounted for before that fact can support the next transaction's reserve proof. The code/history results need no VM output-size bound; their nondebit corollary reuses the existing balance-proof bounds.
From Stdlib Require Import List String ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Execution QedkConcrete.transactionstage
  QedkConcrete.authorizationcode QedkConcrete.transactionhistory
  QedkConcrete.executioncreation QedkConcrete.transactionfinalize.
Require Import QedkConcrete.nativeinputs.
Set Default Goal Selector "!".
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
  (apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.
Import ListNotations.
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 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_vm_input_wellformed block tx validation :
  stringmaps.WellFormed (W.t.accounts (B.t.world_state block)) →
  stringmaps.WellFormed (W.t.accounts (S.t.world_state (snd (vmInput block tx validation)))).
Proof.
  intro Hmap.
  assert (Hprefix : stringmaps.WellFormed (W.t.accounts (S.t.world_state
    (snd (prefix block tx validation))))).
  { unfold transactionPrefix.
    match goal with |- context [Result.List.fold_left _ ([], ?charged) _] ⇒
      apply (proj1 (@authorization.authorizations_preserve_balances F
        (T.authorization_list tx) [] charged ltac:(apply worldaccounts.account_write_wellformed; exact Hmap)))
    end. }
  unfold transactionVmInput. destruct (prefix block tx validation) as [authorities prepared].
  cbn beta iota zeta delta [fst snd] in Hprefix |- ×.
  change (stringmaps.WellFormed (W.t.accounts (S.t.world_state
    (@E.bump_emptying_transaction_counters F authorities prepared)))).
  rewrite transactionsupply.bump_counters_accounts. exact Hprefix.
Qed.

Lemma balance_write_preserves_code world keep addr balance query :
  stringmaps.WellFormed (W.t.accounts world) →
  A.t.code (readAccount (State.op_pointcaretlparenrparenltminus world
    (@W.account (Some keep) addr) (A.t.with_balance balance (readAccount world addr))) query) =
  A.t.code (readAccount world query).
Proof.
  intro Hmap. cbv beta. rewrite code_after_account_write by exact Hmap.
  destruct (String.eqb addr query) eqn:Heq; [apply String.eqb_eq in Heq; subst query|]; reflexivity.
Qed.

Finalization cannot change a surviving account's code, even if the beneficiary is that account. Empty-account normalization is harmless: an account removed that way already had empty code.
Theorem process_transaction_retains_host_code 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 →
  let '(msg, entry) := vmInput block tx validation in
  let afterVm := snd (callFromEoa tx msg entry) in
  ∀ query, ¬ List.In query (S.t.self_destruct afterVm) →
    A.t.code (readAccount (B.t.world_state post) query) =
    A.t.code (readAccount (S.t.world_state afterVm) query).
Proof.
  intros Hrevision Hmap Hvalidation Hrun.
  pose proof (transaction_vm_input_wellformed 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 (@execution_call_from_eoa_preserves_creation F
    tx msg Hrevision Hgas beforeVm Hbefore) as Hafter.
  change (∀ query, ¬ List.In query (S.t.self_destruct (snd (callFromEoa tx msg beforeVm))) →
    A.t.code (readAccount (B.t.world_state post) query) =
    A.t.code (readAccount (S.t.world_state (snd (callFromEoa tx msg beforeVm))) query)).
  destruct (callFromEoa tx msg beforeVm) as [result afterVm] eqn:Hcall.
  cbn beta iota zeta delta [fst snd] in Hafter, Hrun |- ×.
  intros query HnotDeleted. destruct Hafter as [HafterMap Hframe].
  assert (HcounterMap : stringmaps.WellFormed (W.t.accounts (S.t.world_state
    (@E.bump_emptying_transaction_counters F [E.transaction_validation.sender validation] afterVm)))).
  { rewrite transactionsupply.bump_counters_accounts. exact HafterMap. }
  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).
  match goal with |- context [OCamlSeq.fold_left ?f ?credited ?addresses] ⇒
    assert (HcreditMap : stringmaps.WellFormed (W.t.accounts (B.t.world_state credited))) by
      (apply stringmaps.update_wellformed; exact HafterMap);
    pose proof (@delete_accounts_preserves_other credited (S.t.self_destruct afterVm)
      query HcreditMap HnotDeleted) as [_ Hread]
  end.
  etransitivity; [exact (f_equal A.t.code Hread)|].
  etransitivity.
  - match goal with |- context [A.t.with_balance ?balance _] ⇒
      exact (balance_write_preserves_code (S.t.world_state
        (@E.bump_emptying_transaction_counters F [E.transaction_validation.sender validation] afterVm))
        false (Chain.Ethereum.Block.Header.t.beneficiary
          (Chain.Ethereum.Block.t.header (B.t.current_block block))) balance query HcounterMap)
    end.
  - reflexivity.
Qed.

A signer excluded from contract creation keeps exactly the code produced by authorization processing, including when the VM reverts.
Theorem process_transaction_noncreated_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 →
  let '(msg, entry) := vmInput block tx validation in
  ¬ List.In query (S.t.accounts_created_in_current_transaction (snd (callFromEoa tx msg entry))) →
  A.t.code (readAccount (B.t.world_state post) query) =
    A.t.code (readAccount (S.t.world_state entry) query).
Proof.
  intros Hrevision Hmap Hvalidation Hrun.
  pose proof (process_transaction_retains_host_code block tx validation post Hrevision Hmap Hvalidation Hrun) as Hfinal.
  pose proof (transaction_vm_input_wellformed block tx validation Hmap) as Hentry.
  pose proof (@transaction_vm_input_metadata F block tx validation) as Hmetadata.
  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. }
  destruct (vmInput block tx validation) as [msg entry].
  cbn beta iota zeta delta [fst snd] in Hfinal, Hentry, Hmetadata, Hgas |- ×.
  intro Hcreated.
  destruct (@execution_call_from_eoa_preserves_creation F
    tx msg Hrevision Hgas entry Hentry) as [_ Hframe].
  assert (HnotDeleted : ¬ List.In query (S.t.self_destruct (snd (callFromEoa tx msg entry)))).
  { intro Hin. destruct (hostcode.destruction_covered _ _ Hframe query Hin) as [Hbefore|Hnew].
    - rewrite (proj2 (proj2 (proj2 Hmetadata))) in Hbefore. contradiction.
    - exact (Hcreated Hnew). }
  etransitivity; [apply Hfinal; exact HnotDeleted|].
  exact (hostcode.noncreated_code _ _ Hframe query Hcreated).
Qed.

Corollary process_transaction_noncontract 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)) →
  Forall (fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20) (T.authorization_list tx) →
  @E.validate_transaction F block tx = inl validation →
  processTransaction block tx = inl post →
  @A.is_smart_contract (readAccount (B.t.world_state block) query) = false →
  let '(msg, entry) := vmInput block tx validation in
  ¬ List.In query (S.t.accounts_created_in_current_transaction (snd (callFromEoa tx msg entry))) →
  @A.is_smart_contract (readAccount (B.t.world_state post) query) = false.
Proof.
  intros Hrevision Hmap Hwidth Hvalidation Hrun Hsc.
  pose proof (process_transaction_noncreated_code block tx validation post query Hrevision Hmap Hvalidation Hrun) as Hcode.
  pose proof (@transaction_vm_input_noncontract F block tx validation query Hmap Hwidth Hsc) as Hentry.
  destruct (vmInput block tx validation) as [msg entry].
  cbn beta iota zeta delta [fst snd] in Hcode, Hentry |- ×.
  intro Hcreated. specialize (Hcode Hcreated).
  exact (eq_trans (@executionreserve.contract_test_same_code
    (readAccount (S.t.world_state entry) query) (readAccount (B.t.world_state post) query) Hcode) Hentry).
Qed.

Corollary process_transaction_other_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 →
  ¬ List.In query (fst (prefix block tx validation)) →
  let '(msg, entry) := vmInput block tx validation in
  ¬ List.In query (S.t.accounts_created_in_current_transaction (snd (callFromEoa tx msg entry))) →
  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 Hauth.
  pose proof (process_transaction_noncreated_code block tx validation post query Hrevision Hmap Hvalidation Hrun) as Hcode.
  pose proof (@transaction_vm_input_other_code F block tx validation query Hmap Hauth) as Hentry.
  destruct (vmInput block tx validation) as [msg entry].
  cbn beta iota zeta delta [fst snd] in Hcode, Hentry |- ×.
  intro Hcreated. exact (eq_trans (Hcode Hcreated) Hentry).
Qed.

Local Abbreviation readCounter := (fun world query ⇒ State.op_pointcaretlparenrparen
  world (@W.next_emptying_transaction_block_for query)).
Local Abbreviation blockNumber := (fun block ⇒ Chain.Ethereum.Block.Header.t.number
  (Chain.Ethereum.Block.t.header (B.t.current_block block))).

A counter allowing emptying before this transaction's K-block expiry proves that this transaction neither came from the account nor applied an authorization for it. This conclusion uses the actual authorization fold, including its nonce checks, rather than treating all signed entries as applied.
Lemma process_transaction_recent_counter_excludes_activity block tx validation post query future :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  stringmaps.WellFormed (W.t.next_emptying_transaction_block (B.t.world_state block)) →
  @E.validate_transaction F block tx = inl validation →
  processTransaction block tx = inl post →
  (future < blockNumber block + 3)%N →
  (readCounter (B.t.world_state post) query ≤ future)%N →
  query ≠ E.transaction_validation.sender validation ∧
  ¬ List.In query (fst (prefix block tx validation)) ∧
  readCounter (B.t.world_state post) query = readCounter (B.t.world_state block) query.
Proof.
  intros Hrevision Hmap Hvalidation Hrun Hfuture Hcounter.
  destruct (@process_transaction_activity_history F
    block tx validation post Hrevision Hmap Hvalidation Hrun)
    as [_ [_ Hhistory]].
  specialize (Hhistory query).
  change (@Reserve_balance.execution_consensus_delay) with 3%N in Hhistory.
  change (readCounter (B.t.world_state post) query =
    if existsb (fun addr ⇒ String.eqb addr query)
      (E.transaction_validation.sender validation :: fst (prefix block tx validation))
    then (blockNumber block + 3)%N else readCounter (B.t.world_state block) query) in Hhistory.
  destruct (existsb (fun addr ⇒ String.eqb addr query)
    (E.transaction_validation.sender validation :: fst (prefix block tx validation))) eqn:Hmentions.
  { lia. }
  assert (Habsent : ¬ List.In query
    (E.transaction_validation.sender validation :: fst (prefix block tx validation))).
  { intro Hin. assert (Htrue : existsb (fun addr ⇒ String.eqb addr query)
      (E.transaction_validation.sender validation :: fst (prefix block tx validation)) = true).
    { apply existsb_exists. ∃ query. split; [exact Hin|apply String.eqb_refl]. }
    congruence. }
  split; [intro Heq; apply Habsent; left; congruence|].
  split; [intro Hin; apply Habsent; right; exact Hin|exact Hhistory].
Qed.

Lemma noncontract_undelegated_empty_code account :
  @A.is_smart_contract account = false →
  @Delegation.is_valid_delegation (A.t.code account) = false →
  A.t.code account = Byte_string.Bytes.empty.
Proof.
  intros Hsc Hdelegated.
  change (andb (Byte_string.Bytes.op_ltgt (A.t.code account) Byte_string.Bytes.empty)
    (negb (@Delegation.is_valid_delegation (A.t.code account))) = false) in Hsc.
  rewrite Hdelegated, Bool.andb_true_r in Hsc.
  change (negb (Z.eqb (OCamlString.compare (A.t.code account) String.EmptyString) 0) = false) in Hsc.
  apply Bool.negb_false_iff, Z.eqb_eq in Hsc.
  apply reservecheck.address_compare_eq. exact Hsc.
Qed.

This is the concrete counterpart of the emptying-balance invariant: if an account can still empty in this transaction's unexecuted window, this transaction did not reduce its balance. Nonsender status, absence of applied authorizations, and empty entry code are conclusions, not extra premises. Creation at the signer remains excluded cryptographically.
Theorem process_transaction_future_emptying_nondebit block tx validation post query future :
  MonadVM.Staking.staking_address ≠ query →
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  hashwords.keccak256OutputSize → @assemblychecked.nativeOutputBounds args →
  wordrange.wordRange (Support.UintN.to_z (Chain.Monad.PARAMS.chain_id params)) →
  transactionchecked.headerWords (Chain.Ethereum.Block.t.header (B.t.current_block block)) →
  supply.balanceInvariant (B.t.world_state block) → hostaccountformat.worldFormat (B.t.world_state block) →
  stringmaps.WellFormed (W.t.next_emptying_transaction_block (B.t.world_state block)) →
  Forall (fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20) (T.authorization_list tx) →
  transactionValueAndDataBounds tx →
  @E.validate_transaction F block tx = inl validation →
  processTransaction block tx = inl post →
  @A.is_smart_contract (readAccount (B.t.world_state block) query) = false →
  (future < blockNumber block + 3)%N →
  (readCounter (B.t.world_state post) query ≤ future)%N →
  @Delegation.is_valid_delegation (A.t.code (readAccount (B.t.world_state post) query)) = false →
  let '(msg, entry) := vmInput block tx validation in
  ¬ List.In query (S.t.accounts_created_in_current_transaction (snd (callFromEoa tx msg entry))) →
  Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state block) query)) ≤
  Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state post) query)).
Proof using F U8 UB UI0.
  intros Hnot_staking Hrevision Hhash Hnative Hchain Hheader Hbalance Hformat Hcounters Hwidth Hvalue
    Hvalidation Hrun Hsc Hfuture Hcounter Hdelegated.
  destruct (process_transaction_recent_counter_excludes_activity block tx validation post query future
    Hrevision Hcounters Hvalidation Hrun Hfuture Hcounter) as [Hsender [Hauth Hhistory]].
  pose proof (process_transaction_other_code block tx validation post query Hrevision (proj1 Hbalance)
    Hvalidation Hrun Hauth) as Hcode.
  pose proof (@process_transaction_nonsender_nondebit F UI0 UB U8
    block tx validation post query Hnot_staking Hrevision Hhash Hnative
    Hchain Hheader Hbalance Hformat Hwidth Hvalue Hvalidation Hrun) as Hbound.
  destruct (vmInput block tx validation) as [msg entry].
  cbn beta iota zeta delta [fst snd] in Hcode, Hbound |- ×.
  intro Hcreated. specialize (Hcode Hcreated).
  apply Hbound; [|exact Hsender|exact Hauth|exact Hcreated].
  apply noncontract_undelegated_empty_code; [exact Hsc|].
  cbv beta in Hcode, Hdelegated |- ×. rewrite <- Hcode. exact Hdelegated.
Qed.

world is an execution state; query is the sender address being tested; future is its proposed transaction's block height. Return true exactly when this state records no delegation for query and its earliest emptying block is <= future. No state is changed. This does not account for transactions after world or for the candidate's own authorizations; the consensus caller checks those separately.
Within the execution-delay window, a transaction removes eligibility exactly for its sender and applied authorities. For every other signer, both the delegation code and counter stay unchanged. This is the history fact needed to transport the snapshot's emptying test through execution.
Theorem process_transaction_future_emptying block tx validation post query future :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  stringmaps.WellFormed (W.t.accounts (B.t.world_state block)) →
  stringmaps.WellFormed (W.t.next_emptying_transaction_block (B.t.world_state block)) →
  @E.validate_transaction F block tx = inl validation →
  processTransaction block tx = inl post →
  (future < blockNumber block + 3)%N →
  let '(msg, entry) := vmInput block tx validation in
  ¬ List.In query (S.t.accounts_created_in_current_transaction (snd (callFromEoa tx msg entry))) →
  emptyingEligible (B.t.world_state post) query future =
    andb (emptyingEligible (B.t.world_state block) query future)
      (negb (existsb (fun addr ⇒ String.eqb addr query)
        (E.transaction_validation.sender validation :: fst (prefix block tx validation)))).
Proof.
  intros Hrevision Hmap Hcounters Hvalidation Hrun Hfuture.
  destruct (@process_transaction_activity_history F
    block tx validation post Hrevision Hcounters Hvalidation Hrun)
    as [_ [_ Hhistory]].
  specialize (Hhistory query).
  change (readCounter (B.t.world_state post) query =
    if existsb (fun addr ⇒ String.eqb addr query)
      (E.transaction_validation.sender validation :: fst (prefix block tx validation))
    then (blockNumber block + 3)%N else readCounter (B.t.world_state block) query) in Hhistory.
  pose proof (process_transaction_other_code block tx validation post query Hrevision Hmap
    Hvalidation Hrun) as Hcode.
  destruct (vmInput block tx validation) as [msg entry].
  cbn beta iota zeta delta [fst snd] in Hcode |- ×.
  intro Hcreated. unfold emptyingEligible.
  rewrite Hhistory.
  destruct (existsb (fun addr ⇒ String.eqb addr query)
    (E.transaction_validation.sender validation :: fst (prefix block tx validation))) eqn:Hmentions.
  - assert (Hlate : N.leb (blockNumber block + 3) future = false)
      by (apply N.leb_gt; exact Hfuture).
    rewrite Hlate. cbn [negb]. rewrite !Bool.andb_false_r. reflexivity.
  - assert (Hauth : ¬ List.In query (fst (prefix block tx validation))).
    { intro Hin. assert (Htrue : existsb (fun addr ⇒ String.eqb addr query)
        (E.transaction_validation.sender validation :: fst (prefix block tx validation)) = true).
      { apply existsb_exists. ∃ query. split; [right; exact Hin|apply String.eqb_refl]. }
      congruence. }
    specialize (Hcode Hauth Hcreated). cbv beta in Hcode |- ×.
    rewrite Hcode. cbn [negb]. apply eq_sym, Bool.andb_true_r.
Qed.

Lift the emptying argument through the transaction fold actually used by process_block. If the account is eligible at the end of the prefix, it was eligible throughout, and its starting balance is still available. The creation exclusion is the signer-address cryptographic condition; no intermediate balance or emptying invariant is assumed.
Theorem transactions_future_emptying_nondebit txs query future :
  MonadVM.Staking.staking_address ≠ query →
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  hashwords.keccak256OutputSize → @assemblychecked.nativeOutputBounds args →
  wordrange.wordRange (Support.UintN.to_z (Chain.Monad.PARAMS.chain_id params)) →
  Forall (fun tx ⇒
    Forall (fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20) (T.authorization_list tx) ∧
    transactionValueAndDataBounds tx) txs →
  (∀ block tx validation,
    List.In tx txs → @E.validate_transaction F block tx = inl validation →
    @A.is_smart_contract (readAccount (B.t.world_state block) query) = false →
    let '(msg, entry) := vmInput block tx validation in
    ¬ List.In query (S.t.accounts_created_in_current_transaction (snd (callFromEoa tx msg entry)))) →
  ∀ block post,
  transactionchecked.headerWords (Chain.Ethereum.Block.t.header (B.t.current_block block)) →
  supply.balanceInvariant (B.t.world_state block) → hostaccountformat.worldFormat (B.t.world_state block) →
  stringmaps.WellFormed (W.t.next_emptying_transaction_block (B.t.world_state block)) →
  @A.is_smart_contract (readAccount (B.t.world_state block) query) = false →
  (future < blockNumber block + 3)%N →
  Result.List.fold_leftM processTransaction block txs = inl post →
  emptyingEligible (B.t.world_state post) query future = true →
  emptyingEligible (B.t.world_state block) query future = true ∧
  Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state block) query)) ≤
    Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state post) query)).
Proof using F U8 UB UI0.
  intros Hnot_staking Hrevision Hhash Hnative Hchain Hwidth Hsafe.
  revert Hwidth Hsafe.
  induction txs as [|tx rest IH]; intros Hwidth Hsafe block post Hheader Hbalance Hformat Hcounters Hsc Hfuture Hrun Heligible.
  - cbn [Result.List.fold_leftM] in Hrun. injection Hrun as <-. split; [exact Heligible|lia].
  - inversion Hwidth as [|? ? [Hauth Hvalue] Htail]; subst.
    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] eqn:Hvalidation;
        [∃ validation; reflexivity|discriminate Hstep]. }
    destruct Hvalid as [validation Hvalidation].
    pose proof (Hsafe block tx validation (or_introl eq_refl) Hvalidation Hsc) as Hcreated.
    pose proof (process_transaction_noncontract block tx validation next query Hrevision (proj1 Hbalance)
      Hauth Hvalidation Hstep Hsc) as HnextSc.
    pose proof (process_transaction_future_emptying block tx validation next query future Hrevision
      (proj1 Hbalance) Hcounters Hvalidation Hstep Hfuture) as HnextEligible.
    pose proof (process_transaction_future_emptying_nondebit block tx validation next query future Hnot_staking Hrevision
      Hhash Hnative Hchain Hheader Hbalance Hformat Hcounters Hauth Hvalue Hvalidation Hstep Hsc Hfuture) as HnextBalance.
    assert (Hblock : B.t.current_block next = B.t.current_block block).
    { exact (@transactionchecked.process_transaction_current_block F
      block tx next Hstep). }
    assert (HnextSupply : supply.balanceInvariant (B.t.world_state next)).
    { exact (proj1 (@transactionchecked.process_transaction_preserves_supply F UI0 UB U8
      block tx next Hrevision Hhash Hnative Hchain
      (proj1 (proj2 Hheader)) (proj2 (proj2 Hheader)) Hbalance Hformat Hauth Hvalue Hstep)). }
    assert (HnextFormat : hostaccountformat.worldFormat (B.t.world_state next)).
    { pose proof (@transactionformat.process_transaction_preserves_format F
      block tx Hrevision Hauth Hformat) as H.
      rewrite Hstep in H. exact H. }
    assert (HnextCounters : stringmaps.WellFormed (W.t.next_emptying_transaction_block (B.t.world_state next))).
    { exact (proj1 (proj2 (@process_transaction_activity_history F
      block tx validation next Hrevision Hcounters Hvalidation Hstep))). }
    destruct (vmInput block tx validation) as [msg entry].
    cbn beta iota zeta delta [fst snd] in Hcreated, HnextSc, HnextEligible, HnextBalance.
    specialize (HnextSc Hcreated). specialize (HnextEligible Hcreated).
    specialize (IH Htail ltac:(intros b t v Hin; apply Hsafe; right; exact Hin)
      next post ltac:(rewrite Hblock; exact Hheader) HnextSupply HnextFormat HnextCounters HnextSc
      ltac:(cbv beta; rewrite Hblock; exact Hfuture) Hrun Heligible).
    destruct IH as [Hmiddle Hremaining].
    split.
    + rewrite Hmiddle in HnextEligible. symmetry in HnextEligible.
      apply Bool.andb_true_iff in HnextEligible. exact (proj1 HnextEligible).
    + unfold emptyingEligible in Hmiddle. apply Bool.andb_true_iff in Hmiddle as [Hundelegated Hcounter].
      apply Bool.negb_true_iff in Hundelegated. apply N.leb_le in Hcounter.
      specialize (HnextBalance Hcounter Hundelegated Hcreated). lia.
Qed.

Local Abbreviation hostCall := (@E.Host.call F).

System messages precede the transaction fold. They have no sender fee or authorization processing, but still execute the VM. Their zero root value and the empty-code nondebit theorem protect an eligible signer without assuming that these calls have no account effects.
Theorem system_message_emptying_nondebit block addr data query future :
  MonadVM.Staking.staking_address ≠ query →
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  hashwords.keccak256OutputSize → @assemblychecked.nativeOutputBounds args →
  wordrange.wordRange (Support.UintN.to_z (Chain.Monad.PARAMS.chain_id params)) →
  transactionchecked.headerWords (Chain.Ethereum.Block.t.header (B.t.current_block block)) →
  (OCamlString.length data < 2^62)%Z →
  supply.balanceInvariant (B.t.world_state block) → hostaccountformat.worldFormat (B.t.world_state block) →
  @A.is_smart_contract (readAccount (B.t.world_state block) query) = false →
  (∀ msg initial,
    S.t.world_state initial = B.t.world_state block →
    S.t.accounts_created_in_current_transaction initial = [] →
    ¬ List.In query (S.t.accounts_created_in_current_transaction (snd (hostCall msg initial)))) →
  let post := snd (@E.process_system_message F
    block addr data) in
  emptyingEligible (B.t.world_state post) query future =
    emptyingEligible (B.t.world_state block) query future ∧
  (emptyingEligible (B.t.world_state post) query future = true →
    Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state block) query)) ≤
      Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state post) query))).
Proof using F.
  intros Hnot_staking Hrevision Hhash Hnative Hchain Hheader Hdata Hbalance Hformat Hsc Hsafe.
  cbn zeta. unfold E.process_system_message.
  match goal with |- context [if ?test then _ else _] ⇒ destruct test end.
  { split; [reflexivity|intros _; apply Z.le_refl]. }
  cbn beta iota zeta.
  match goal with |- context [E.Host.call ?message ?entry] ⇒
    set (msg := message); set (initial := entry)
  end.
  assert (Hmsg : @vmcallchecked.vmMessageBounds msg).
  { split; [change (0 ≤ 30000000 < 2^63); lia|].
    split; [change (0 ≤ 0 < 2^256); lia|]. split; [exact Hdata|].
    apply vmcallchecked.encoded_capacity_all_decoders.
    unfold E.vm_max_memory_usage. rewrite Hrevision. vm_compute. reflexivity. }
  pose proof (Hsafe msg initial eq_refl eq_refl) as Hcreated.
  pose proof (@execution_host_call_preserves_creation F
    msg Hrevision (proj1 Hmsg) initial (proj1 Hbalance)) as Hframe.
  pose proof (@executioncontext.execution_call_preserves_context F
    msg Hrevision (proj1 Hmsg) initial) as Hcontext.
  pose proof (hostcode.noncreated_code _ _ (proj2 Hframe) query Hcreated) as Hcode.
  unfold hostframe.transactionContext in Hcontext.
  injection Hcontext as Hinitial Hblock Horigin Hgas Hprice Hhistory Hcounters.
  assert (Heligible : emptyingEligible (S.t.world_state (snd (hostCall msg initial))) query future =
    emptyingEligible (B.t.world_state block) query future).
  { unfold emptyingEligible. cbv beta in Hcode |- ×. apply f_equal2.
    - exact (f_equal (fun code ⇒ negb
        (@Delegation.is_valid_delegation code)) Hcode).
    - change (N.leb (match OCamlMap.Make.find_opt stringmaps.stringOrder query
        (W.t.next_emptying_transaction_block (S.t.world_state (snd (hostCall msg initial)))) with
        Some n ⇒ n | None ⇒ 0%N end) future =
        N.leb (match OCamlMap.Make.find_opt stringmaps.stringOrder query
        (W.t.next_emptying_transaction_block (B.t.world_state block)) with
        Some n ⇒ n | None ⇒ 0%N end) future).
      exact (f_equal (fun counters ⇒ N.leb
        (match OCamlMap.Make.find_opt stringmaps.stringOrder query counters with
         Some n ⇒ n | None ⇒ 0%N end) future) Hcounters). }
  destruct (hostCall msg initial) as [result afterVm] eqn:Hcall.
  cbn beta iota zeta delta [fst snd B.t.with_world_state B.t.world_state] in Hcreated, Heligible |- ×.
  split; [exact Heligible|]. intro Hallowed.
  assert (Hempty : A.t.code (readAccount (B.t.world_state block) query) = Byte_string.Bytes.empty).
  { apply noncontract_undelegated_empty_code; [exact Hsc|].
    rewrite Heligible in Hallowed. unfold emptyingEligible in Hallowed.
    apply Bool.andb_true_iff in Hallowed as [Hdelegation _].
    apply Bool.negb_true_iff. exact Hdelegation. }
  assert (Hentry : vmsupplywords.hostSupplyContext params (supply.totalBalance (B.t.world_state block)) initial).
  { split.
    - split; [split; [exact Hbalance|apply Z.le_refl]|].
      split; [exact Hformat|constructor].
    - destruct Hheader as [Hbase [Hnumbers Hrandao]]. split.
      + constructor; [change (0 ≤ 0 < 2^256); lia|].
        constructor; [exact Hbase|]. constructor; [exact Hchain|constructor].
      + split; assumption. }
  pose (minimum := Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state block) query))).
  assert (Hfloor : @nondebitframe.uncreatedBalanceFloor query
      (minimum + Numeric.U256.to_z (Evmc.Message.t.value msg)) initial).
  { split; [exact Hbalance|]. right. split; [exact Hempty|].
    change (minimum + 0 ≤ minimum). lia. }
  pose proof (@executionnondebit.execution_host_call_value_floor F

     (supply.totalBalance (B.t.world_state block)) query minimum msg
    Hnot_staking Hrevision Hhash Hnative Hmsg eq_refl ltac:(intro H; exact H) initial Hentry Hfloor) as Hafter.
  change (@nondebitframe.uncreatedBalanceFloor query minimum
    (snd (hostCall msg initial))) in Hafter.
  rewrite Hcall in Hafter.
  destruct Hafter as [_ [Hnew|[_ Hbound]]]; [contradiction|exact Hbound].
Qed.

End Execution.

Print Assumptions process_transaction_retains_host_code.

Print Assumptions process_transaction_noncontract.
Print Assumptions process_transaction_other_code.

Print Assumptions process_transaction_future_emptying_nondebit.
Print Assumptions process_transaction_future_emptying.

Print Assumptions transactions_future_emptying_nondebit.

Print Assumptions system_message_emptying_nondebit.