Library monadpure.evmmisc

Account and transaction vocabulary retained from Monad's pure EVM support. The records are unchanged, including fields preserved by account updates. Unused numeric lenses and C++ proof infrastructure have been omitted.
Require Import monadpure.misc.
Require Import elpi.apps.derive.derive.
Require Import Lens.Lens Lens.Elpi.Elpi.
Require Import EVMOpSem.block.

Set Default Goal Selector "!".

Definition w256 := N.
Definition EvmAddr := N.

Definition tsender (t : block.transaction) : EvmAddr :=
  Z.to_N (word160.word160ToInteger (block.tr_from t)).

Record Indices := {
  block_index : N;
  tx_index : N;
}.

Record AccountM := {
  coreAc : block.block_account;
  incarnation : Indices;
  relevantKeys : list N;
  balance : N;
}.

Axiom keccak256_program : evm.program → N.
Definition code_hash_of_program (pr : evm.program) : N := keccak256_program pr.
Definition delegation_indicator_size : Z := 23%Z.
Definition delegation_marker_prefix (p : evm.program) : bool :=
  Z.eqb (word8.word8ToUInt (evm.program_as_natural_map p 0)) 239 &&
  Z.eqb (word8.word8ToUInt (evm.program_as_natural_map p 1)) 1 &&
  Z.eqb (word8.word8ToUInt (evm.program_as_natural_map p 2)) 0.

Definition isDelegationMarker (p : evm.program) : bool :=
  Z.eqb (evm.program_length p) delegation_indicator_size &&
  delegation_marker_prefix p.

Definition delegatedTo (a : AccountM) : option EvmAddr :=
  if isDelegationMarker (block.block_account_code (coreAc a))
  then Some 0%N
  else None.

Record TxResult := {
  gas_used : N;
  gas_refund : N;
  logs : list evm.log_entry;
}.

Record BlockHeader := {
  base_fee_per_gas : option w256;
  number : N;
  beneficiary : EvmAddr;
  timestamp : N;
}.

#[only(lens)] derive AccountM.

Definition w256_to_Z (w : keccak.w256) : Z := Zdigits.binary_value 256 w.
Definition w256_to_N (w : keccak.w256) : N := Z.to_N (w256_to_Z w).

Opaque Zdigits.binary_value Zdigits.Z_to_binary.