Library MonadVM.State

File generated by rocq-of-ocaml
Require Import RocqOfOCaml.RocqOfOCaml.
Require Import RocqOfOCaml.Settings.

Require Import MonadVM.Support.UintN.
Require MonadVM.Bloom.
Require MonadVM.Byte_string.
Require MonadVM.Chain.Ethereum.
Require MonadVM.Chain.Monad.
Require MonadVM.Crypto.
Require MonadVM.Delegation.
Require MonadVM.Evmc.
Require MonadVM.Gas.
Require MonadVM.Map.
Require MonadVM.Monad.
Require MonadVM.Mpt.
Require MonadVM.Numeric.
Require MonadVM.Option.
Require MonadVM.Rlp.
Require MonadVM.String.
Require MonadVM.Traits.

Require Import MonadVM.Support.Variants.
Require MonadVM.Support.CryptoBlake2.
Require Import RocqOfOCaml.Opaque.
Local Ltac _rocq_witness_type typ :=
  let typ := eval hnf in typ in
  lazymatch typ with
  | list ?a ⇒ let a := _rocq_witness_type a in constr:(list a)
  | option ?a ⇒ let a := _rocq_witness_type a in constr:(option a)
  | prod ?a ?b ⇒ let a := _rocq_witness_type a in
      let b := _rocq_witness_type b in constr:(prod a b)
  | sum ?a ?b ⇒ let a := _rocq_witness_type a in
      let b := _rocq_witness_type b in constr:(sum a b)
  | ?a → ?b ⇒ let a := _rocq_witness_type a in
      let b := _rocq_witness_type b in constr:(a → b)
  | _ ⇒ typ
  end.
Definition op_pointcaretlparenrparen {A B : Set}
  (x_value : A) (lens : Lens.t A B) : B := lens.(Lens.t.get) x_value.

Definition op_pointcaretlparenrparenltminus {A B : Set}
  (x_value : A) (lens : Lens.t A B) (v' : B) : A :=
  lens.(Lens.t.set) v' x_value.

Definition op_pointcaretdollarlparenrparenltminus {A B : Set}
  (x_value : A) (lens : Lens.t A B) (f_value : B → B) : A :=
  Lens.modify lens f_value x_value.

Module WorldState.
State across multiple blocks. Tracks accounts, storage, and all previously validated blocks. This includes the world state as per YP 4.1.
  Module t.
    Record record : Set := Build {
      history : list MonadVM.Chain.Ethereum.Block.t;
      accounts :
        MonadVM.Chain.Ethereum.Address.Map.t MonadVM.Chain.Ethereum.Account.t;
      next_emptying_transaction_block :
        MonadVM.Chain.Ethereum.Address.Map.t MonadVM.Support.UintN.t;
    }.
    Definition with_history history (r : record) :=
      Build history r.(accounts) r.(next_emptying_transaction_block).
    Definition with_accounts accounts (r : record) :=
      Build r.(history) accounts r.(next_emptying_transaction_block).
    Definition with_next_emptying_transaction_block
      next_emptying_transaction_block (r : record) :=
      Build r.(history) r.(accounts) next_emptying_transaction_block.
  End t.
  Definition t := t.record.

State across multiple blocks. Tracks accounts, storage, and all previously validated blocks. This includes the world state as per YP 4.1.
  Module TLens.
State across multiple blocks. Tracks accounts, storage, and all previously validated blocks. This includes the world state as per YP 4.1.
    Definition history : Lens.t t (list MonadVM.Chain.Ethereum.Block.t) :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒ r_value.(MonadVM.State.WorldState.t.history);
        Lens.t.set :=
          fun (v_value : list MonadVM.Chain.Ethereum.Block.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.WorldState.t.with_history v_value r_value; |}.

State across multiple blocks. Tracks accounts, storage, and all previously validated blocks. This includes the world state as per YP 4.1.
    Definition accounts
      : Lens.t t
        (MonadVM.Chain.Ethereum.Address.Map.t MonadVM.Chain.Ethereum.Account.t) :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒ r_value.(MonadVM.State.WorldState.t.accounts);
        Lens.t.set :=
          fun (v_value :
            MonadVM.Chain.Ethereum.Address.Map.t
              MonadVM.Chain.Ethereum.Account.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.WorldState.t.with_accounts v_value r_value; |}.

State across multiple blocks. Tracks accounts, storage, and all previously validated blocks. This includes the world state as per YP 4.1.
    Definition next_emptying_transaction_block
      : Lens.t t (MonadVM.Chain.Ethereum.Address.Map.t MonadVM.Support.UintN.t) :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.WorldState.t.next_emptying_transaction_block);
        Lens.t.set :=
          fun (v_value :
            MonadVM.Chain.Ethereum.Address.Map.t MonadVM.Support.UintN.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.WorldState.t.with_next_emptying_transaction_block
                v_value r_value; |}.
  End TLens.

State across multiple blocks. Tracks accounts, storage, and all previously validated blocks. This includes the world state as per YP 4.1. State across multiple blocks. Tracks accounts, storage, and all previously validated blocks. This includes the world state as per YP 4.1.


  Definition history := TLens.history.

  Definition accounts := TLens.accounts.

  Definition next_emptying_transaction_block :=
    TLens.next_emptying_transaction_block.

  Definition empty : t :=
    {| MonadVM.State.WorldState.t.history := nil;
      MonadVM.State.WorldState.t.accounts :=
        MonadVM.Chain.Ethereum.Address.Map.empty;
      MonadVM.State.WorldState.t.next_emptying_transaction_block :=
        MonadVM.Chain.Ethereum.Address.Map.empty; |}.

