Library QedkConcrete.transactionstage

Reserve bounds through concrete transaction processing

This names the fee/authorization/access-list prefix already present in Execution.process_transaction; it does not define a second executor. The prefix bounds are derived from validation and the initial supply; the final theorems concern the returned process_transaction state. No VM balance/frame postcondition is assumed. Successful validation here describes an already processed transaction. These preservation lemmas support the separate consensus proof, which derives validation rather than assuming it.
From Stdlib Require Import List ZArith Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Execution QedkConcrete.transactionchecked
  QedkConcrete.transactionhistory QedkConcrete.transactionfees
  QedkConcrete.transactionentrywords QedkConcrete.authorization
  QedkConcrete.hostcontextwords QedkConcrete.hostframe QedkConcrete.wordrange
  QedkConcrete.vmcallchecked QedkConcrete.vmsupplywords QedkConcrete.assemblychecked
  QedkConcrete.supply QedkConcrete.validation QedkConcrete.transactionformat
  QedkConcrete.worldaccounts QedkConcrete.hostaccountformat
  QedkConcrete.transactionfinalize QedkConcrete.executionreserve
  QedkConcrete.hashwords QedkConcrete.executionchecked
  QedkConcrete.authorizationcode QedkConcrete.executioncreation QedkConcrete.hostcode
  QedkConcrete.executionnondebit
  QedkConcrete.reservestorage QedkConcrete.reserveencoding QedkConcrete.hoststoragewords.
Require Import QedkConcrete.nativeinputs.
Set Default Goal Selector "!".
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 precompileAddresses := (@Precompiles.Make.Make_result.precompile_addresses
  (@E.Precompiles_fargs F) (@E.Precompiles F)).
Local Abbreviation prefix := (@transactionPrefix F).

Definition transactionVmInput block tx (validation : E.transaction_validation) : Evmc.Message.t × S.t :=
  let '(authorities, prepared) := prefix block tx validation in
  let beforeVm := @S.initialize_access_sets tx
    (@E.bump_emptying_transaction_counters F authorities prepared) precompileAddresses in
  let message := @E.prepare_message F (E.transaction_validation.sender validation)
    (@Gas.op_minus
      (T.gas_limit tx) (E.transaction_validation.intrinsic_gas validation)) tx (S.t.world_state beforeVm) in
  (message, beforeVm).

Lemma transaction_vm_input_supply block tx validation :
  @E.validate_transaction F block tx = inl validation →
  balanceInvariant (B.t.world_state block) →
  let beforeVm := snd (transactionVmInput block tx validation) in
  balanceInvariant (S.t.world_state beforeVm) ∧
  totalBalance (S.t.world_state beforeVm) = totalBalance (B.t.world_state block) -
    Numeric.U256.to_z (E.transaction_validation.total_fee validation).
Proof.
  intros Hvalidation Hinitial.
  pose proof (@account_balance_bounded_by_supply (B.t.world_state block)
    (E.transaction_validation.sender validation) (proj1 (proj2 Hinitial))) as Hbalance.
  pose proof (proj2 (proj2 Hinitial)) as Hsupply.
  pose proof (validated_debit_range block tx validation Hvalidation ltac:(cbn beta in Hbalance; lia))
    as [Hfee Hdebit].
  assert (HfeeNonnegative : 0 ≤ Numeric.U256.to_z (E.transaction_validation.total_fee validation)).
  { rewrite Hfee. apply N2Z.is_nonneg. }
  set (initial := @S.make
    block (E.transaction_validation.sender validation) tx).
  pose proof (@transaction_entry_supply F initial (E.transaction_validation.sender validation)
    (E.transaction_validation.total_fee validation) (T.authorization_list tx)
    Hinitial HfeeNonnegative Hdebit) as [Hauth Htotal].
  change (balanceInvariant (S.t.world_state (snd (prefix block tx validation)))) in Hauth.
  change (totalBalance (S.t.world_state (snd (prefix block tx validation))) =
    totalBalance (B.t.world_state block) - Numeric.U256.to_z (E.transaction_validation.total_fee validation)) in Htotal.
  unfold transactionVmInput. destruct (prefix block tx validation) as [authorities prepared].
  cbn beta iota zeta delta [fst snd] in Hauth, Htotal |- ×.
  split.
  - change (balanceInvariant (S.t.world_state (@E.bump_emptying_transaction_counters F authorities prepared))).
    apply transactionsupply.bump_counters_balance_invariant. exact Hauth.
  - change (totalBalance (S.t.world_state (@E.bump_emptying_transaction_counters F authorities prepared)) =
      totalBalance (B.t.world_state block) - Numeric.U256.to_z (E.transaction_validation.total_fee validation)).
    rewrite transactionsupply.bump_counters_total. exact Htotal.
Qed.
Validation supplies the gas/price bounds; the upfront debit supplies the aggregate headroom later used to pay the beneficiary.
Lemma transaction_vm_input_safe block tx validation :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  @E.validate_transaction F block tx = inl validation →
  wordRange (Support.UintN.to_z (Chain.Monad.PARAMS.chain_id params)) →
  headerWords (Chain.Ethereum.Block.t.header (B.t.current_block block)) →
  balanceInvariant (B.t.world_state block) → worldFormat (B.t.world_state block) →
  Forall (fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20)
    (T.authorization_list tx) →
  transactionValueAndDataBounds tx →
  let '(message, beforeVm) := transactionVmInput block tx validation in
  hostSupplyContext params
    (totalBalance (B.t.world_state block) - Numeric.U256.to_z (E.transaction_validation.total_fee validation)) beforeVm ∧
  @vmMessageBounds message.
