Library QedkConcrete.consensushistory

Consensus nonce and activity history without VM execution

The scan recovers senders, consumes their nonces, and processes authorizations sequentially. It reads initial code eligibility but never executes a transaction or reads its resulting balances/storage. Activity records contain senders and predicted applied authorities, not every recovered signer. Prediction is proved exact at this window's transaction senders; discrepancies at other addresses do not affect their fee budgets.
From Stdlib Require Import List String ZArith Bool Lia.
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import MonadVM.Execution QedkConcrete.authorizationnonces
  QedkConcrete.publictransaction QedkConcrete.transactioncode.
Set Default Goal Selector "!".
Import ListNotations.
Module E := Execution.Make.
Module A := Chain.Ethereum.Account.
Module W := State.WorldState.
Module T := Chain.Ethereum.Transaction.
Module Addr := Chain.Ethereum.Address.

Information calculated from the snapshot and the transactions already checked after it. This record contains neither blocks nor transaction lists. Nonce agreement with execution is proved for the window's transaction senders under the main theorem's assumptions.
Record ConsensusHistory := {
  
For each address, the snapshot nonce plus the increments from earlier senders and authorizations predicted to apply. checkTransaction uses this as the expected sender nonce; VM execution is not simulated.
Addresses that sent an earlier transaction or whose authorization is predicted to have applied in one. Membership rules out emptying later in this window. Receiving funds or signing a rejected authorization alone does not add an address. Repetitions are allowed; only membership is used.
  historyActivity : list Addr.t
}.

Section History.
F supplies the chain ID and revision for sender/authorization processing; the account state is supplied separately as snapshot.
snapshot is the designated execution state S_h. Return a ConsensusHistory with its account nonces and an empty historyActivity list: no transactions after this snapshot have yet been checked. Earlier emptying restrictions remain in snapshot and are read separately by historyAllowsEmptying.
Definition initialHistory (snapshot : W.t) : ConsensusHistory :=
  {| historyNonces := fun a ⇒ A.t.nonce (readAccount snapshot a);
     historyActivity := [] |}.

Calculate the nonce and emptying-eligibility changes for one transaction.
  • snapshot: S_h, used to read whether an account has ordinary contract code and is therefore ineligible for an authorization.
  • history: nonces and sender/authorization activity before tx.
  • sender: the recovered sender of tx, supplied by the caller.
  • tx: the transaction whose sender nonce and authorization list to process.
Result: (authorities, next) contains the addresses whose authorizations are predicted to apply in tx, and the updated ConsensusHistory. Rejected authorizations neither increment a nonce nor add an address. The sender nonce is consumed before testing its authorizations, as in concrete execution. The eligibility bit is read from the snapshot; the proof only needs it to remain valid for this window's transaction senders. This function does not check tx's sender nonce; checkTransaction does.
Definition advanceHistory (snapshot : W.t) (history : ConsensusHistory)
    (sender : Addr.t) (tx : T.t) : list Addr.t × ConsensusHistory :=
  let '(authorities, nonces) := @authorizationNonces F
    (fun a ⇒ negb (@A.is_smart_contract (readAccount snapshot a)))
    ([], fun a ⇒ if String.eqb sender a
      then @Numeric.U64.op_plus (historyNonces history a) (@Numeric.U64.one)
      else historyNonces history a) (T.authorization_list tx) in
  (authorities, {| historyNonces := nonces;
                  historyActivity := sender :: authorities ++ historyActivity history |}).

snapshot supplies account-code eligibility; history is the information before this list; txs is the ordered list to process with advanceHistory. Return Some next with the resulting history, or None if sender recovery fails. An empty list returns Some history. Gas budgets and sender nonce equality are not checked: this helper alone does not establish validity.
Fixpoint scanHistory (snapshot : W.t) (history : ConsensusHistory) (txs : list T.t)
    : option ConsensusHistory :=
  match txs with
  | [] ⇒ Some history
  | tx :: rest ⇒
      match transactionSender tx with
      | None ⇒ None
      | Some sender ⇒ scanHistory snapshot (snd (advanceHistory snapshot history sender tx)) rest
      end
  end.

Test emptying eligibility before the candidate's own authorizations.
  • snapshot: S_h, supplying delegation and the earliest emptying block already recorded by execution.
  • history: information about transactions already checked after S_h.
  • a: the candidate sender's address.
  • block: the candidate's block height, not the snapshot height.
Result: true exactly when a is undelegated in snapshot, its recorded earliest emptying block is no later than block, and it is absent from historyActivity. checkTransaction additionally excludes a sender whose authorization applies in the candidate itself. Within the K-block window, none of the activity in history is old enough to permit emptying again.
Definition historyAllowsEmptying (snapshot : W.t) (history : ConsensusHistory)
    (a : Addr.t) (block : N) : bool :=
  @emptyingEligible snapshot a block &&
    negb (existsb (fun addr ⇒ String.eqb addr a) (historyActivity history)).

End History.