account_opt addr provides a lens into the current state of the account for addr. Addresses that do not correspond to entries in the underlying map correspond to None. EIP-161 deletion of touched empty accounts is done here, which frees the implementation from keeping track of touched accounts. Note that the Ethereum executable spec uses a similar approach by intercepting any state updates to an account and deleting it if it is empty after the update.
  Definition account_opt (keep_empty_optional : option bool)
    : MonadVM.Chain.Ethereum.Address.Map.key →
    Lens.t t (option MonadVM.Chain.Ethereum.Account.t) :=
    match keep_empty_optional with
    | Some keep_empty ⇒
      fun (addr : MonadVM.Chain.Ethereum.Address.Map.key) ⇒
        let '{| Lens.t.get := get; Lens.t.set := set |} :=
          Lens.Infix.op_pipeminusminus accounts
            (MonadVM.Chain.Ethereum.Address.Map._at addr) in
        let set :=
          if keep_empty then
            set
          else
            fun (acct : option MonadVM.Chain.Ethereum.Account.t) ⇒
              fun (state : t) ⇒
                let acct :=
                  match
                    (acct,
                      match acct with
                      | Some acct ⇒
                        MonadVM.Chain.Ethereum.Account.is_empty acct
                      | _ ⇒ false
                      end) with
                  | (Some acct, true) ⇒ None
                  | (_, _) ⇒ acct
                  end in
                set acct state in
        {| Lens.t.get := get; Lens.t.set := set; |}
    | None ⇒
      let 'keep_empty := false in
      fun (addr : MonadVM.Chain.Ethereum.Address.Map.key) ⇒
        let '{| Lens.t.get := get; Lens.t.set := set |} :=
          Lens.Infix.op_pipeminusminus accounts
            (MonadVM.Chain.Ethereum.Address.Map._at addr) in
        let set :=
          if keep_empty then
            set
          else
            fun (acct : option MonadVM.Chain.Ethereum.Account.t) ⇒
              fun (state : t) ⇒
                let acct :=
                  match
                    (acct,
                      match acct with
                      | Some acct ⇒
                        MonadVM.Chain.Ethereum.Account.is_empty acct
                      | _ ⇒ false
                      end) with
                  | (Some acct, true) ⇒ None
                  | (_, _) ⇒ acct
                  end in
                set acct state in
        {| Lens.t.get := get; Lens.t.set := set; |}
    end.

account addr provides a lens into the current state of the account for addr. Addresses that do not correspond to entries in the underlying map are considered to correspond to empty accounts. Conversely, setting the account of an address to the empty account deletes it from the underlying map. Since non-existent accounts are treated as empty, we do not make a distinction between empty (YP (14)) and dead (YP (15)) accounts. As with {!account_opt}, updating an account to be empty removes it from the underlying map.
  Definition account (keep_empty_optional : option bool)
    : MonadVM.Chain.Ethereum.Address.Map.key →
    Lens.t t MonadVM.Chain.Ethereum.Account.t :=
    match keep_empty_optional with
    | Some keep_empty ⇒
      fun (addr : MonadVM.Chain.Ethereum.Address.Map.key) ⇒
        Lens.Infix.op_pipeminusminus (account_opt (Some keep_empty) addr)
          (MonadVM.Option.get_or_default MonadVM.Chain.Ethereum.Account.empty)
    | None ⇒
      let 'keep_empty := false in
      fun (addr : MonadVM.Chain.Ethereum.Address.Map.key) ⇒
        Lens.Infix.op_pipeminusminus (account_opt (Some keep_empty) addr)
          (MonadVM.Option.get_or_default MonadVM.Chain.Ethereum.Account.empty)
    end.

next_emptying_transaction_block_for addr returns the block number of the next block in which a transaction from account addr would be considered emptying.
  Definition next_emptying_transaction_block_for
    (addr : MonadVM.Chain.Ethereum.Address.Map.key)
    : Lens.t t MonadVM.Support.UintN.t :=
    Lens.Infix.op_pipeminusminus
      (Lens.Infix.op_pipeminusminus next_emptying_transaction_block
        (MonadVM.Chain.Ethereum.Address.Map._at addr))
      (MonadVM.Option.get_or_default MonadVM.Support.UintN.zero).

state_root state computes the state root of the current account map. This involves computing the storage roots of every account in the state, which is very expensive.
  Definition state_root (state : t) : string :=
    let mpt :=
      MonadVM.Mpt.of_seq
        (RocqOfOCaml.OCamlSeq.map
          (fun (function_parameter :
            MonadVM.Chain.Ethereum.Address.t × MonadVM.Chain.Ethereum.Account.t)
            ⇒
            let '(addr, acc) := function_parameter in
            let address_hash :=
              MonadVM.Crypto.keccak_256
                (MonadVM.Chain.Ethereum.Address.to_bytes addr) in
            ((MonadVM.Byte_string.B32.(MonadVM.Byte_string.Fixed.Fixed_result.to_bytes)
              address_hash),
              (MonadVM.Rlp.encode (MonadVM.Chain.Ethereum.Account.to_rlp acc))))
          (MonadVM.Chain.Ethereum.Address.Map.to_seq
            state.(MonadVM.State.WorldState.t.accounts))) in
    mpt.(MonadVM.Mpt.t.root_hash).
End WorldState.

Module BlockState.
State across multiple transactions in a single block. Tracks the world state, the gas that has been consumed so far by transactions in the block, logs and receipts.
  Module t.
    Record record : Set := Build {
      world_state : WorldState.t;
      current_block : MonadVM.Chain.Ethereum.Block.t;
      gas_used : MonadVM.Gas.t;
      transactions_processed :
        list
          (MonadVM.Chain.Ethereum.Transaction.t ×
            MonadVM.Chain.Ethereum.Receipt.t);
      transaction_frames : list (MonadVM.Evmc.Message.t × MonadVM.Evmc.Result.t);
      withdrawals_processed : list MonadVM.Chain.Ethereum.Withdrawal.t;
      requests : list MonadVM.Byte_string.Bytes.t;
    }.
    Definition with_world_state world_state (r : record) :=
      Build world_state r.(current_block) r.(gas_used)
        r.(transactions_processed) r.(transaction_frames)
        r.(withdrawals_processed) r.(requests).
    Definition with_current_block current_block (r : record) :=
      Build r.(world_state) current_block r.(gas_used)
        r.(transactions_processed) r.(transaction_frames)
        r.(withdrawals_processed) r.(requests).
    Definition with_gas_used gas_used (r : record) :=
      Build r.(world_state) r.(current_block) gas_used
        r.(transactions_processed) r.(transaction_frames)
        r.(withdrawals_processed) r.(requests).
    Definition with_transactions_processed transactions_processed
      (r : record) :=
      Build r.(world_state) r.(current_block) r.(gas_used)
        transactions_processed r.(transaction_frames) r.(withdrawals_processed)
        r.(requests).
    Definition with_transaction_frames transaction_frames (r : record) :=
      Build r.(world_state) r.(current_block) r.(gas_used)
        r.(transactions_processed) transaction_frames r.(withdrawals_processed)
        r.(requests).
    Definition with_withdrawals_processed withdrawals_processed (r : record) :=
      Build r.(world_state) r.(current_block) r.(gas_used)
        r.(transactions_processed) r.(transaction_frames) withdrawals_processed
        r.(requests).
    Definition with_requests requests (r : record) :=
      Build r.(world_state) r.(current_block) r.(gas_used)
        r.(transactions_processed) r.(transaction_frames)
        r.(withdrawals_processed) requests.
  End t.
  Definition t := t.record.