Proof using F U8 UB UI0.
  intros Hrevision Hvalidation Hchain Hheader Hinitial Hformat Hwidth Hvalue.
  pose proof (transaction_vm_input_supply block tx validation Hvalidation Hinitial) as [Hbefore Htotal].
  pose proof (@account_balance_bounded_by_supply (B.t.world_state block)
    (E.transaction_validation.sender validation) (proj1 (proj2 Hinitial))) as Hbalance.
  pose proof (proj2 (proj2 Hinitial)) as Hsupply.
  pose proof (validated_debit_range block tx validation Hvalidation ltac:(cbn beta in Hbalance; lia))
    as [Hfee Hdebit].
  pose proof (@transaction_initial_context_words F UI0 UB U8 params block tx validation
    Hvalidation Hinitial Hchain (proj1 (proj2 Hheader)) (proj2 (proj2 Hheader))) as HinitialContext.
  set (initial := @S.make
    block (E.transaction_validation.sender validation) tx).
  change (hostContextWords params initial) in HinitialContext.
  pose proof (@transaction_entry_balances F initial (E.transaction_validation.sender validation)
    (E.transaction_validation.total_fee validation) (T.authorization_list tx)
    (proj1 Hinitial) Hdebit) as [_ [HauthContext _]].
  assert (HinitialFormat : hostFormat initial) by (apply transaction_initial_format; exact Hformat).
  pose proof (@transaction_entry_format F initial (E.transaction_validation.sender validation)
    (E.transaction_validation.total_fee validation) (T.authorization_list tx) Hwidth HinitialFormat) as HauthFormat.
  change (hostFormat (snd (prefix block tx validation))) in HauthFormat.
  change (transactionContext (snd (prefix block tx validation)) = transactionContext initial) in HauthContext.
  unfold transactionVmInput in Hbefore, Htotal |- ×.
  destruct (prefix block tx validation) as [authorities prepared].
  cbn beta iota zeta delta [fst snd] in Hbefore, Htotal, HauthFormat, HauthContext |- ×.
  split.
  - split.
    + split; [split; [exact Hbefore|lia]|].
      change (hostFormat (@E.bump_emptying_transaction_counters F authorities prepared)).
      apply bump_counters_format. exact HauthFormat.
    + change (hostContextWords params prepared).
      eapply host_context_words_preserved; eassumption.
  - apply (validated_message_bounds block tx validation); assumption.
Qed.
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)).

Connect the Host result to the actual returned block state. Beneficiary payment uses money already debited, so it cannot wrap or reduce a balance. Only an account explicitly deleted by SELFDESTRUCT is excluded here.
Theorem process_transaction_retains_host_balance block tx validation post :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  keccak256OutputSize → @nativeOutputBounds args →
  wordRange (Support.UintN.to_z (Chain.Monad.PARAMS.chain_id params)) →
  headerWords (Chain.Ethereum.Block.t.header (B.t.current_block block)) →
  balanceInvariant (B.t.world_state block) → worldFormat (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 →
  let '(msg, entry) := transactionVmInput block tx validation in
  let afterVm := snd (callFromEoa tx msg entry) in
  ∀ query, ¬ List.In query (S.t.self_destruct afterVm) →
    Numeric.U256.to_z (A.t.balance (readAccount (S.t.world_state afterVm) query)) ≤
    Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state post) query)).
Proof using F U8 UB UI0.
  intros Hrevision Hhash Hnative Hchain Hheader Hinitial Hformat Hwidth Hvalue Hvalidation Hrun.
  pose proof (transaction_vm_input_safe block tx validation Hrevision Hvalidation
    Hchain Hheader Hinitial Hformat Hwidth Hvalue) as Hsafe.
  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 Hsafe |- ×.
  destruct (prefix block tx validation) as [authorities prepared].
  cbn beta iota zeta delta [fst snd] in Hsafe, 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.
  destruct Hsafe as [Hbefore Hmsg].
  pose proof (@execution_call_from_eoa_supply_and_output F

    (totalBalance (B.t.world_state block) - Numeric.U256.to_z (E.transaction_validation.total_fee validation))
    tx msg beforeVm Hrevision Hhash Hnative Hmsg Hbefore) as Hafter.
  change (∀ query, ¬ List.In query (S.t.self_destruct (snd (callFromEoa tx msg beforeVm))) →
    Numeric.U256.to_z (A.t.balance (readAccount (S.t.world_state (snd (callFromEoa tx msg beforeVm))) query)) ≤
    Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state post) 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 [[[[Hinv Htotal] _] _] _].
  pose proof (transactionsupply.bump_counters_balance_invariant afterVm
    [E.transaction_validation.sender validation] Hinv) as Hcounters.
  pose proof (transactionsupply.bump_counters_total afterVm [E.transaction_validation.sender validation]) as HcounterTotal.
  pose proof (@beneficiary_credit_reuses_fee F block tx validation
    (S.t.world_state (@E.bump_emptying_transaction_counters F [E.transaction_validation.sender validation] afterVm))
    Hvalidation Hinitial Hcounters ltac:(lia)) as [HcreditInv [_ Hcredit]].
  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] ⇒
    pose proof (@delete_accounts_preserves_other credited (S.t.self_destruct afterVm)
      query (proj1 HcreditInv) HnotDeleted) as [_ Hread]
  end.
  eapply Z.le_trans.
  2: { apply Z.eq_le_incl. symmetry.
       exact (f_equal (fun account ⇒ Numeric.U256.to_z (A.t.balance account)) Hread). }
  eapply Z.le_trans; [|exact (Hcredit query)].
  change (Numeric.U256.to_z (A.t.balance (readAccount (S.t.world_state afterVm) query)) ≤
    Numeric.U256.to_z (A.t.balance (readAccount (S.t.world_state
      (@E.bump_emptying_transaction_counters F [E.transaction_validation.sender validation] afterVm)) query))).
  unfold E.bump_emptying_transaction_counters.
  cbn beta iota zeta delta [S.t.with_world_state S.t.world_state].
  reflexivity.
