Library QedkConcrete.blockentry

Concrete block entry before user transactions

These definitions name the generated system-message sequence and its validation errors. They do not assume a successful transaction or VM.
From Stdlib Require Import List String ZArith.
Require Import RocqOfOCaml.RocqOfOCaml MonadVM.Execution.
Set Default Goal Selector "!".
Module E := Execution.Make.
Module B := State.BlockState.
Module W := State.WorldState.
Section Execution.
Context {F : E.FArgs}.
Local Abbreviation systemMessage := (@E.process_system_message F).
Local Abbreviation activate := (@Reserve_balance.activate_precompile).
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 user 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)).

Lemma validate_block_no_transaction_error world block details :
  @E.validate_block F world block ≠
    inr (Execution.Error.Invalid_transaction details).
Proof.
  unfold E.validate_block.
  change (@Result.op_letdollar) with
    (fun (A B C : Set) (r : A + B) (f : A → C + B) ⇒
      match r with inl value ⇒ f value | inr error ⇒ inr error end).
  change (@Result.when_) with
    (fun (A : Set) (condition : bool) (r : unit + A) ⇒ if condition then r else inl tt).
  change (@Result._return) with (fun (A B : Set) (x : A) ⇒ @inl A B x).
  unfold E.invalid_block. cbn beta iota zeta.
  repeat (match goal with |- context [if ?condition then _ else _] ⇒ destruct condition end;
    cbn beta iota zeta).
  all: discriminate.
Qed.

Lemma validate_output_no_transaction_error block post details :
  @E.validate_input_block_against_output F block post ≠
    inr (Execution.Error.Invalid_transaction details).
Proof.
  unfold E.validate_input_block_against_output.
  change (@Result.op_letdollar) with
    (fun (A B C : Set) (r : A + B) (f : A → C + B) ⇒
      match r with inl value ⇒ f value | inr error ⇒ inr error end).
  change (@Result.when_) with
    (fun (A : Set) (condition : bool) (r : unit + A) ⇒ if condition then r else inl tt).
  change (@Result._return) with (fun (A B : Set) (x : A) ⇒ @inl A B x).
  unfold E.invalid_block. cbn beta iota zeta.
  repeat (match goal with |- context [if ?condition then _ else _] ⇒ destruct condition end;
    cbn beta iota zeta).
  all: discriminate.
Qed.
End Execution.