State across multiple transactions in a single block. Tracks the world state, the gas that has been consumed so far by transactions in the block, logs and receipts.
  Module TLens.
State across multiple transactions in a single block. Tracks the world state, the gas that has been consumed so far by transactions in the block, logs and receipts.
    Definition world_state : Lens.t t WorldState.t :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒ r_value.(MonadVM.State.BlockState.t.world_state);
        Lens.t.set :=
          fun (v_value : WorldState.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.BlockState.t.with_world_state v_value r_value; |}.

State across multiple transactions in a single block. Tracks the world state, the gas that has been consumed so far by transactions in the block, logs and receipts.
    Definition current_block : Lens.t t MonadVM.Chain.Ethereum.Block.t :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.BlockState.t.current_block);
        Lens.t.set :=
          fun (v_value : MonadVM.Chain.Ethereum.Block.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.BlockState.t.with_current_block v_value r_value; |}.

State across multiple transactions in a single block. Tracks the world state, the gas that has been consumed so far by transactions in the block, logs and receipts.
    Definition gas_used : Lens.t t MonadVM.Gas.t :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒ r_value.(MonadVM.State.BlockState.t.gas_used);
        Lens.t.set :=
          fun (v_value : MonadVM.Gas.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.BlockState.t.with_gas_used v_value r_value; |}.

State across multiple transactions in a single block. Tracks the world state, the gas that has been consumed so far by transactions in the block, logs and receipts.
    Definition transactions_processed
      : Lens.t t
        (list
          (MonadVM.Chain.Ethereum.Transaction.t ×
            MonadVM.Chain.Ethereum.Receipt.t)) :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.BlockState.t.transactions_processed);
        Lens.t.set :=
          fun (v_value :
            list
              (MonadVM.Chain.Ethereum.Transaction.t ×
                MonadVM.Chain.Ethereum.Receipt.t)) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.BlockState.t.with_transactions_processed v_value
                r_value; |}.

State across multiple transactions in a single block. Tracks the world state, the gas that has been consumed so far by transactions in the block, logs and receipts.
    Definition transaction_frames
      : Lens.t t (list (MonadVM.Evmc.Message.t × MonadVM.Evmc.Result.t)) :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.BlockState.t.transaction_frames);
        Lens.t.set :=
          fun (v_value : list (MonadVM.Evmc.Message.t × MonadVM.Evmc.Result.t))
            ⇒
            fun (r_value : t) ⇒
              MonadVM.State.BlockState.t.with_transaction_frames v_value r_value;
        |}.

State across multiple transactions in a single block. Tracks the world state, the gas that has been consumed so far by transactions in the block, logs and receipts.
    Definition withdrawals_processed
      : Lens.t t (list MonadVM.Chain.Ethereum.Withdrawal.t) :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.BlockState.t.withdrawals_processed);
        Lens.t.set :=
          fun (v_value : list MonadVM.Chain.Ethereum.Withdrawal.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.BlockState.t.with_withdrawals_processed v_value
                r_value; |}.

State across multiple transactions in a single block. Tracks the world state, the gas that has been consumed so far by transactions in the block, logs and receipts.
    Definition requests : Lens.t t (list MonadVM.Byte_string.Bytes.t) :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒ r_value.(MonadVM.State.BlockState.t.requests);
        Lens.t.set :=
          fun (v_value : list MonadVM.Byte_string.Bytes.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.BlockState.t.with_requests v_value r_value; |}.
  End TLens.

State across multiple transactions in a single block. Tracks the world state, the gas that has been consumed so far by transactions in the block, logs and receipts. State across multiple transactions in a single block. Tracks the world state, the gas that has been consumed so far by transactions in the block, logs and receipts.


  Definition world_state := TLens.world_state.

  Definition current_block := TLens.current_block.

  Definition gas_used := TLens.gas_used.

  Definition transactions_processed := TLens.transactions_processed.

  Definition transaction_frames := TLens.transaction_frames.

  Definition withdrawals_processed := TLens.withdrawals_processed.

  Definition requests := TLens.requests.

  Definition make
    (world_state : WorldState.t)
    (current_block : MonadVM.Chain.Ethereum.Block.t) : t :=
    {| MonadVM.State.BlockState.t.world_state := world_state;
      MonadVM.State.BlockState.t.current_block := current_block;
      MonadVM.State.BlockState.t.gas_used := MonadVM.Gas.zero;
      MonadVM.State.BlockState.t.transactions_processed := nil;
      MonadVM.State.BlockState.t.transaction_frames := nil;
      MonadVM.State.BlockState.t.withdrawals_processed := nil;
      MonadVM.State.BlockState.t.requests := nil; |}.

  Definition account (keep_empty_optional : option bool)
    : MonadVM.Chain.Ethereum.Address.Map.key →
    Lens.t t MonadVM.Chain.Ethereum.Account.t :=
    match keep_empty_optional with
    | Some keep_empty ⇒
      fun (addr : MonadVM.Chain.Ethereum.Address.Map.key) ⇒
        Lens.Infix.op_pipeminusminus world_state
          (WorldState.account (Some keep_empty) addr)
    | None ⇒
      let 'keep_empty := false in
      fun (addr : MonadVM.Chain.Ethereum.Address.Map.key) ⇒
        Lens.Infix.op_pipeminusminus world_state
          (WorldState.account (Some keep_empty) addr)
    end.

  Definition account_opt (keep_empty_optional : option bool)
    : MonadVM.Chain.Ethereum.Address.Map.key →
    Lens.t t (option MonadVM.Chain.Ethereum.Account.t) :=
    match keep_empty_optional with
    | Some keep_empty ⇒
      fun (addr : MonadVM.Chain.Ethereum.Address.Map.key) ⇒
        Lens.Infix.op_pipeminusminus world_state
          (WorldState.account_opt (Some keep_empty) addr)
    | None ⇒
      let 'keep_empty := false in
      fun (addr : MonadVM.Chain.Ethereum.Address.Map.key) ⇒
        Lens.Infix.op_pipeminusminus world_state
          (WorldState.account_opt (Some keep_empty) addr)
    end.