Qed.
Lemma authorization_preserves_destruction s auth :
  S.t.self_destruct (snd (@E.process_authorization F s auth)) = S.t.self_destruct 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_destruction auths authorities s :
  S.t.self_destruct (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.self_destruct 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_destruction 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_metadata block tx validation :
  let entry := snd (transactionVmInput block tx validation) in
  S.t.initial_world_state entry = B.t.world_state block ∧
  S.t.current_block entry = B.t.current_block block ∧
  S.t.tx_origin entry = E.transaction_validation.sender validation ∧
  S.t.self_destruct entry = [].
Proof.
  pose proof (@transaction_prefix_context F block tx validation) as Hcontext.
  assert (Hdes : S.t.self_destruct (snd (prefix block tx validation)) = []).
  { unfold transactionPrefix. rewrite authorizations_preserve_destruction. reflexivity. }
  unfold transactionVmInput. destruct (prefix block tx validation) as [authorities prepared].
  cbn beta iota zeta delta [fst snd] in Hcontext, Hdes |- ×.
  unfold transactionContext in Hcontext.
  injection Hcontext as Hinitial Hblock Horigin Hlimit Hprice Hhistory Hcounter.
  split; [exact Hinitial|]. split; [exact Hblock|]. split; [exact Horigin|exact Hdes].
Qed.

Lemma transaction_vm_input_noncontract block tx validation query :
  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) →
  @A.is_smart_contract (readAccount (B.t.world_state block) query) = false →
  @A.is_smart_contract (readAccount (S.t.world_state (snd (transactionVmInput block tx validation))) query) = false.
Proof.
  intros Hwf Hwidth Hsc.
  pose proof (@transaction_prefix_preserves_noncontract F block tx validation query
    Hwf Hwidth Hsc) as Hprefix.
  unfold transactionVmInput. destruct (prefix block tx validation) as [authorities prepared].
  cbn beta iota zeta delta [fst snd] in Hprefix |- ×.
  change (@A.is_smart_contract (readAccount (S.t.world_state (@E.bump_emptying_transaction_counters F authorities prepared)) query) = false).
  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 transaction_vm_input_balances block tx validation :
  @E.validate_transaction F block tx = inl validation →
  balanceInvariant (B.t.world_state block) →
  ∀ query,
  Numeric.U256.to_z (A.t.balance (readAccount
    (S.t.world_state (snd (transactionVmInput block tx validation))) query)) =
  if String.eqb (E.transaction_validation.sender validation) query then
    Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state block) query)) -
      Numeric.U256.to_z (E.transaction_validation.total_fee validation)
  else Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state block) query)).
Proof.
  intros Hvalidation Hinitial query.
  pose proof (@account_balance_bounded_by_supply (B.t.world_state block)
    (E.transaction_validation.sender validation) (proj1 (proj2 Hinitial))) as Hbalance.
  pose proof (proj2 (proj2 Hinitial)) as Hsupply.
  pose proof (validated_debit_range block tx validation Hvalidation ltac:(cbn beta in Hbalance; lia))
    as [Hfee Hdebit].
  set (initial := @S.make
    block (E.transaction_validation.sender validation) tx).
  pose proof (@transaction_entry_balances F initial (E.transaction_validation.sender validation)
    (E.transaction_validation.total_fee validation) (T.authorization_list tx)
    (proj1 Hinitial) Hdebit) as [_ [_ Hbalances]].
  specialize (Hbalances query).
  change (Numeric.U256.to_z (A.t.balance (readAccount
    (S.t.world_state (snd (prefix block tx validation))) query)) =
    if String.eqb (E.transaction_validation.sender validation) query then
      Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state block) query)) -
        Numeric.U256.to_z (E.transaction_validation.total_fee validation)
    else Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state block) query))) in Hbalances.
  unfold transactionVmInput. destruct (prefix block tx validation) as [authorities prepared].
  cbn beta iota zeta delta [fst snd] in Hbalances |- ×.
  match goal with |- _ = ?rhs ⇒
    change (Numeric.U256.to_z (A.t.balance (readAccount
      (S.t.world_state (@E.bump_emptying_transaction_counters F authorities prepared)) query)) = rhs)
  end.
  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 Hbalances.
Qed.
Local Abbreviation protected := (@reservecheck.protected).
Local Abbreviation configured := (@Reserve_balance.user_reserve_balance).
A concrete transaction preserves a nonsender's protected reserve, including when it reverts and when the nonsender is the fee beneficiary. Creation at the protected address is excluded explicitly; neither the final code nor the VM's balance behavior is assumed.
Theorem process_transaction_nonsender_reserve block tx validation post addr original :
  MonadVM.Staking.staking_address ≠ addr →
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  keccak256OutputSize → @nativeOutputBounds args →
  wordRange (Support.UintN.to_z (Chain.Monad.PARAMS.chain_id params)) →
  headerWords (Chain.Ethereum.Block.t.header (B.t.current_block block)) →
  balanceInvariant (B.t.world_state block) → worldFormat (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 →
  Chain.Ethereum.Address.Map.find_opt addr (W.t.accounts (B.t.world_state block)) = Some original →
  @A.is_smart_contract (readAccount (B.t.world_state block) addr) = false →
  addr ≠ E.transaction_validation.sender validation →
  let '(msg, entry) := transactionVmInput block tx validation in
  ¬ List.In addr (S.t.accounts_created_in_current_transaction (snd (callFromEoa tx msg entry))) →
  Numeric.U256.to_z (Numeric.U256.min
    (configured (B.t.world_state block)
      (Chain.Ethereum.Block.Header.t.number (Chain.Ethereum.Block.t.header (B.t.current_block block))) addr)
    (A.t.balance original)) ≤
  Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state post) addr)).
