Library QedkConcrete.consensusrequirements
Input bounds and reachable-state exclusions
From Stdlib Require Import List String ZArith Bool.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution
QedkConcrete.transactionstage QedkConcrete.transactionchecked
QedkConcrete.publictransaction QedkConcrete.wordrange.
Require Import QedkConcrete.nativeinputs.
Require Export QedkConcrete.stakingsystem.
Set Default Goal Selector "!".
Import ListNotations.
Local Open Scope Z_scope.
Module E := Execution.Make.
Module S := State.TransactionState.
Module B := State.BlockState.
Module W := State.WorldState.
Module A := Chain.Ethereum.Account.
Module T := Chain.Ethereum.Transaction.
Module Addr := Chain.Ethereum.Address.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution
QedkConcrete.transactionstage QedkConcrete.transactionchecked
QedkConcrete.publictransaction QedkConcrete.wordrange.
Require Import QedkConcrete.nativeinputs.
Require Export QedkConcrete.stakingsystem.
Set Default Goal Selector "!".
Import ListNotations.
Local Open Scope Z_scope.
Module E := Execution.Make.
Module S := State.TransactionState.
Module B := State.BlockState.
Module W := State.WorldState.
Module A := Chain.Ethereum.Account.
Module T := Chain.Ethereum.Transaction.
Module Addr := Chain.Ethereum.Address.
The staking precompile's address, using the same construction as the
OCaml staking module. It is protected from CREATE/CREATE2 separately from
transaction senders; this does not give it a sender's reserve protection.
Definition stakingAddress : Addr.t := Addr.of_hex_string None "0x1000".
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
Context {UI0 : Basics.Unreachable Support.UintN.Impl.t}
{UB : Basics.Unreachable Bloom.t}
{U8 : Basics.Unreachable Byte_string.B8.(Byte_string.Fixed.Fixed_result.t)}.
Local Abbreviation vmInput := (@transactionVmInput F).
Local Abbreviation callFromEoa := (@E.Host.call_from_eoa F).
Local Abbreviation processTransaction := (@E.process_transaction F).
Local Abbreviation readAccount := (fun world addr ⇒ State.op_pointcaretlparenrparen
world (@W.account None addr)).
Local Abbreviation native := (@Reserve_balance.precompile_address).
Local Abbreviation recoveredAuthority := (@Chain.Ethereum.Transaction.Authorization.authority).
Local Abbreviation systemMessage := (@E.process_system_message F).
Local Abbreviation activate := (@Reserve_balance.activate_precompile).
Context {UBlock : Basics.Unreachable Chain.Ethereum.Block.t}
{UTries : Basics.Unreachable (OCamlIarray.t Mpt.Trie.t)}
{UChar : Basics.Unreachable OCamlChar.t} {UWorld : Basics.Unreachable W.t}
{UTrie : Basics.Unreachable Mpt.Trie.t} {UNibbles : Basics.Unreachable Mpt.Nibbles.t}.
Local Abbreviation processBlock := (@E.process_block F).
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation args := (@E.Instantiation_fargs F).
Context {UI0 : Basics.Unreachable Support.UintN.Impl.t}
{UB : Basics.Unreachable Bloom.t}
{U8 : Basics.Unreachable Byte_string.B8.(Byte_string.Fixed.Fixed_result.t)}.
Local Abbreviation vmInput := (@transactionVmInput F).
Local Abbreviation callFromEoa := (@E.Host.call_from_eoa F).
Local Abbreviation processTransaction := (@E.process_transaction F).
Local Abbreviation readAccount := (fun world addr ⇒ State.op_pointcaretlparenrparen
world (@W.account None addr)).
Local Abbreviation native := (@Reserve_balance.precompile_address).
Local Abbreviation recoveredAuthority := (@Chain.Ethereum.Transaction.Authorization.authority).
Local Abbreviation systemMessage := (@E.process_system_message F).
Local Abbreviation activate := (@Reserve_balance.activate_precompile).
Context {UBlock : Basics.Unreachable Chain.Ethereum.Block.t}
{UTries : Basics.Unreachable (OCamlIarray.t Mpt.Trie.t)}
{UChar : Basics.Unreachable OCamlChar.t} {UWorld : Basics.Unreachable W.t}
{UTrie : Basics.Unreachable Mpt.Trie.t} {UNibbles : Basics.Unreachable Mpt.Nibbles.t}.
Local Abbreviation processBlock := (@E.process_block F).
world is the execution state before block. Return the transaction
processing state after activating the reserve precompile, initializing
this block and running its EIP-4788/EIP-2935 system messages, but before
any transaction or withdrawal. This is a BlockState, not a block.
Definition blockTransactionEntry (world : W.t) (block : Chain.Ethereum.Block.t) : B.t :=
let activated := activate world in
let initial := @B.make activated block in
let beacon := snd (systemMessage initial (@E.beacon_roots_address F)
(Byte_string.B32.(Byte_string.Fixed.Fixed_result.to_bytes)
(Chain.Ethereum.Block.Header.t.parent_beacon_block_root (Chain.Ethereum.Block.t.header block)))) in
let parent := @Chain.Ethereum.Block.hash (@Result.List.hd Chain.Ethereum.Block.t (@E._rocq_fallback_validate_block_0 F block) (W.t.history activated)) in
snd (systemMessage beacon (@E.history_storage_address F)
(Byte_string.B32.(Byte_string.Fixed.Fixed_result.to_bytes) parent)).
Local Abbreviation height := (fun block ⇒ Chain.Ethereum.Block.Header.t.number
(Chain.Ethereum.Block.t.header block)).
let activated := activate world in
let initial := @B.make activated block in
let beacon := snd (systemMessage initial (@E.beacon_roots_address F)
(Byte_string.B32.(Byte_string.Fixed.Fixed_result.to_bytes)
(Chain.Ethereum.Block.Header.t.parent_beacon_block_root (Chain.Ethereum.Block.t.header block)))) in
let parent := @Chain.Ethereum.Block.hash (@Result.List.hd Chain.Ethereum.Block.t (@E._rocq_fallback_validate_block_0 F block) (W.t.history activated)) in
snd (systemMessage beacon (@E.history_storage_address F)
(Byte_string.B32.(Byte_string.Fixed.Fixed_result.to_bytes) parent)).
Local Abbreviation height := (fun block ⇒ Chain.Ethereum.Block.Header.t.number
(Chain.Ethereum.Block.t.header block)).
accountAt snapshot a reads account a from the designated execution
snapshot S_h. Return its account record (nonce, balance, storage and code);
no transactions after block h are applied.
snapshot is S_h and addr is the address to test. Return true for ordinary
contract code there, false for empty code or an EIP-7702 delegation marker.
True means ineligible as a transaction sender, not "is delegated".
Definition isContractAt (snapshot : W.t) (addr : Addr.t) : bool :=
@A.is_smart_contract (accountAt snapshot addr).
@A.is_smart_contract (accountAt snapshot addr).
reserveAt snapshot b a is R_h(a,b) in the draft: account a's reserve
for block b, using only the configuration recorded in snapshot S_h.
The result is a U256 amount in wei, not an updated configuration.
The lookup compares the pending activation height with b to choose the
settled or pending reserve, or the default reserve for an unconfigured
account. It is not G_a, the remaining gas budget, and does not change storage.
Conditions on one block's inputs, not an admission or execution check.
Result: a proposition requiring the representation/height bounds below,
sender membership, and no recovered authorization signer equal to 0x1001.
Other authorization signers need not belong to signers. No assertion
here requires a transaction's nonce or balance check to pass.
- signers: the list which must contain each recovered transaction sender.
- until: upper window height, requiring b <= until < b+3 for this block.
- block: the candidate block, supplying its header, transactions and withdrawals.
Definition blockInputs (signers : list Addr.t) (until : N) (block : Chain.Ethereum.Block.t) : Prop :=
headerWords (Chain.Ethereum.Block.t.header block) ∧
OCamlString.length (Chain.Ethereum.Block.Header.t.parent_beacon_block_root
(Chain.Ethereum.Block.t.header block)) = 32 ∧
(height block ≤ until < height block + 3)%N ∧
Forall (fun tx ⇒ transactionValueAndDataBounds tx ∧
Forall (fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20)
(T.authorization_list tx) ∧
Forall (fun auth ⇒ recoveredAuthority auth ≠ Some native)
(T.authorization_list tx) ∧
(∀ a, transactionSender tx = Some a → List.In a signers)) (Chain.Ethereum.Block.t.transactions block) ∧
Forall (fun wd ⇒ 0 ≤ Numeric.U64.to_z (Chain.Ethereum.Withdrawal.t.amount wd) < 2^64)
(Chain.Ethereum.Block.t.withdrawals block).
headerWords (Chain.Ethereum.Block.t.header block) ∧
OCamlString.length (Chain.Ethereum.Block.Header.t.parent_beacon_block_root
(Chain.Ethereum.Block.t.header block)) = 32 ∧
(height block ≤ until < height block + 3)%N ∧
Forall (fun tx ⇒ transactionValueAndDataBounds tx ∧
Forall (fun auth ⇒ OCamlString.length (T.Authorization.t.address auth) = 20)
(T.authorization_list tx) ∧
Forall (fun auth ⇒ recoveredAuthority auth ≠ Some native)
(T.authorization_list tx) ∧
(∀ a, transactionSender tx = Some a → List.In a signers)) (Chain.Ethereum.Block.t.transactions block) ∧
Forall (fun wd ⇒ 0 ≤ Numeric.U64.to_z (Chain.Ethereum.Withdrawal.t.amount wd) < 2^64)
(Chain.Ethereum.Block.t.withdrawals block).
State the CREATE/CREATE2 exclusion for one transaction list.
Result: a proposition about each successfully executed prefix and the
next transaction, if that transaction validates. A listed address or
0x1000 which then has no ordinary contract code must not appear in the VM result's
created-accounts list. Delegation is allowed. This is a cryptographic
premise about this run, not about arbitrary starting states.
- signers: transaction-sender addresses covered by this exclusion; the staking address 0x1000 is additionally covered.
- block: the BlockState immediately before txs, not a block header.
- txs: the ordered transactions to execute from that state.
Definition prefixAvoidsSignerCreation signers block txs :=
∀ first tx last before,
txs = first ++ tx :: last →
Result.List.fold_leftM (@E.dispatch_transaction F) block first = inl before →
∀ validation a, (List.In a signers ∨ a = stakingAddress) →
@E.validate_transaction F before tx = inl validation →
@A.is_smart_contract (readAccount (B.t.world_state before) a) = false →
let '(msg, entry) := vmInput before tx validation in
¬ List.In a (S.t.accounts_created_in_current_transaction (snd (callFromEoa tx msg entry))).
∀ first tx last before,
txs = first ++ tx :: last →
Result.List.fold_leftM (@E.dispatch_transaction F) block first = inl before →
∀ validation a, (List.In a signers ∨ a = stakingAddress) →
@E.validate_transaction F before tx = inl validation →
@A.is_smart_contract (readAccount (B.t.world_state before) a) = false →
let '(msg, entry) := vmInput before tx validation in
¬ List.In a (S.t.accounts_created_in_current_transaction (snd (callFromEoa tx msg entry))).
signers lists the transaction-sender addresses; verify is the block-result
verification flag; world is the initial execution state; blocks is
the ordered list to execute.
Result: a proposition requiring prefixAvoidsSignerCreation in every
block reached after a successfully executed block prefix, provided that
block's header validation passes. Its starting transaction state includes
the system messages, via blockTransactionEntry. It does not assume that
the block prefix succeeds; it restricts whichever prefixes do succeed.
Definition windowAvoidsSignerCreation signers verify world blocks :=
∀ before block after reached,
blocks = before ++ block :: after →
Result.List.fold_leftM (processBlock verify) world before = inl reached →
@E.validate_block F reached block = inl tt →
prefixAvoidsSignerCreation signers (blockTransactionEntry reached block)
(Chain.Ethereum.Block.t.transactions block).
∀ before block after reached,
blocks = before ++ block :: after →
Result.List.fold_leftM (processBlock verify) world before = inl reached →
@E.validate_block F reached block = inl tt →
prefixAvoidsSignerCreation signers (blockTransactionEntry reached block)
(Chain.Ethereum.Block.t.transactions block).
State the concrete staking-syscall validity requirement for one transaction
list. Each Monad system transaction reached after a dispatched prefix must
carry valid calldata for one of the three staking syscalls
(syscall_snapshot, syscall_on_epoch_change,
syscall_reward) and satisfy its staking-storage
preconditions (validStakingSyscall). User EOA transactions are
unrestricted.
Definition prefixValidStakingSyscalls (block : B.t) (txs : list T.t) : Prop :=
∀ first tx last before,
txs = first ++ tx :: last →
Result.List.fold_leftM (@E.dispatch_transaction F) block first = inl before →
@E.is_system_transaction F tx = true →
validStakingSyscall (B.t.world_state before) tx.
∀ first tx last before,
txs = first ++ tx :: last →
Result.List.fold_leftM (@E.dispatch_transaction F) block first = inl before →
@E.is_system_transaction F tx = true →
validStakingSyscall (B.t.world_state before) tx.
Require prefixValidStakingSyscalls in every block reached after a
successfully executed block prefix whose header validates.
Definition windowValidStakingSyscalls verify world blocks : Prop :=
∀ before block after reached,
blocks = before ++ block :: after →
Result.List.fold_leftM (processBlock verify) world before = inl reached →
@E.validate_block F reached block = inl tt →
prefixValidStakingSyscalls (blockTransactionEntry reached block)
(Chain.Ethereum.Block.t.transactions block).
∀ before block after reached,
blocks = before ++ block :: after →
Result.List.fold_leftM (processBlock verify) world before = inl reached →
@E.validate_block F reached block = inl tt →
prefixValidStakingSyscalls (blockTransactionEntry reached block)
(Chain.Ethereum.Block.t.transactions block).
blocks is the supplied block list. Return the proposition that its
header heights are nondecreasing: every earlier height is <= each later
height. This permits equal heights and gaps; it does not establish
header validity, consensus acceptance or successful execution.