finalize_current_block bs returns bs.current_block with its header updated to reflect the new state after block execution. This will overwrite header fields parent_hash, state_root, transactions_root, receipts_root, withdrawals_root, logs_bloom, requests_hash, gas_used and blob_gas_used.
  Definition _rocq_fallback_finalize_current_block_0 :
    ltac:(let typ := constr:(ltac:(first [unshelve refine ((RocqOfOCaml.OCamlChar.t)%type
    )]; first [match goal with |- ?g ⇒ let sort := type of g in lazymatch sort with Set ⇒ fail | _ ⇒ shelve end end | eassumption | typeclasses eauto | RocqOfOCaml.Opaque.opaque_inhabit 64%nat])) in let typ := _rocq_witness_type typ in exact typ).
  Proof. unshelve (RocqOfOCaml.Opaque.opaque_inhabit 64%nat). all: RocqOfOCaml.Opaque.opaque_inhabit 64%nat. Qed.

  Definition _rocq_fallback_finalize_current_block_1 :
    ltac:(let typ := constr:(ltac:(first [unshelve refine ((MonadVM.Chain.Ethereum.Block.t)%type
    )]; first [match goal with |- ?g ⇒ let sort := type of g in lazymatch sort with Set ⇒ fail | _ ⇒ shelve end end | exact
    _rocq_fallback_finalize_current_block_0 | eassumption | typeclasses eauto | RocqOfOCaml.Opaque.opaque_inhabit 64%nat])) in let typ := _rocq_witness_type typ in exact typ).
  Proof. unshelve (RocqOfOCaml.Opaque.opaque_inhabit 64%nat). all: RocqOfOCaml.Opaque.opaque_inhabit 64%nat. Qed.

  Definition finalize_current_block (block_state : t)
    : MonadVM.Chain.Ethereum.Block.t :=
    let parent_hash :=
      MonadVM.Chain.Ethereum.Block.hash
        ((RocqOfOCaml.OCamlList.hd
          (H := RocqOfOCaml.Opaque.legacy_witness _rocq_fallback_finalize_current_block_1))
          block_state.(MonadVM.State.BlockState.t.world_state).(MonadVM.State.WorldState.t.history))
      in
    let state_root :=
      WorldState.state_root block_state.(MonadVM.State.BlockState.t.world_state)
      in
    let transactions_root :=
      (MonadVM.Mpt.of_seq_i
        (RocqOfOCaml.OCamlSeq.map
          (fun (function_parameter :
            MonadVM.Chain.Ethereum.Transaction.t ×
              MonadVM.Chain.Ethereum.Receipt.t) ⇒
            let '(tx, _) := function_parameter in
            MonadVM.Chain.Ethereum.Transaction.encode tx)
          (RocqOfOCaml.OCamlList.to_seq
            block_state.(MonadVM.State.BlockState.t.transactions_processed)))).(MonadVM.Mpt.t.root_hash)
      in
    let receipts_root :=
      (MonadVM.Mpt.of_seq_i
        (RocqOfOCaml.OCamlSeq.map
          (fun (function_parameter :
            MonadVM.Chain.Ethereum.Transaction.t ×
              MonadVM.Chain.Ethereum.Receipt.t) ⇒
            let '(_, receipt) := function_parameter in
            MonadVM.Chain.Ethereum.Receipt.encode receipt)
          (RocqOfOCaml.OCamlList.to_seq
            block_state.(MonadVM.State.BlockState.t.transactions_processed)))).(MonadVM.Mpt.t.root_hash)
      in
    let withdrawals_root :=
      (MonadVM.Mpt.of_seq_i
        (RocqOfOCaml.OCamlSeq.map
          (fun (w_value : MonadVM.Chain.Ethereum.Withdrawal.t) ⇒
            MonadVM.Chain.Ethereum.Withdrawal.encode w_value)
          (RocqOfOCaml.OCamlList.to_seq
            block_state.(MonadVM.State.BlockState.t.withdrawals_processed)))).(MonadVM.Mpt.t.root_hash)
      in
    let logs_bloom :=
      MonadVM.Bloom.union
        (RocqOfOCaml.OCamlSeq.map
          (fun (function_parameter :
            MonadVM.Chain.Ethereum.Transaction.t ×
              MonadVM.Chain.Ethereum.Receipt.t) ⇒
            let '(_, receipt) := function_parameter in
            receipt.(MonadVM.Chain.Ethereum.Receipt.t.bloom))
          (RocqOfOCaml.OCamlList.to_seq
            block_state.(MonadVM.State.BlockState.t.transactions_processed))) in
    let requests_hash :=
      MonadVM.Crypto.sha_256
        (MonadVM.Byte_string.Bytes.concat MonadVM.Byte_string.Bytes.empty
          (RocqOfOCaml.OCamlList.stable_sort
            (fun (r_a : MonadVM.Byte_string.Bytes.t) ⇒
              fun (r_b : MonadVM.Byte_string.Bytes.t) ⇒
                RocqOfOCaml.OCamlChar.compare
                  ((MonadVM.String.get
                    (_rocq_fallback_finalize_current_block_0)) r_a 0)
                  ((MonadVM.String.get
                    (_rocq_fallback_finalize_current_block_0)) r_b 0))
            (RocqOfOCaml.OCamlList.filter
              (fun (req : MonadVM.Byte_string.Bytes.t) ⇒
                Z.gtb (MonadVM.Byte_string.Bytes.length req) 1)
              block_state.(MonadVM.State.BlockState.t.requests)))) in
    let gas_used := block_state.(MonadVM.State.BlockState.t.gas_used) in
    let blob_gas_used := MonadVM.Numeric.U64.zero in
    let header :=
      MonadVM.Chain.Ethereum.Block.Header.t.with_requests_hash requests_hash
        (MonadVM.Chain.Ethereum.Block.Header.t.with_blob_gas_used blob_gas_used
          (MonadVM.Chain.Ethereum.Block.Header.t.with_withdrawals_root
            withdrawals_root
            (MonadVM.Chain.Ethereum.Block.Header.t.with_gas_used gas_used
              (MonadVM.Chain.Ethereum.Block.Header.t.with_logs_bloom logs_bloom
                (MonadVM.Chain.Ethereum.Block.Header.t.with_receipts_root
                  receipts_root
                  (MonadVM.Chain.Ethereum.Block.Header.t.with_transactions_root
                    transactions_root
                    (MonadVM.Chain.Ethereum.Block.Header.t.with_state_root
                      state_root
                      (MonadVM.Chain.Ethereum.Block.Header.t.with_parent_hash
                        parent_hash
                        block_state.(MonadVM.State.BlockState.t.current_block).(MonadVM.Chain.Ethereum.Block.t.header)))))))))
      in
    MonadVM.Chain.Ethereum.Block.t.with_header header
      block_state.(MonadVM.State.BlockState.t.current_block).