Proof using F U8 UB UI0.
  intros Hstaking Hrevision Hhash Hnative Hchain Hheader Hinitial Hformat Hwidth Hvalue
    Hvalidation Hrun Hfind Hsc Hsender.
  pose proof (process_transaction_retains_host_balance block tx validation post Hrevision Hhash Hnative
    Hchain Hheader Hinitial Hformat Hwidth Hvalue Hvalidation Hrun) as Hfinal.
  pose proof (transaction_vm_input_safe block tx validation Hrevision Hvalidation
    Hchain Hheader Hinitial Hformat Hwidth Hvalue) as Hsafe.
  pose proof (transaction_vm_input_metadata block tx validation) as Hmetadata.
  pose proof (transaction_vm_input_noncontract block tx validation addr (proj1 Hinitial) Hwidth Hsc) as Hentrysc.
  pose proof (transaction_vm_input_balances block tx validation Hvalidation Hinitial addr) as Hbalance.
  destruct (transactionVmInput block tx validation) as [msg entry] eqn:Hinput.
  cbn beta iota zeta delta [fst snd] in Hfinal, Hsafe, Hmetadata, Hentrysc, Hbalance |- ×.
  intro Hcreated.
  destruct Hmetadata as [HinitialWorld [Hblock [Horigin Hdes]]].
  destruct Hsafe as [[[[HentryInv _] _] _] Hmsg].
  assert (Hgas : 0 ≤ Evmc.Message.t.gas msg < 2^63) by exact (proj1 Hmsg).
  assert (HnotDeleted : ¬ List.In addr (S.t.self_destruct (snd (callFromEoa tx msg entry)))).
  { destruct (@execution_call_from_eoa_preserves_creation F
      tx msg Hrevision Hgas entry (proj1 HentryInv)) as [_ Hframe].
    intro Hin. destruct (destruction_covered _ _ Hframe addr Hin) as [Hbefore|Hnew].
    - rewrite Hdes in Hbefore. contradiction.
    - exact (Hcreated Hnew). }
  assert (Hbound : Z.min (Numeric.U256.to_z (A.t.balance (readAccount (S.t.world_state entry) addr)))
    (Numeric.U256.to_z (protected entry addr original)) ≤
    Numeric.U256.to_z (A.t.balance (readAccount (S.t.world_state (snd (callFromEoa tx msg entry))) addr))).
  { apply (@call_nonsender_reserve_lower_bound F
      tx msg entry addr original).
    - exact Hrevision.
    - exact Hgas.
    - exact (proj1 HentryInv).
    - rewrite HinitialWorld. exact Hfind.
    - exact Hentrysc.
    - change (Z.eqb (OCamlString.compare addr MonadVM.Staking.staking_address) 0 = false).
      apply Z.eqb_neq. intro Heq.
      apply Hstaking. symmetry. apply reservecheck.address_compare_eq. exact Heq.
    - rewrite Hdes. tauto.
    - rewrite Horigin.
      change (Z.eqb (OCamlString.compare addr (E.transaction_validation.sender validation)) 0 = false).
      apply Z.eqb_neq. intro Heq.
      apply Hsender. apply reservecheck.address_compare_eq. exact Heq.
    - exact Hcreated. }
  assert (Horiginal : readAccount (B.t.world_state block) addr = original).
  { change ((match Chain.Ethereum.Address.Map.find_opt addr (W.t.accounts (B.t.world_state block)) with
      Some ac ⇒ ac | None ⇒ @A.empty end) = original). rewrite Hfind. reflexivity. }
  assert (Hneq : String.eqb (E.transaction_validation.sender validation) addr = false)
    by (apply String.eqb_neq; congruence).
  rewrite Hneq in Hbalance. cbv beta in Hbalance, Hbound, Horiginal.
  rewrite Horiginal in Hbalance. rewrite Hbalance in Hbound.
  unfold reservecheck.protected in Hbound. rewrite HinitialWorld, Hblock in Hbound.
  pose proof (Hfinal addr HnotDeleted) as Hlast. cbv beta in Hlast |- ×.
  rewrite reservecheck.u256_min in Hbound |- ×. lia.
Qed.
Lemma configured_word_range world block addr :
  worldFormat world → wordRange (configured world block addr).
Proof.
  intro Hformat.
  pose proof (proj1 (proj1 (world_format_components world) Hformat)) as Hstorage.
  set (native := @Reserve_balance.precompile_address ).
  pose proof (@read_account_storage_words world native Hstorage) as Hbytes.
  assert (Hfield : ∀ offset,
    (@readConfigField (A.t.storage (readAccount world native)) addr offset < 2^256)%N).
  { intro offset. apply read_config_bounded. exact Hbytes. }
  unfold Reserve_balance.user_reserve_balance.
  match goal with |- wordRange (@Numeric.U256.of_uint_exn (Reserve_config.active ?r block)) ⇒
    set (record := r)
  end.
  assert (Hsettled : (Reserve_config.t.settled record < 2^256)%N) by (exact (Hfield 0)).
  assert (Hpending : (Reserve_config.t.pending record < 2^256)%N) by (exact (Hfield 1)).
  match goal with |- wordRange (@Numeric.U256.of_uint_exn ?value) ⇒
    assert (Hactive : (value < 2^256)%N)
  end.
  { unfold Reserve_config.active.
    match goal with |- context [if ?b then _ else _] ⇒ destruct b end.
    - change (10000000000000000000 < 2^256)%N. lia.
    - match goal with |- context [if ?b then _ else _] ⇒ destruct b end; assumption. }
  unfold wordRange. rewrite reservecheck.u256_of_uint by lia.
  split; [apply N2Z.is_nonneg|lia].
