Library QedkConcrete.transactionchecks

Transaction validation before execution

These are the native validator's checks other than signature recovery, fee affordability and sender-code eligibility. Recovery and fees are checked separately by consensus. Sender-code eligibility follows from the main theorem's initial-state condition and proved preservation; the execution validator still checks it. The nonce comes from consensus's ordered sender/authorization scan. No VM execution or future state is an input.
From Stdlib Require Import Bool ZArith List.
From stdpp Require Import decidable numbers strings.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution MonadVM.Staking.
Set Default Goal Selector "!".
Import ListNotations.
Module E := Execution.Make.
Module T := Chain.Ethereum.Transaction.
Module Header := Chain.Ethereum.Block.Header.
Module U64 := Numeric.U64.
Module Constants := Chain.Monad.Constants.
Local Abbreviation asbool := bool_decide.

Check the system-transaction validity conditions other than sender recovery to Chain.Monad.system_sender and sender-code eligibility.
  • tx: the signed candidate system transaction.
  • expectedNonce: Chain.Monad.system_sender's account nonce after preceding transaction processing, calculated by consensus.
Result: true if tx is a legacy call to staking_address with a non-overflowing matching nonce and intrinsic/floor gas within the fixed 2,000,000 system-transaction gas limit.
Definition systemTransactionChecks (tx : T.t) (expectedNonce : U64.t) : bool :=
  let gasLimit := Gas.of_int 2000000%Z in
  (match tx with
   | T.Legacy txImpl ⇒
       match txImpl.(T.legacy_tx.to_) with
       | Some to_ ⇒ asbool (to_ = Staking.staking_address)
       | None ⇒ false
       end
   | _ ⇒ false
   end) &&
  asbool (T.nonce tx ≠ U64.max_t) &&
  asbool (expectedNonce = T.nonce tx) &&
  asbool (Gas.tx_intrinsic_gas tx ≤ gasLimit)%N &&
  asbool (Gas.tx_floor_gas tx ≤ gasLimit)%N.

Section Checks.
F supplies the chain ID and revision; no execution state is supplied.
Context {F : E.FArgs}.

Check the transaction-validity conditions other than sender recovery, gas-fee affordability and sender-code eligibility.
  • header: the transaction's block header, supplying the base fee.
  • tx: the signed candidate transaction.
  • expectedNonce: its sender's account nonce after preceding sender and authorization processing, calculated by consensus, not just read at S_h.
Result: true if all checks below pass, false otherwise. They check chain ID, sender nonce limit/equality, initcode size, intrinsic/maximum/floor gas, a nonempty SET_CODE authorization list and effective gas price. True alone does not establish full validity: checkTransaction also requires sender recovery and sufficient fees. The execution sender-code check is proved to pass under the existing theorem conditions, not checked here.
Definition transactionChecks (header : Header.t)
    (tx : T.t) (expectedNonce : U64.t) : bool :=
  let baseFee := header.(Header.t.base_fee_per_gas) in
  let gasLimit := T.gas_limit tx in
  let initcodeSize := match T.call_or_create_value tx with
    | T.Create {| T.call_or_create.Create.initcode := code |} ⇒ Byte_string.Bytes.length code
    | _ ⇒ 0%Z end in
  (match T.chain_id tx with
    | Some id ⇒ asbool (id = (@E.Params F).(Execution.Make_Params_signature.chain_id))
    | None ⇒ true end) &&
  asbool (T.nonce tx ≠ U64.max_t) &&
  asbool (expectedNonce = T.nonce tx) &&
  asbool (initcodeSize ≤ Constants.max_init_code_size)%Z &&
  asbool (Gas.tx_intrinsic_gas tx ≤ gasLimit)%N &&
  asbool (gasLimit ≤ Gas.tx_max_gas_limit)%N &&
  asbool (Gas.tx_floor_gas tx ≤ gasLimit)%N &&
  (match tx with T.SetCode t ⇒ match t.(T.set_code_tx.authorization_list) with
     | [] ⇒ false | _ :: _ ⇒ true end | _ ⇒ true end) &&
  (match Gas.tx_effective_gas_price baseFee tx with
   | Some price ⇒ asbool (baseFee ≤ price)%N
   | None ⇒ false end).
End Checks.