End BlockState.

Module TransactionState.
  Module StorageKey.
    Module Impl.
      Definition t : Set := MonadVM.Chain.Ethereum.Address.t × string.

      Definition compare
        (function_parameter : MonadVM.Chain.Ethereum.Address.t × string)
        : MonadVM.Chain.Ethereum.Address.t × string → int :=
        let '(a1, w1) := function_parameter in
        fun (function_parameter : MonadVM.Chain.Ethereum.Address.t × string) ⇒
          let '(a2, w2) := function_parameter in
          let c1 := MonadVM.Chain.Ethereum.Address.compare a1 a2 in
          if Z.eqb c1 0 then
            MonadVM.Byte_string.B32.(MonadVM.Byte_string.Fixed.Fixed_result.compare)
              w1 w2
          else
            c1.

      Definition module
        :MonadVM.Map.OrderedType
          (t := MonadVM.Chain.Ethereum.Address.t × string) :=
        {|
          MonadVM.Map.OrderedType.compare := compare
        |}.
    End Impl.
    Definition Impl := Impl.module.

Inclusion of the module Impl
    Definition t := Impl.(MonadVM.Map.OrderedType.t).

    Definition compare := Impl.(MonadVM.Map.OrderedType.compare).

    Definition _Set := RocqOfOCaml.OCamlSet.Make Impl.
  End StorageKey.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
  Module t.
    Record record : Set := Build {
      initial_world_state : WorldState.t;
      world_state : WorldState.t;
      current_block : MonadVM.Chain.Ethereum.Block.t;
      transient_storage :
        MonadVM.Chain.Ethereum.Address.Map.t
          (MonadVM.Byte_string.B32.(MonadVM.Byte_string.Fixed.Fixed_result.Map).(MonadVM.Byte_string.Fixed.Map.Map_signature.t)
            string);
      accounts_created_in_current_transaction :
        MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.t);
      prior_transactions : list MonadVM.Chain.Ethereum.Transaction.t;
      tx_chain_id : MonadVM.Support.UintN.t;
      tx_origin : MonadVM.Chain.Ethereum.Address.t;
      tx_gas_price : MonadVM.Gas.t;
      tx_gas_limit : MonadVM.Gas.t;
      self_destruct :
        MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.t);
      logs : list MonadVM.Chain.Ethereum.Log.t;
      refund : MonadVM.Numeric.U256.t;
      accessed_addresses :
        MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.t);
      accessed_keys : StorageKey._Set.(RocqOfOCaml.OCamlSet.S.t);
    }.
    Definition with_initial_world_state initial_world_state (r : record) :=
      Build initial_world_state r.(world_state) r.(current_block)
        r.(transient_storage) r.(accounts_created_in_current_transaction)
        r.(prior_transactions) r.(tx_chain_id) r.(tx_origin) r.(tx_gas_price)
        r.(tx_gas_limit) r.(self_destruct) r.(logs) r.(refund)
        r.(accessed_addresses) r.(accessed_keys).
    Definition with_world_state world_state (r : record) :=
      Build r.(initial_world_state) world_state r.(current_block)
        r.(transient_storage) r.(accounts_created_in_current_transaction)
        r.(prior_transactions) r.(tx_chain_id) r.(tx_origin) r.(tx_gas_price)
        r.(tx_gas_limit) r.(self_destruct) r.(logs) r.(refund)
        r.(accessed_addresses) r.(accessed_keys).
    Definition with_current_block current_block (r : record) :=
      Build r.(initial_world_state) r.(world_state) current_block
        r.(transient_storage) r.(accounts_created_in_current_transaction)
        r.(prior_transactions) r.(tx_chain_id) r.(tx_origin) r.(tx_gas_price)
        r.(tx_gas_limit) r.(self_destruct) r.(logs) r.(refund)
        r.(accessed_addresses) r.(accessed_keys).
    Definition with_transient_storage transient_storage (r : record) :=
      Build r.(initial_world_state) r.(world_state) r.(current_block)
        transient_storage r.(accounts_created_in_current_transaction)
        r.(prior_transactions) r.(tx_chain_id) r.(tx_origin) r.(tx_gas_price)
        r.(tx_gas_limit) r.(self_destruct) r.(logs) r.(refund)
        r.(accessed_addresses) r.(accessed_keys).
    Definition with_accounts_created_in_current_transaction
      accounts_created_in_current_transaction (r : record) :=
      Build r.(initial_world_state) r.(world_state) r.(current_block)
        r.(transient_storage) accounts_created_in_current_transaction
        r.(prior_transactions) r.(tx_chain_id) r.(tx_origin) r.(tx_gas_price)
        r.(tx_gas_limit) r.(self_destruct) r.(logs) r.(refund)
        r.(accessed_addresses) r.(accessed_keys).
    Definition with_prior_transactions prior_transactions (r : record) :=
      Build r.(initial_world_state) r.(world_state) r.(current_block)
        r.(transient_storage) r.(accounts_created_in_current_transaction)
        prior_transactions r.(tx_chain_id) r.(tx_origin) r.(tx_gas_price)
        r.(tx_gas_limit) r.(self_destruct) r.(logs) r.(refund)
        r.(accessed_addresses) r.(accessed_keys).
    Definition with_tx_chain_id tx_chain_id (r : record) :=
      Build r.(initial_world_state) r.(world_state) r.(current_block)
        r.(transient_storage) r.(accounts_created_in_current_transaction)
        r.(prior_transactions) tx_chain_id r.(tx_origin) r.(tx_gas_price)
        r.(tx_gas_limit) r.(self_destruct) r.(logs) r.(refund)
        r.(accessed_addresses) r.(accessed_keys).
    Definition with_tx_origin tx_origin (r : record) :=
      Build r.(initial_world_state) r.(world_state) r.(current_block)
        r.(transient_storage) r.(accounts_created_in_current_transaction)
        r.(prior_transactions) r.(tx_chain_id) tx_origin r.(tx_gas_price)
        r.(tx_gas_limit) r.(self_destruct) r.(logs) r.(refund)
        r.(accessed_addresses) r.(accessed_keys).
    Definition with_tx_gas_price tx_gas_price (r : record) :=
      Build r.(initial_world_state) r.(world_state) r.(current_block)
        r.(transient_storage) r.(accounts_created_in_current_transaction)
        r.(prior_transactions) r.(tx_chain_id) r.(tx_origin) tx_gas_price
        r.(tx_gas_limit) r.(self_destruct) r.(logs) r.(refund)
        r.(accessed_addresses) r.(accessed_keys).
    Definition with_tx_gas_limit tx_gas_limit (r : record) :=
      Build r.(initial_world_state) r.(world_state) r.(current_block)
        r.(transient_storage) r.(accounts_created_in_current_transaction)
        r.(prior_transactions) r.(tx_chain_id) r.(tx_origin) r.(tx_gas_price)
        tx_gas_limit r.(self_destruct) r.(logs) r.(refund)
        r.(accessed_addresses) r.(accessed_keys).
    Definition with_self_destruct self_destruct (r : record) :=
      Build r.(initial_world_state) r.(world_state) r.(current_block)
        r.(transient_storage) r.(accounts_created_in_current_transaction)
        r.(prior_transactions) r.(tx_chain_id) r.(tx_origin) r.(tx_gas_price)
        r.(tx_gas_limit) self_destruct r.(logs) r.(refund)
        r.(accessed_addresses) r.(accessed_keys).
    Definition with_logs logs (r : record) :=
      Build r.(initial_world_state) r.(world_state) r.(current_block)
        r.(transient_storage) r.(accounts_created_in_current_transaction)
        r.(prior_transactions) r.(tx_chain_id) r.(tx_origin) r.(tx_gas_price)
        r.(tx_gas_limit) r.(self_destruct) logs r.(refund)
        r.(accessed_addresses) r.(accessed_keys).
    Definition with_refund refund (r : record) :=
      Build r.(initial_world_state) r.(world_state) r.(current_block)
        r.(transient_storage) r.(accounts_created_in_current_transaction)
        r.(prior_transactions) r.(tx_chain_id) r.(tx_origin) r.(tx_gas_price)
        r.(tx_gas_limit) r.(self_destruct) r.(logs) refund
        r.(accessed_addresses) r.(accessed_keys).
    Definition with_accessed_addresses accessed_addresses (r : record) :=
      Build r.(initial_world_state) r.(world_state) r.(current_block)
        r.(transient_storage) r.(accounts_created_in_current_transaction)
        r.(prior_transactions) r.(tx_chain_id) r.(tx_origin) r.(tx_gas_price)
        r.(tx_gas_limit) r.(self_destruct) r.(logs) r.(refund)
        accessed_addresses r.(accessed_keys).
    Definition with_accessed_keys accessed_keys (r : record) :=
      Build r.(initial_world_state) r.(world_state) r.(current_block)
        r.(transient_storage) r.(accounts_created_in_current_transaction)
        r.(prior_transactions) r.(tx_chain_id) r.(tx_origin) r.(tx_gas_price)
        r.(tx_gas_limit) r.(self_destruct) r.(logs) r.(refund)
        r.(accessed_addresses) accessed_keys.
  End t.
  Definition t := t.record.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
  Module TLens.