Qed.
Lemma transaction_vm_input_fee block tx validation :
  @E.validate_transaction F block tx = inl validation →
  balanceInvariant (B.t.world_state block) →
  let entry := snd (transactionVmInput block tx validation) in
  Z.of_N (S.t.tx_gas_limit entry × S.t.tx_gas_price entry) =
    Numeric.U256.to_z (E.transaction_validation.total_fee validation).
Proof.
  intros Hvalidation Hinitial.
  pose proof (@transaction_prefix_context F block tx validation) as Hcontext.
  pose proof (validated_effective_price block tx validation Hvalidation) as Hprice.
  pose proof (@account_balance_bounded_by_supply (B.t.world_state block)
    (E.transaction_validation.sender validation) (proj1 (proj2 Hinitial))) as Hbalance.
  pose proof (proj2 (proj2 Hinitial)) as Hsupply.
  pose proof (validated_debit_range block tx validation Hvalidation ltac:(cbn beta in Hbalance; lia)) as [Hfee _].
  unfold transactionVmInput. destruct (prefix block tx validation) as [authorities prepared].
  cbn beta iota zeta delta [fst snd] in Hcontext |- ×.
  unfold transactionContext in Hcontext.
  injection Hcontext as HinitialWorld Hblock Horigin Hlimit Hgasprice Hhistory Hcounter.
  change (Z.of_N (S.t.tx_gas_limit prepared × S.t.tx_gas_price prepared) =
    Numeric.U256.to_z (E.transaction_validation.total_fee validation)).
  rewrite Hlimit, Hgasprice.
  rewrite Hprice. exact (eq_sym Hfee).
Qed.

Local Abbreviation emptying := (@Reserve_balance.is_emptying_tx).

The charged fee is the sole permitted reduction of a non-emptying sender's protected reserve. This includes the concrete upfront debit, authorization fold, reverted calls, beneficiary credit and finalization.
Theorem process_transaction_sender_reserve block tx validation post original :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  keccak256OutputSize → @nativeOutputBounds args →
  wordRange (Support.UintN.to_z (Chain.Monad.PARAMS.chain_id params)) →
  headerWords (Chain.Ethereum.Block.t.header (B.t.current_block block)) →
  balanceInvariant (B.t.world_state block) → worldFormat (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 →
  let sender := E.transaction_validation.sender validation in
  MonadVM.Staking.staking_address ≠ sender →
  Chain.Ethereum.Address.Map.find_opt sender (W.t.accounts (B.t.world_state block)) = Some original →
  @A.is_smart_contract (readAccount (B.t.world_state block) sender) = false →
  let '(msg, entry) := transactionVmInput block tx validation in
  fst (emptying entry) = false →
  ¬ List.In sender (S.t.accounts_created_in_current_transaction (snd (callFromEoa tx msg entry))) →
  Numeric.U256.to_z (Numeric.U256.min
    (configured (B.t.world_state block)
      (Chain.Ethereum.Block.Header.t.number (Chain.Ethereum.Block.t.header (B.t.current_block block))) sender)
    (A.t.balance original)) - Numeric.U256.to_z (E.transaction_validation.total_fee validation) ≤
  Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state post) sender)).
Proof using F U8 UB UI0.
  intros Hrevision Hhash Hnative Hchain Hheader Hinitial Hformat Hwidth Hvalue
    Hvalidation Hrun sender Hstaking Hfind Hsc.
  pose proof (process_transaction_retains_host_balance block tx validation post Hrevision Hhash Hnative
    Hchain Hheader Hinitial Hformat Hwidth Hvalue Hvalidation Hrun) as Hfinal.
  pose proof (transaction_vm_input_safe block tx validation Hrevision Hvalidation
    Hchain Hheader Hinitial Hformat Hwidth Hvalue) as Hsafe.
  pose proof (transaction_vm_input_metadata block tx validation) as Hmetadata.
  pose proof (transaction_vm_input_noncontract block tx validation sender (proj1 Hinitial) Hwidth Hsc) as Hentrysc.
  pose proof (transaction_vm_input_balances block tx validation Hvalidation Hinitial sender) as Hbalance.
  pose proof (transaction_vm_input_fee block tx validation Hvalidation Hinitial) as Hfee.
  destruct (transactionVmInput block tx validation) as [msg entry] eqn:Hinput.
  cbn beta iota zeta delta [fst snd] in Hfinal, Hsafe, Hmetadata, Hentrysc, Hbalance, Hfee |- ×.
  intros Hempty Hcreated.
  destruct Hmetadata as [HinitialWorld [Hblock [Horigin Hdes]]].
  fold sender in Horigin, Hbalance.
  destruct Hsafe as [[[[HentryInv _] _] _] Hmsg].
  assert (Hgas : 0 ≤ Evmc.Message.t.gas msg < 2^63) by exact (proj1 Hmsg).
  assert (HnotDeleted : ¬ List.In sender (S.t.self_destruct (snd (callFromEoa tx msg entry)))).
  { destruct (@execution_call_from_eoa_preserves_creation F
      tx msg Hrevision Hgas entry (proj1 HentryInv)) as [_ Hframe].
    intro Hin. destruct (destruction_covered _ _ Hframe sender Hin) as [Hbefore|Hnew].
    - rewrite Hdes in Hbefore. contradiction.
    - exact (Hcreated Hnew). }
  assert (Horiginal : readAccount (B.t.world_state block) sender = original).
  { change ((match Chain.Ethereum.Address.Map.find_opt sender (W.t.accounts (B.t.world_state block)) with
      Some ac ⇒ ac | None ⇒ @A.empty end) = original). rewrite Hfind. reflexivity. }
  assert (Hrange : wordRange (protected entry sender original)).
  { pose proof (configured_word_range (B.t.world_state block)
      (Chain.Ethereum.Block.Header.t.number (Chain.Ethereum.Block.t.header (B.t.current_block block)))
      sender Hformat) as Hconfigured.
    pose proof (@account_balance_bounded_by_supply (B.t.world_state block) sender
      (proj1 (proj2 Hinitial))) as Haccount.
    pose proof (proj2 (proj2 Hinitial)) as Htotal.
    cbv beta in Haccount, Horiginal. rewrite Horiginal in Haccount.
    unfold wordRange, reservecheck.protected in ×.
    rewrite HinitialWorld, Hblock, reservecheck.u256_min. lia. }
  pose proof (@call_sender_reserve_lower_bound F
      tx msg entry original Hrevision Hgas (proj1 HentryInv)) as Hbound.
  cbn zeta in Hbound. rewrite Horigin in Hbound.
  assert (Hstakingb : Chain.Ethereum.Address.op_eq sender MonadVM.Staking.staking_address = false).
  { change (Z.eqb (OCamlString.compare sender MonadVM.Staking.staking_address) 0 = false).
    apply Z.eqb_neq. intro Heq.
    apply Hstaking. symmetry. apply reservecheck.address_compare_eq. exact Heq. }
  specialize (Hbound ltac:(rewrite HinitialWorld; exact Hfind) Hentrysc Hstakingb
    ltac:(rewrite Hdes; tauto) Hempty Hrange Hcreated).
  rewrite String.eqb_refl in Hbalance. cbv beta in Hbalance, Hbound, Horiginal.
  rewrite Horiginal in Hbalance. rewrite Hbalance, Hfee in Hbound.
  unfold reservecheck.protected in Hbound. rewrite HinitialWorld, Hblock in Hbound.
  pose proof (Hfinal sender HnotDeleted) as Hlast. cbv beta in Hlast |- ×.
  rewrite reservecheck.u256_min in Hbound |- ×. lia.
