Library QedkConcrete.authorizationnoncechecks

Public authorization nonce calculation

These are the functions used by consensus, separated from their execution correspondence proofs so revisions can share the same admission algorithm.
From Stdlib Require Import List String ZArith Bool Lia.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Set Default Goal Selector "!".
Import ListNotations.
Local Open Scope Z_scope.
Module E := Execution.Make.
Module T := Chain.Ethereum.Transaction.
Module Addr := Chain.Ethereum.Address.
Section Authorization.
Context {F : E.FArgs}.
Local Abbreviation recoveredAuthority := (@T.Authorization.authority).

eligible a says address a has empty code or a delegation marker; nonces a is its nonce before this entry; auth is one signed EIP-7702 authorization. The chain ID is supplied by F.
Return (Some authority, after) if the entry passes the chain-ID, nonce-limit, signature, code and nonce-equality checks, with that address's nonce incremented in after. Otherwise return (None, nonces). This function calculates nonce changes; it does not write delegation code.
Definition authorizationNonceStep (eligible : Addr.t → bool)
    (nonces : Addr.t → Numeric.U64.t) (auth : T.Authorization.t)
    : option Addr.t × (Addr.t → Numeric.U64.t) :=
  if orb
    (andb (Numeric.U256.op_ltgt (T.Authorization.t.chain_id auth) (@Numeric.U256.zero))
      (Support.UintN.op_ltgt (@Numeric.U256.to_uint (T.Authorization.t.chain_id auth))
        (@E.Params F).(Execution.Make_Params_signature.chain_id)))
    (Numeric.U64.op_eq (T.Authorization.t.nonce auth) Numeric.U64.max_t)
  then (None, nonces)
  else match recoveredAuthority auth with
  | None ⇒ (None, nonces)
  | Some authority ⇒
      if andb (eligible authority) (Numeric.U64.op_eq (T.Authorization.t.nonce auth) (nonces authority))
      then (Some authority, fun query ⇒ if String.eqb authority query
        then @Numeric.U64.op_plus (nonces authority) (@Numeric.U64.one) else nonces query)
      else (None, nonces)
  end.

Calculate authorization nonce changes without executing contract code.
  • eligible a: true if address a has empty code or a delegation marker.
  • initial: addresses already counted as applied, and the nonce of each address before this authorization list. The transaction's sender nonce must already have been incremented by the caller.
  • auths: the transaction's authorization list, processed in its given order.
Result: the accumulated applied-address list and final nonce function. Each entry passing chain-ID, nonce-limit, signature, code-eligibility and nonce-equality checks increments its authority's nonce and prepends that address. Other entries leave both components unchanged. Repeated authorities are checked against the nonce resulting from earlier entries.
Definition authorizationNonces (eligible : Addr.t → bool)
    (initial : list Addr.t × (Addr.t → Numeric.U64.t)) (auths : list T.Authorization.t)
    : list Addr.t × (Addr.t → Numeric.U64.t) :=
  OCamlList.fold_left (fun '(applied, nonces) auth ⇒
    let '(authority, after) := authorizationNonceStep eligible nonces auth in
    match authority with Some a ⇒ (a :: applied, after) | None ⇒ (applied, after) end)
    initial auths.

End Authorization.