Library QedkConcrete.transactionchecks
Transaction validation before execution
From Stdlib Require Import Bool ZArith List.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Set Default Goal Selector "!".
Import ListNotations.
Module E := Execution.Make.
Module T := Chain.Ethereum.Transaction.
Section Checks.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Set Default Goal Selector "!".
Import ListNotations.
Module E := Execution.Make.
Module T := Chain.Ethereum.Transaction.
Section Checks.
F supplies the chain ID and revision; no execution state is supplied.
Check the transaction-validity conditions other than sender recovery and
gas-fee affordability.
Result: true if all checks below pass, false otherwise. They check chain
ID, sender nonce limit/equality, initcode size, intrinsic/maximum/floor gas,
sender code, a nonempty SET_CODE authorization list and effective gas price.
True alone does not establish full validity: checkTransaction also
requires sender recovery and sufficient remaining gas budget.
- 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.
- senderIsContract: whether its sender has ordinary contract code in S_h. Empty code and an EIP-7702 delegation marker both give false.
Definition transactionChecks (header : Chain.Ethereum.Block.Header.t)
(tx : T.t) (expectedNonce : Numeric.U64.t) (senderIsContract : bool) : bool :=
negb (match T.chain_id tx with
| Some id ⇒ Support.UintN.op_ltgt id (@E.Params F).(Execution.Make_Params_signature.chain_id)
| None ⇒ false end) &&
negb (Numeric.U64.op_eq (T.nonce tx) Numeric.U64.max_t) &&
negb (Numeric.U64.op_ltgt expectedNonce (T.nonce tx)) &&
negb (Z.gtb (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) Chain.Monad.Constants.max_init_code_size) &&
negb (Gas.op_gt (@Gas.tx_intrinsic_gas tx) (T.gas_limit tx)) &&
negb (Gas.op_gt (T.gas_limit tx) (@Gas.tx_max_gas_limit)) &&
negb (Gas.op_gt (@Gas.tx_floor_gas tx) (T.gas_limit tx)) &&
negb senderIsContract &&
(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 header.(Chain.Ethereum.Block.Header.t.base_fee_per_gas) tx with
| Some price ⇒ negb (Gas.op_lt price header.(Chain.Ethereum.Block.Header.t.base_fee_per_gas))
| None ⇒ false end).
End Checks.
(tx : T.t) (expectedNonce : Numeric.U64.t) (senderIsContract : bool) : bool :=
negb (match T.chain_id tx with
| Some id ⇒ Support.UintN.op_ltgt id (@E.Params F).(Execution.Make_Params_signature.chain_id)
| None ⇒ false end) &&
negb (Numeric.U64.op_eq (T.nonce tx) Numeric.U64.max_t) &&
negb (Numeric.U64.op_ltgt expectedNonce (T.nonce tx)) &&
negb (Z.gtb (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) Chain.Monad.Constants.max_init_code_size) &&
negb (Gas.op_gt (@Gas.tx_intrinsic_gas tx) (T.gas_limit tx)) &&
negb (Gas.op_gt (T.gas_limit tx) (@Gas.tx_max_gas_limit)) &&
negb (Gas.op_gt (@Gas.tx_floor_gas tx) (T.gas_limit tx)) &&
negb senderIsContract &&
(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 header.(Chain.Ethereum.Block.Header.t.base_fee_per_gas) tx with
| Some price ⇒ negb (Gas.op_lt price header.(Chain.Ethereum.Block.Header.t.base_fee_per_gas))
| None ⇒ false end).
End Checks.