Qed.

The external message uses the transaction sender, and CALL resolves code at its recipient. These facts are derived from prepare_message, not supplied as an execution-account assumption.
Lemma transaction_vm_input_message block tx validation :
  let msg := fst (transactionVmInput block tx validation) in
  Evmc.Message.t.sender msg = E.transaction_validation.sender validation ∧
  (Evmc.Message.t.kind msg = Evmc.Message.CallKind.Call ∨
    Evmc.Message.t.kind msg = Evmc.Message.CallKind.Create) ∧
  Evmc.Message.t.code_address msg = Evmc.Message.t.recipient msg.
Proof.
  unfold transactionVmInput. destruct (prefix block tx validation) as [authorities prepared].
  cbn beta iota zeta delta [fst snd]. unfold E.prepare_message.
  destruct (T.call_or_create_value tx) as [[target data]|[initcode]];
    cbn beta iota zeta delta [Evmc.Message.t.sender Evmc.Message.t.kind
      Evmc.Message.t.code_address Evmc.Message.t.recipient].
  all: split; [reflexivity|split; [first [left; reflexivity|right; reflexivity]|reflexivity]].
Qed.

Lemma transaction_vm_input_other_code block tx validation query :
  stringmaps.WellFormed (W.t.accounts (B.t.world_state block)) →
  ¬ List.In query (fst (prefix block tx validation)) →
  A.t.code (readAccount (S.t.world_state (snd (transactionVmInput block tx validation))) query) =
    A.t.code (readAccount (B.t.world_state block) query).
Proof.
  intros Hwf Hauth.
  pose proof (@transaction_prefix_other_code F block tx validation query
    Hwf Hauth) 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.

This is the stronger bound needed before a future emptying transaction: an undelegated nonsender retains its entire balance, not merely its reserve. Applied authorizations are excluded explicitly because they can install executable code at the account. Contract creation is excluded separately; the proof derives the nested VM behavior rather than assuming nondebit.
Theorem process_transaction_nonsender_nondebit block tx validation post addr :
  MonadVM.Staking.staking_address ≠ addr →
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  keccak256OutputSize → @nativeOutputBounds args →
  wordRange (Support.UintN.to_z (Chain.Monad.PARAMS.chain_id params)) →
  headerWords (Chain.Ethereum.Block.t.header (B.t.current_block block)) →
  balanceInvariant (B.t.world_state block) → worldFormat (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.t.code (readAccount (B.t.world_state block) addr) = Byte_string.Bytes.empty →
  addr ≠ E.transaction_validation.sender validation →
  ¬ List.In addr (fst (prefix block tx validation)) →
  let '(msg, entry) := transactionVmInput block tx validation in
  ¬ List.In addr (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) addr)) ≤
  Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state post) addr)).