State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
    Definition initial_world_state : Lens.t t WorldState.t :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.TransactionState.t.initial_world_state);
        Lens.t.set :=
          fun (v_value : WorldState.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.TransactionState.t.with_initial_world_state v_value
                r_value; |}.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
    Definition world_state : Lens.t t WorldState.t :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.TransactionState.t.world_state);
        Lens.t.set :=
          fun (v_value : WorldState.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.TransactionState.t.with_world_state v_value r_value;
        |}.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
    Definition current_block : Lens.t t MonadVM.Chain.Ethereum.Block.t :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.TransactionState.t.current_block);
        Lens.t.set :=
          fun (v_value : MonadVM.Chain.Ethereum.Block.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.TransactionState.t.with_current_block v_value
                r_value; |}.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
    Definition transient_storage
      : Lens.t t
        (MonadVM.Chain.Ethereum.Address.Map.t
          (MonadVM.Byte_string.B32.(MonadVM.Byte_string.Fixed.Fixed_result.Map).(MonadVM.Byte_string.Fixed.Map.Map_signature.t)
            string)) :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.TransactionState.t.transient_storage);
        Lens.t.set :=
          fun (v_value :
            MonadVM.Chain.Ethereum.Address.Map.t
              (MonadVM.Byte_string.B32.(MonadVM.Byte_string.Fixed.Fixed_result.Map).(MonadVM.Byte_string.Fixed.Map.Map_signature.t)
                string)) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.TransactionState.t.with_transient_storage v_value
                r_value; |}.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
    Definition accounts_created_in_current_transaction
      : Lens.t t MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.t) :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.TransactionState.t.accounts_created_in_current_transaction);
        Lens.t.set :=
          fun (v_value :
            MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.t)) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.TransactionState.t.with_accounts_created_in_current_transaction
                v_value r_value; |}.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
    Definition prior_transactions
      : Lens.t t (list MonadVM.Chain.Ethereum.Transaction.t) :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.TransactionState.t.prior_transactions);
        Lens.t.set :=
          fun (v_value : list MonadVM.Chain.Ethereum.Transaction.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.TransactionState.t.with_prior_transactions v_value
                r_value; |}.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
    Definition tx_chain_id : Lens.t t MonadVM.Support.UintN.t :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.TransactionState.t.tx_chain_id);
        Lens.t.set :=
          fun (v_value : MonadVM.Support.UintN.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.TransactionState.t.with_tx_chain_id v_value r_value;
        |}.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
    Definition tx_origin : Lens.t t MonadVM.Chain.Ethereum.Address.t :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.TransactionState.t.tx_origin);
        Lens.t.set :=
          fun (v_value : MonadVM.Chain.Ethereum.Address.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.TransactionState.t.with_tx_origin v_value r_value;
        |}.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
    Definition tx_gas_price : Lens.t t MonadVM.Gas.t :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.TransactionState.t.tx_gas_price);
        Lens.t.set :=
          fun (v_value : MonadVM.Gas.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.TransactionState.t.with_tx_gas_price v_value r_value;
        |}.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
    Definition tx_gas_limit : Lens.t t MonadVM.Gas.t :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.TransactionState.t.tx_gas_limit);
        Lens.t.set :=
          fun (v_value : MonadVM.Gas.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.TransactionState.t.with_tx_gas_limit v_value r_value;
        |}.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
    Definition self_destruct
      : Lens.t t MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.t) :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.TransactionState.t.self_destruct);
        Lens.t.set :=
          fun (v_value :
            MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.t)) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.TransactionState.t.with_self_destruct v_value
                r_value; |}.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
    Definition logs : Lens.t t (list MonadVM.Chain.Ethereum.Log.t) :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒ r_value.(MonadVM.State.TransactionState.t.logs);
        Lens.t.set :=
          fun (v_value : list MonadVM.Chain.Ethereum.Log.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.TransactionState.t.with_logs v_value r_value; |}.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
    Definition refund : Lens.t t MonadVM.Numeric.U256.t :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒ r_value.(MonadVM.State.TransactionState.t.refund);
        Lens.t.set :=
          fun (v_value : MonadVM.Numeric.U256.t) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.TransactionState.t.with_refund v_value r_value; |}.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
    Definition accessed_addresses
      : Lens.t t MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.t) :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.TransactionState.t.accessed_addresses);
        Lens.t.set :=
          fun (v_value :
            MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.t)) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.TransactionState.t.with_accessed_addresses v_value
                r_value; |}.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).
    Definition accessed_keys
      : Lens.t t StorageKey._Set.(RocqOfOCaml.OCamlSet.S.t) :=
      {|
        Lens.t.get :=
          fun (r_value : t) ⇒
            r_value.(MonadVM.State.TransactionState.t.accessed_keys);
        Lens.t.set :=
          fun (v_value : StorageKey._Set.(RocqOfOCaml.OCamlSet.S.t)) ⇒
            fun (r_value : t) ⇒
              MonadVM.State.TransactionState.t.with_accessed_keys v_value
                r_value; |}.
  End TLens.

