Library SetcodeConcrete.consensusconditions

Conditions for the SETCODE consensus theorem

Conditions on the initial state and inputs are separate from the facts derived about executed prefixes. Amounts are in wei. A protected sender is an address in senders, which must contain every transaction sender; unrelated authorization signers need not be in that list.
From Stdlib Require Import List String NArith ZArith Bool Lia.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Require Import QedkConcrete.worldaccounts QedkConcrete.validation
  QedkConcrete.publictransaction QedkConcrete.reservecheck
  QedkConcrete.reservestorage QedkConcrete.reserveencoding
  QedkConcrete.hoststoragewords QedkConcrete.hostaccountformat
  QedkConcrete.hashwords QedkConcrete.precompileoutputs
  QedkConcrete.blsmapbounds QedkConcrete.nativeinputs
  QedkConcrete.supply QedkConcrete.wordrange QedkConcrete.credits
  QedkConcrete.protectedstorage QedkConcrete.protectedstoragenative
  QedkConcrete.protectedstorageboundarycore QedkConcrete.blockentry
  QedkConcrete.transactionchecks.
Require Export SetcodeConcrete.consensusresources SetcodeConcrete.rechecking.
Require Import SetcodeConcrete.consensuschecks SetcodeConcrete.reserve
  SetcodeConcrete.nonceagreement SetcodeConcrete.nonceagreementsequence
  SetcodeConcrete.activityagreement SetcodeConcrete.emptyingagreement
  SetcodeConcrete.blockcode SetcodeConcrete.blockconfig
  SetcodeConcrete.windowconfig SetcodeConcrete.blocknonceagreement
  SetcodeConcrete.blockactivityagreement SetcodeConcrete.blockemptyingagreement
  SetcodeConcrete.blocksupply SetcodeConcrete.windowsupply
  SetcodeConcrete.nativeoutputs SetcodeConcrete.windownonce
  SetcodeConcrete.windownonceagreement SetcodeConcrete.noncebudget
  SetcodeConcrete.consensusnonce SetcodeConcrete.consensusvalidation
  SetcodeConcrete.consensusresourcesproofs SetcodeConcrete.miscblockproofs
  SetcodeConcrete.transactionbudget SetcodeConcrete.blockbudget
  SetcodeConcrete.windowbudget.
Import ListNotations.
Set Default Goal Selector "!".
Local Open Scope Z_scope.
#[local] Hint Extern 100 (Basics.Unreachable _) ⇒
  (apply Opaque.legacy_witness; Opaque.opaque_inhabit 64%nat) : typeclass_instances.

Module E := Execution.Make.
Module B := State.BlockState.
Module W := consensuschecks.W.
Module A := consensuschecks.A.
Module T := consensuschecks.T.
Module Addr := consensuschecks.Addr.
Module Block := consensuschecks.Block.
Local Abbreviation native := Reserve_balance.precompile_address.
Local Abbreviation accountAt := consensuschecks.accountAt.

Conditions for execution from snapshot of ordered blocks. senders contains all transaction senders; until bounds the three-height window. verify is the generated executor's result-comparison flag, also used by the reached-state creation restriction. The main theorem uses false. This is a proposition about inputs, not an executable consensus check.
Record SetcodeWindowConditions {F : E.FArgs}
    (senders : list Addr.t) (until : N) (verify : bool)
    (snapshot : W.t) (blocks : list Block.t) : Prop := {
  
Initial balance/format/system-code and decoded-input conditions, bounded supply and nonce allowance, and transaction-sender membership.
Valid reserve-precompile storage map and encoded settings initially.
Well-formed map of earliest blocks at which accounts may empty.
Listed senders initially have empty code or delegation markers.
  window_sender_eligibility :
    ∀ a, In a senders → A.is_smart_contract (accountAt snapshot a) = false;
  
No sender or recovered authorization signer is the reserve precompile; transactions may still call that precompile.
Every block lies among at most three heights ending at until. Consecutive-height checks are supplied separately by miscBlockChecks.
  window_heights :
    Forall (fun block ⇒
      (Block.Header.t.number (Block.t.header block) ≤ until <
        Block.Header.t.number (Block.t.header block) + 3)%N) blocks;
  
Cryptographic exclusion: reached CREATE/CREATE2 executions cannot create a protected sender that is not already a contract. This constrains reached states, not arbitrary hypothetical VM inputs.
Facts proved about post, reached by executing past from snapshot. past ++ rest is the originally admitted sequence. height is its original budget-initialization height; until, senders and verify have the same meaning as in SetcodeWindowConditions.
This record is a conclusion, not an additional premise for the initial window. It retains admission against snapshot; it does not claim a fresh consensus check against post accepts migrated senders.
Record RemainingWindowInvariant {F : E.FArgs}
    (senders : list Addr.t) (until : N) (verify : bool)
    (snapshot : W.t) (height : N) (past rest : list Block.t) (post : W.t) : Prop := {
  
Actual post-state balance/format/system-code invariants and enough aggregate supply/nonce capacity for all remaining work.
middle is consensus state after past, next after rest, both computed using the original snapshot. WindowBudgetBacking relates middle to actual post: budgets are funded, unmigrated nonces agree, and reserve configuration and emptying activity remain consistent.
The original reached-state CREATE exclusion also holds for the remaining execution starting at post; it is not assumed again.