Proof using F U8 UB UI0.
  intros Hstaking Hrevision Hhash Hnative Hchain Hheader Hinitial Hformat Hwidth Hvalue
    Hvalidation Hrun Hempty Hsender Hauth.
  pose proof (process_transaction_retains_host_balance block tx validation post Hrevision Hhash Hnative
    Hchain Hheader Hinitial Hformat Hwidth Hvalue Hvalidation Hrun) as Hfinal.
  pose proof (transaction_vm_input_safe block tx validation Hrevision Hvalidation
    Hchain Hheader Hinitial Hformat Hwidth Hvalue) as Hsafe.
  pose proof (transaction_vm_input_metadata block tx validation) as Hmetadata.
  pose proof (transaction_vm_input_message block tx validation) as Hmessage.
  pose proof (transaction_vm_input_other_code block tx validation addr (proj1 Hinitial) Hauth) as Hcode.
  pose proof (transaction_vm_input_balances block tx validation Hvalidation Hinitial addr) as Hbalance.
  destruct (transactionVmInput block tx validation) as [msg entry] eqn:Hinput.
  cbn beta iota zeta delta [fst snd] in Hfinal, Hsafe, Hmetadata, Hmessage, Hcode, Hbalance |- ×.
  intro Hcreated.
  destruct Hmetadata as [HinitialWorld [Hblock [Horigin Hdes]]].
  destruct Hmessage as [HmsgSender [Hkind HcodeAddress]].
  destruct Hsafe as [Hcontext Hmsg].
  assert (HentryInv : balanceInvariant (S.t.world_state entry))
    by exact (proj1 (proj1 (proj1 Hcontext))).
  assert (Hgas : 0 ≤ Evmc.Message.t.gas msg < 2^63) by exact (proj1 Hmsg).
  assert (HnotDeleted : ¬ List.In addr (S.t.self_destruct (snd (callFromEoa tx msg entry)))).
  { destruct (@execution_call_from_eoa_preserves_creation F
      tx msg Hrevision Hgas entry (proj1 HentryInv)) as [_ Hframe].
    intro Hin. destruct (destruction_covered _ _ Hframe addr Hin) as [Hbefore|Hnew].
    - rewrite Hdes in Hbefore. contradiction.
    - exact (Hcreated Hnew). }
  pose proof (@execution_call_from_eoa_nondebit F

      (totalBalance (B.t.world_state block) - Numeric.U256.to_z (E.transaction_validation.total_fee validation))
      tx addr msg entry Hstaking Hrevision Hhash Hnative Hmsg Hkind (fun _ ⇒ HcodeAddress)
      ltac:(rewrite HmsgSender; congruence) Hcontext (eq_trans Hcode Hempty) Hcreated) as Hbound.
  assert (Hneq : String.eqb (E.transaction_validation.sender validation) addr = false)
    by (apply String.eqb_neq; congruence).
  rewrite Hneq in Hbalance. cbv beta in Hbalance, Hbound.
  change (Numeric.U256.to_z (A.t.balance (readAccount (S.t.world_state entry) addr)) ≤
    Numeric.U256.to_z (A.t.balance (readAccount
      (S.t.world_state (snd (callFromEoa tx msg entry))) addr))) in Hbound.
  cbv beta in Hbound. rewrite Hbalance in Hbound.
  pose proof (Hfinal addr HnotDeleted) as Hlast. cbv beta in Hlast |- ×. lia.
Qed.
Lemma transaction_vm_input_value block tx validation :
  Evmc.Message.t.value (fst (transactionVmInput block tx validation)) = T.value tx.
Proof.
  unfold transactionVmInput. destruct (prefix block tx validation) as [authorities prepared].
  cbn beta iota zeta delta [fst snd]. unfold E.prepare_message.
  destruct (T.call_or_create_value tx); reflexivity.
Qed.

Lemma validated_sender_noncontract block tx validation :
  @E.validate_transaction F block tx = inl validation →
  @A.is_smart_contract (readAccount (B.t.world_state block) (E.transaction_validation.sender validation)) = false.
Proof.
  intro Hvalidation. unfold E.validate_transaction in Hvalidation. cbn zeta in Hvalidation.
  do 13 (apply validation.bind_success in Hvalidation;
    let step := fresh "step" in let Hstep := fresh "Hstep" in
    destruct Hvalidation as [step [Hstep Hvalidation]]; cbn beta iota zeta in Hvalidation).
  injection Hvalidation as <-.
  cbn beta iota zeta delta [E.transaction_validation.sender].
  unfold A.is_smart_contract.
  match goal with
  | H : Result.when_ (andb (Byte_string.Bytes.op_ltgt ?code Byte_string.Bytes.empty)
      (negb ?delegated)) _ = inl _ |- _ ⇒
    destruct (andb (Byte_string.Bytes.op_ltgt code Byte_string.Bytes.empty) (negb delegated)) eqn:Hsc;
      [discriminate H|exact Hsc]
  end.
Qed.

Lemma emptying_sender_has_empty_code entry :
  @A.is_smart_contract (readAccount (S.t.world_state entry) (S.t.tx_origin entry)) = false →
  fst (emptying entry) = true →
  A.t.code (readAccount (S.t.world_state entry) (S.t.tx_origin entry)) = Byte_string.Bytes.empty.
Proof.
  intros Hsc Hempty.
  unfold Reserve_balance.is_emptying_tx in Hempty.
  cbn -[W.account W.next_emptying_transaction_block_for Delegation.is_valid_delegation] in Hempty.
  apply Bool.andb_true_iff in Hempty as [Hundelegated _].
  apply Bool.negb_true_iff in Hundelegated.
  unfold A.is_smart_contract in Hsc.
  change (@Delegation.is_valid_delegation (A.t.code (readAccount (S.t.world_state entry) (S.t.tx_origin entry))) = false) in Hundelegated.
  cbv beta in Hundelegated.
  match type of Hundelegated with ?delegated = false ⇒
    change (andb (Byte_string.Bytes.op_ltgt
      (A.t.code (readAccount (S.t.world_state entry) (S.t.tx_origin entry))) Byte_string.Bytes.empty)
      (negb delegated) = false) in Hsc
  end.
  rewrite Hundelegated in Hsc. rewrite Bool.andb_true_r in Hsc.
  change (negb (Z.eqb (OCamlString.compare
    (A.t.code (readAccount (S.t.world_state entry) (S.t.tx_origin entry))) String.EmptyString) 0
    ) = false) in Hsc.
  apply Bool.negb_false_iff, Z.eqb_eq in Hsc.
  apply reservecheck.address_compare_eq. exact Hsc.
Qed.

