Library SetcodeConcrete.windownonceagreement

The public nonce prediction remains exact until migration

This is the nonce-preservation part of the admission proof. It follows the actual generated block processor, retaining the original admission. It does not yet prove that an accepted window executes successfully: reserve-budget backing is needed to eliminate fee-validation errors.
From Stdlib Require Import List String ZArith.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.blockentry.
Require Import SetcodeConcrete.nonceagreement SetcodeConcrete.nonceagreementsequence
  SetcodeConcrete.blocknonceagreement SetcodeConcrete.blockcode SetcodeConcrete.consensuschecks.
Set Default Goal Selector "!".
Import ListNotations.
Module E := Execution.Make.
Module B := State.BlockState.
Module Block := Chain.Ethereum.Block.
Module T := Chain.Ethereum.Transaction.
Section Execution.
Context {F : E.FArgs}.

Restrict creation only in blocks whose header passes and after block prefixes that actually return a state. Neither header validation nor prefix success is assumed; these implications delimit the execution.
Fixpoint blocksAvoidSenderCreation senders verify world blocks : Prop :=
  match blocks with
  | [] ⇒ True
  | block :: rest ⇒
      (E.validate_block world block = inl tt →
        transactionsAvoidSenderCreation senders (blockTransactionEntry world block)
          (Block.t.transactions block)) ∧
      (∀ post, E.process_block verify world block = inl post →
        blocksAvoidSenderCreation senders verify post rest)
  end.

Lemma processed_block_valid_header verify world block post :
  E.process_block verify world block = inl post → E.validate_block world block = inl tt.
Proof.
  intro Hrun. unfold E.process_block in Hrun.
  destruct (E.validate_block world block) as [[]|error] eqn:Hv; [reflexivity|discriminate].
Qed.
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 blocks_nonce_agreement verify snapshot previous next world blocks post senders :
  (∀ a, In a senders → a ≠ Reserve_balance.precompile_address) →
  Forall (fun block ⇒ Forall (fun tx ⇒ Forall
    (fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20%Z)
    (T.authorization_list tx)) (Block.t.transactions block)) blocks →
  prescribedSystemCode world →
  NonceAgreement (eligibleAt snapshot) (admissionNonces previous) world senders →
  blocksAvoidSenderCreation senders verify world blocks →
  checkBlocks snapshot previous blocks = Some next →
  Result.List.fold_leftM (E.process_block verify) world blocks = inl post →
  NonceAgreement (eligibleAt snapshot) (admissionNonces next) post senders.
Proof.
  intros Hnative Hwidth. revert previous world.
  induction Hwidth as [|block rest Hwidth Hrest IH];
    intros previous world Hsystem Hbefore Hcreation Hcheck Hrun.
  - cbn [checkBlocks] in Hcheck. injection Hcheck as <-.
    injection Hrun as <-. exact Hbefore.
  - cbn [checkBlocks] in Hcheck.
    match type of Hcheck with context [checkTransactions ?s ?h ?p ?ts] ⇒
      set (capped := p) in *;
      destruct (checkTransactions s h capped ts) as [middle|] eqn:Htxs end; [|discriminate].
    change (Result.op_letdollar (E.process_block verify world block)
      (fun after ⇒ Result.List.fold_leftM (E.process_block verify) after rest) = inl post) in Hrun.
    destruct (E.process_block verify world block) as [after|error] eqn:Hblock; [|discriminate].
    destruct Hcreation as [Hcreation Htail].
    assert (Hafter : NonceAgreement (eligibleAt snapshot) (admissionNonces middle) after senders).
    { exact (block_nonce_agreement cold warm access write reserve Hrevision Hcold Hwarm
        verify snapshot capped middle world block after senders Hnative Hwidth Hsystem Hbefore
        (Hcreation (processed_block_valid_header _ _ _ _ Hblock)) Htxs Hblock). }
    apply (IH middle after).
    + exact (block_preserves_system_code cold warm access write reserve verify world block after
        Hrevision Hcold Hwarm Hsystem Hblock).
    + exact Hafter.
    + exact (Htail after Hblock).
    + exact Hcheck.
    + exact Hrun.
Qed.
End Execution.
Print Assumptions blocks_nonce_agreement.