Library SetcodeConcrete.nonceagreementsequence

Nonce prediction through an admitted transaction list

The creation premise refers only to executions reached from the supplied block state. Regular accounts need no creation premise: their concrete collision and deletion checks already prevent recreation or deletion. This preservation result is an ingredient of the full success proof, not a claim that successful execution may be assumed in that theorem.
From Stdlib Require Import List String ZArith.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import SetcodeConcrete.nonceagreement SetcodeConcrete.transactionentry
  SetcodeConcrete.consensuschecks SetcodeConcrete.supplysequence.
Set Default Goal Selector "!".
Import ListNotations.
Module E := Execution.Make.
Module B := State.BlockState.
Module S := State.TransactionState.
Module A := Chain.Ethereum.Account.
Module T := Chain.Ethereum.Transaction.
Module Block := Chain.Ethereum.Block.
Section Execution.
Context {F : E.FArgs}.

For each transaction, exclude sender-address creation only if its validator succeeds and the address is not already a contract. Recurse only on its actual returned state. Errors introduce no arbitrary state.
Fixpoint transactionsAvoidSenderCreation senders state txs : Prop :=
  match txs with
  | [] ⇒ True
  | tx :: rest ⇒
      (∀ validation, E.validate_transaction state tx = inl validation →
        ∀ a, In a senders → A.is_smart_contract (accountAt (B.t.world_state state) a) = false →
        ¬ In a (S.t.accounts_created_in_current_transaction (transactionFinished state tx validation))) ∧
      (∀ post, E.process_transaction state tx = inl post →
        transactionsAvoidSenderCreation senders post rest)
  end.

Context (cold warm access write reserve : N).
Context (Hrevision : E.Params.(Execution.Make_Params_signature.revision) =
  Support.Variants.Revision.Setcode (cold, warm, access, write, reserve)).
Context (Hcold : (0 < cold)%N) (Hwarm : (0 < warm)%N).

Theorem transactions_nonce_agreement snapshot previous next state txs post senders :
  (∀ a, In a senders → a ≠ Reserve_balance.precompile_address) →
  Forall (fun tx ⇒ Forall (fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
    (T.authorization_list tx)) txs →
  NonceAgreement (eligibleAt snapshot) (admissionNonces previous) (B.t.world_state state) senders →
  transactionsAvoidSenderCreation senders state txs →
  checkTransactions snapshot (Block.t.header (B.t.current_block state)) previous txs = Some next →
  Result.List.fold_leftM E.process_transaction state txs = inl post →
  NonceAgreement (eligibleAt snapshot) (admissionNonces next) (B.t.world_state post) senders.
Proof.
  intros Hnative Hwidth. revert previous state.
  induction Hwidth as [|tx rest HtxWidth Hrest IH];
    intros previous state Hbefore Hcreated Hcheck Hrun.
  - cbn [checkTransactions] in Hcheck. injection Hcheck as <-.
    injection Hrun as <-. exact Hbefore.
  - cbn [checkTransactions] in Hcheck.
    destruct (checkTransaction snapshot (Block.t.header (B.t.current_block state)) previous tx)
      as [middle|] eqn:Htx; [|discriminate].
    change (Result.op_letdollar (E.process_transaction state tx)
      (fun after ⇒ Result.List.fold_leftM E.process_transaction after rest) = inl post) in Hrun.
    destruct (E.process_transaction state tx) as [after|error] eqn:Hexec; [|discriminate].
    destruct Hcreated as [Hcreation Hcreated].
    assert (Hnext : NonceAgreement (eligibleAt snapshot) (admissionNonces middle)
      (B.t.world_state after) senders).
    { unfold checkTransaction in Htx.
      destruct (T.sender _ tx) as [sender|] eqn:Hsender; [|discriminate].
      destruct (Gas.tx_effective_gas_price _ tx); [|discriminate].
      match type of Htx with context [if ?condition then _ else _] ⇒
        destruct condition end; [|discriminate].
      cbn zeta in Htx.
      match type of Htx with context [if ?condition then _ else _] ⇒
        destruct condition end; [|discriminate].
      injection Htx as <-.
      exact (process_transaction_nonce_agreement cold warm access write reserve Hrevision Hcold Hwarm
        state tx after (eligibleAt snapshot) (admissionNonces previous) senders sender
        Hnative HtxWidth Hsender Hbefore Hcreation Hexec). }
    apply (IH middle after Hnext (Hcreated after Hexec)); [|exact Hrun].
    rewrite (process_transaction_current_block state tx after Hexec). exact Hcheck.
Qed.
End Execution.
Print Assumptions transactions_nonce_agreement.