Emptying does not permit arbitrary loss of the sender's balance: the sender is undelegated, so the VM can spend only the root transfer value. The upfront gas charge is accounted for separately. Reverts and beneficiary credits can only improve this bound. This describes a processed transaction; it does not assume fee solvency of any later consensus-accepted transaction.
Theorem process_transaction_emptying_sender block tx validation post :
  (@E.Params F).(Execution.Make_Params_signature.revision) = Support.Variants.Revision.Eleven →
  keccak256OutputSize → @nativeOutputBounds args →
  wordRange (Support.UintN.to_z (Chain.Monad.PARAMS.chain_id params)) →
  headerWords (Chain.Ethereum.Block.t.header (B.t.current_block block)) →
  balanceInvariant (B.t.world_state block) → worldFormat (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 →
  let sender := E.transaction_validation.sender validation in
  MonadVM.Staking.staking_address ≠ sender →
  let '(msg, entry) := transactionVmInput block tx validation in
  fst (emptying entry) = true →
  ¬ List.In sender (S.t.accounts_created_in_current_transaction (snd (callFromEoa tx msg entry))) →
  Z.max (Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state block) sender)) -
    Numeric.U256.to_z (E.transaction_validation.total_fee validation) - Numeric.U256.to_z (T.value tx)) 0 ≤
  Numeric.U256.to_z (A.t.balance (readAccount (B.t.world_state post) sender)).
Proof using F U8 UB UI0.
  intros Hrevision Hhash Hnative Hchain Hheader Hinitial Hformat Hwidth Hvalue Hvalidation Hrun sender Hstaking.
  pose proof (validated_sender_noncontract block tx validation Hvalidation) as Hsc.
  pose proof (process_transaction_retains_host_balance block tx validation post Hrevision Hhash Hnative
    Hchain Hheader Hinitial Hformat Hwidth Hvalue Hvalidation Hrun) as Hfinal.
  pose proof (transaction_vm_input_safe block tx validation Hrevision Hvalidation
    Hchain Hheader Hinitial Hformat Hwidth Hvalue) as Hsafe.
  pose proof (transaction_vm_input_metadata block tx validation) as Hmetadata.
  pose proof (transaction_vm_input_message block tx validation) as Hmessage.
  pose proof (transaction_vm_input_value block tx validation) as HtransferValue.
  pose proof (transaction_vm_input_noncontract block tx validation sender (proj1 Hinitial) Hwidth Hsc) as Hentrysc.
  pose proof (transaction_vm_input_balances block tx validation Hvalidation Hinitial sender) as Hbalance.
  pose proof (@process_transaction_preserves_supply F UI0 UB U8
    block tx post Hrevision Hhash Hnative Hchain
    (proj1 (proj2 Hheader)) (proj2 (proj2 Hheader)) Hinitial Hformat Hwidth Hvalue Hrun) as [Hpost _].
  pose proof (@account_balance_bounded_by_supply (B.t.world_state post) sender
    (proj1 (proj2 Hpost))) as HpostBalance.
  destruct (transactionVmInput block tx validation) as [msg entry] eqn:Hinput.
  cbn beta iota zeta delta [fst snd] in Hfinal, Hsafe, Hmetadata, Hmessage, Hentrysc, Hbalance, HtransferValue |- ×.
  intros Hempty Hcreated.
  destruct Hmetadata as [HinitialWorld [Hblock [Horigin Hdes]]].
  destruct Hmessage as [HmsgSender [Hkind HcodeAddress]].
  destruct Hsafe as [Hcontext Hmsg].
  assert (HentryInv : balanceInvariant (S.t.world_state entry))
    by exact (proj1 (proj1 (proj1 Hcontext))).
  assert (Hgas : 0 ≤ Evmc.Message.t.gas msg < 2^63) by exact (proj1 Hmsg).
  assert (Hcode : A.t.code (readAccount (S.t.world_state entry) sender) = Byte_string.Bytes.empty).
  { unfold sender. rewrite <- Horigin. apply emptying_sender_has_empty_code; [rewrite Horigin; exact Hentrysc|exact Hempty]. }
  assert (HnotDeleted : ¬ List.In sender (S.t.self_destruct (snd (callFromEoa tx msg entry)))).
  { destruct (@execution_call_from_eoa_preserves_creation F
      tx msg Hrevision Hgas entry (proj1 HentryInv)) as [_ Hframe].
    intro Hin. destruct (destruction_covered _ _ Hframe sender Hin) as [Hbefore|Hnew].
    - rewrite Hdes in Hbefore. contradiction.
    - exact (Hcreated Hnew). }
  pose proof (@execution_call_from_eoa_value_bound F

      (totalBalance (B.t.world_state block) - Numeric.U256.to_z (E.transaction_validation.total_fee validation))
      tx sender msg entry Hstaking Hrevision Hhash Hnative Hmsg Hkind (fun _ ⇒ HcodeAddress)
      Hcontext Hcode Hcreated) as Hbound.
  fold sender in Hbalance. rewrite String.eqb_refl in Hbalance.
  change (Numeric.U256.to_z (A.t.balance (readAccount (S.t.world_state entry) sender)) -
    Numeric.U256.to_z (Evmc.Message.t.value msg) ≤
    Numeric.U256.to_z (A.t.balance (readAccount
      (S.t.world_state (snd (callFromEoa tx msg entry))) sender))) in Hbound.
  cbv beta in Hbalance, Hbound. rewrite Hbalance, HtransferValue in Hbound.
  pose proof (Hfinal sender HnotDeleted) as Hlast. cbv beta in Hlast, HpostBalance |- ×. lia.
Qed.

End Execution.

Print Assumptions transaction_vm_input_supply.
Print Assumptions transaction_vm_input_safe.
Print Assumptions process_transaction_retains_host_balance.
Print Assumptions process_transaction_nonsender_reserve.
Print Assumptions process_transaction_sender_reserve.

Print Assumptions process_transaction_nonsender_nondebit.

Print Assumptions process_transaction_emptying_sender.