State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)). State within a single transaction. Tracks the initial world state, any changes to its storage, and variables that are internal to the transaction such as the accrued substate (YP (62)).


  Definition initial_world_state := TLens.initial_world_state.

  Definition world_state := TLens.world_state.

  Definition current_block := TLens.current_block.

  Definition transient_storage := TLens.transient_storage.

  Definition accounts_created_in_current_transaction :=
    TLens.accounts_created_in_current_transaction.

  Definition prior_transactions := TLens.prior_transactions.

  Definition tx_chain_id := TLens.tx_chain_id.

  Definition tx_origin := TLens.tx_origin.

  Definition tx_gas_price := TLens.tx_gas_price.

  Definition tx_gas_limit := TLens.tx_gas_limit.

  Definition self_destruct := TLens.self_destruct.

  Definition logs := TLens.logs.

  Definition refund := TLens.refund.

  Definition accessed_addresses := TLens.accessed_addresses.

  Definition accessed_keys := TLens.accessed_keys.

  Definition empty : t :=
    let world_state := WorldState.empty in
    let current_block :=
      {|
        MonadVM.Chain.Ethereum.Block.t.header :=
          MonadVM.Chain.Ethereum.Block.Header.empty;
        MonadVM.Chain.Ethereum.Block.t.transactions := nil;
        MonadVM.Chain.Ethereum.Block.t.ommers := nil;
        MonadVM.Chain.Ethereum.Block.t.withdrawals := nil; |} in
    {| MonadVM.State.TransactionState.t.initial_world_state := world_state;
      MonadVM.State.TransactionState.t.world_state := world_state;
      MonadVM.State.TransactionState.t.current_block := current_block;
      MonadVM.State.TransactionState.t.transient_storage :=
        MonadVM.Chain.Ethereum.Address.Map.empty;
      MonadVM.State.TransactionState.t.accounts_created_in_current_transaction
        := MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.empty);
      MonadVM.State.TransactionState.t.prior_transactions := nil;
      MonadVM.State.TransactionState.t.tx_chain_id :=
        MonadVM.Support.UintN.zero;
      MonadVM.State.TransactionState.t.tx_origin :=
        MonadVM.Chain.Ethereum.Address.zero;
      MonadVM.State.TransactionState.t.tx_gas_price := MonadVM.Gas.zero;
      MonadVM.State.TransactionState.t.tx_gas_limit := MonadVM.Gas.zero;
      MonadVM.State.TransactionState.t.self_destruct :=
        MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.empty);
      MonadVM.State.TransactionState.t.logs := nil;
      MonadVM.State.TransactionState.t.refund := MonadVM.Numeric.U256.zero;
      MonadVM.State.TransactionState.t.accessed_addresses :=
        MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.empty);
      MonadVM.State.TransactionState.t.accessed_keys :=
        StorageKey._Set.(RocqOfOCaml.OCamlSet.S.empty); |}.

  Definition _rocq_fallback_make_0 : ltac:(let typ := constr:(ltac:(first [unshelve refine ((MonadVM.Support.UintN.Impl.t)%type )]; first [match goal with |- ?g ⇒ let sort := type of g in lazymatch sort with Set ⇒ fail | _ ⇒ shelve end end | eassumption | typeclasses eauto | RocqOfOCaml.Opaque.opaque_inhabit 64%nat])) in let typ := _rocq_witness_type typ in exact typ).
  Proof. unshelve (RocqOfOCaml.Opaque.opaque_inhabit 64%nat). all: RocqOfOCaml.Opaque.opaque_inhabit 64%nat. Qed.

  Definition make
    (block_state : BlockState.t) (sender : MonadVM.Chain.Ethereum.Address.t)
    (tx : MonadVM.Chain.Ethereum.Transaction.t) : t :=
    let tx_gas_price :=
      (MonadVM.Option.get (_rocq_fallback_make_0))
        (MonadVM.Gas.tx_effective_gas_price
          block_state.(MonadVM.State.BlockState.t.current_block).(MonadVM.Chain.Ethereum.Block.t.header).(MonadVM.Chain.Ethereum.Block.Header.t.base_fee_per_gas)
          tx) in
    MonadVM.State.TransactionState.t.with_tx_gas_limit
      (MonadVM.Chain.Ethereum.Transaction.gas_limit tx)
      (MonadVM.State.TransactionState.t.with_tx_gas_price tx_gas_price
        (MonadVM.State.TransactionState.t.with_tx_origin sender
          (MonadVM.State.TransactionState.t.with_prior_transactions
            (RocqOfOCaml.OCamlList.map fst
              block_state.(MonadVM.State.BlockState.t.transactions_processed))
            (MonadVM.State.TransactionState.t.with_accounts_created_in_current_transaction
              MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.empty)
              (MonadVM.State.TransactionState.t.with_transient_storage
                MonadVM.Chain.Ethereum.Address.Map.empty
                (MonadVM.State.TransactionState.t.with_current_block
                  block_state.(MonadVM.State.BlockState.t.current_block)
                  (MonadVM.State.TransactionState.t.with_world_state
                    block_state.(MonadVM.State.BlockState.t.world_state)
                    (MonadVM.State.TransactionState.t.with_initial_world_state
                      block_state.(MonadVM.State.BlockState.t.world_state) empty)))))))).

  Definition account (keep_empty_optional : option bool)
    : MonadVM.Chain.Ethereum.Address.Map.key →
    Lens.t t MonadVM.Chain.Ethereum.Account.t :=
    match keep_empty_optional with
    | Some keep_empty ⇒
      fun (addr : MonadVM.Chain.Ethereum.Address.Map.key) ⇒
        Lens.Infix.op_pipeminusminus world_state
          (WorldState.account (Some keep_empty) addr)
    | None ⇒
      let 'keep_empty := false in
      fun (addr : MonadVM.Chain.Ethereum.Address.Map.key) ⇒
        Lens.Infix.op_pipeminusminus world_state
          (WorldState.account (Some keep_empty) addr)
    end.

initialize_access_sets tx state p_addr extends the set of accessed addresses and keys of state with the transaction sender and recipient (if any), the addresses and keys in the transaction's access list, the delegation target of the recipient (if any), the block's beneficiary and the given list of precompiled contract addresses. The state's accessed addresses are not overwritten but extended, so any addresses that were accessed before this call will remain accessed.
  Definition initialize_access_sets
    (tx : MonadVM.Chain.Ethereum.Transaction.t) (transaction_state : t)
    (precompile_addresses :
      MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.t)) : t :=
    let sender := transaction_state.(MonadVM.State.TransactionState.t.tx_origin)
      in
    let access_list := MonadVM.Chain.Ethereum.Transaction.access_list tx in
    let accessed_keys :=
      StorageKey._Set.(RocqOfOCaml.OCamlSet.S.of_seq)
        (RocqOfOCaml.OCamlSeq.flat_map
          (fun (acc : MonadVM.Chain.Ethereum.Transaction.Access.t) ⇒
            RocqOfOCaml.OCamlSeq.map
              (fun (k_value : string) ⇒
                (acc.(MonadVM.Chain.Ethereum.Transaction.Access.t.address),
                  k_value))
              (RocqOfOCaml.OCamlList.to_seq
                acc.(MonadVM.Chain.Ethereum.Transaction.Access.t.storage_keys)))
          (RocqOfOCaml.OCamlList.to_seq access_list)) in
    let access_list_addresses :=
      MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.of_seq)
        (RocqOfOCaml.OCamlSeq.map
          (fun (acc : MonadVM.Chain.Ethereum.Transaction.Access.t) ⇒
            acc.(MonadVM.Chain.Ethereum.Transaction.Access.t.address))
          (RocqOfOCaml.OCamlList.to_seq access_list)) in
    let target_addresses :=
      match MonadVM.Chain.Ethereum.Transaction.call_or_create_value tx with
      | MonadVM.Chain.Ethereum.Transaction.Create _ ⇒
        MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.empty)
      |
        MonadVM.Chain.Ethereum.Transaction.Call {|
          MonadVM.Chain.Ethereum.Transaction.call_or_create.Call.to_ := to_
            |} ⇒
        match
          MonadVM.Delegation.get_delegated_address
            (op_pointcaretlparenrparen transaction_state (account None to_)).(MonadVM.Chain.Ethereum.Account.t.code)
          with
        | None ⇒
          MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.singleton)
            to_
        | Some delegated ⇒
          MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.of_list)
            (Datatypes.cons to_ (Datatypes.cons delegated nil))
        end
      end in
    let accessed_addresses :=
      RocqOfOCaml.OCamlList.fold_left
        MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.union)
        MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.empty)
        (Datatypes.cons access_list_addresses
          (Datatypes.cons precompile_addresses
            (Datatypes.cons
              (MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.singleton)
                sender)
              (Datatypes.cons
                (MonadVM.Chain.Ethereum.Address._Set.(RocqOfOCaml.OCamlSet.S.singleton)
                  transaction_state.(MonadVM.State.TransactionState.t.current_block).(MonadVM.Chain.Ethereum.Block.t.header).(MonadVM.Chain.Ethereum.Block.Header.t.beneficiary))
                (Datatypes.cons target_addresses
                  (Datatypes.cons
                    transaction_state.(MonadVM.State.TransactionState.t.accessed_addresses)
                    nil)))))) in
    MonadVM.State.TransactionState.t.with_accessed_keys accessed_keys
      (MonadVM.State.TransactionState.t.with_accessed_addresses
        accessed_addresses transaction_state).

  Definition M_fargs :=
    MonadVM.Monad.State.Build_FArgs
      (let t : Set := t in
      ((ltac:(constructor) : MonadVM.Monad.State_T_signature (t := t)) :
        MonadVM.Monad.State_T_signature (t := t))).

  Definition M : MonadVM.Monad.State.State_result (_fargs := M_fargs) :=
    (MonadVM.Monad.State.functor (_fargs := (M_fargs ))).
End TransactionState.