Library MonadVM.Setcode_rules

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

Require MonadVM.Byte_string.
Require MonadVM.Chain.Ethereum.
Require MonadVM.Chain.Monad.
Require MonadVM.Numeric.
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.
MIP-19 rules shared by concrete execution and its regression proofs. The five gas prices are explicit experimental configuration, not prices specified by MIP-19. No network timestamp selects this configuration.

Definition enabled (revision : MonadVM.Chain.Monad.Revision.active) : bool :=
  match revision with
  | MonadVM.Support.Variants.Revision.Setcode _ ⇒ true
  | _ ⇒ false
  end.

Definition system_account (addr : MonadVM.Chain.Ethereum.Address.t) : bool :=
  orb
    (MonadVM.Chain.Ethereum.Address.op_eq addr
      (MonadVM.Chain.Ethereum.Address.of_hex_string None
        "000F3df6D732807Ef1319fB7B8bB8522d0Beac02"))
    (MonadVM.Chain.Ethereum.Address.op_eq addr
      (MonadVM.Chain.Ethereum.Address.of_hex_string None
        "0000f90827f1c53a10cb7a02335b175320002935")).

Definition _rocq_fallback_regular_source_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 regular_source (code : MonadVM.Byte_string.Bytes.t) : bool :=
  andb (Z.gtb (MonadVM.Byte_string.Bytes.length code) 0)
    (negb
      (RocqOfOCaml.OCamlChar.equal
        ((MonadVM.String.get (_rocq_fallback_regular_source_0)) code 0)
        "239" % char)).

A fresh consensus decision never admits an ordinary-code sender. Execution's included-failure exception must not be used here.
A migrated sender does not require nonce equality. Both operands must remain below the maximum before incrementing; no wraparound is allowed.
Definition advance_sender_nonce
  (migrated : bool) (actual : MonadVM.Numeric.U64.t)
  (proposed : MonadVM.Numeric.U64.t) : MonadVM.Numeric.U64.t :=
  MonadVM.Numeric.U64.op_plus
    (if migrated then
      MonadVM.Numeric.U64.max actual proposed
    else
      actual) MonadVM.Numeric.U64.one.

Definition next_sender_nonce
  (migrated : bool) (actual : MonadVM.Numeric.U64.t)
  (proposed : MonadVM.Numeric.U64.t) : option MonadVM.Numeric.U64.t :=
  if
    orb (MonadVM.Numeric.U64.op_eq actual MonadVM.Numeric.U64.max_t)
      (MonadVM.Numeric.U64.op_eq proposed MonadVM.Numeric.U64.max_t)
  then
    None
  else
    if orb migrated (MonadVM.Numeric.U64.op_eq actual proposed) then
      Some (advance_sender_nonce migrated actual proposed)
    else
      None.

Definition contract_exempt
  (regular : bool) (sender : bool) (sent_in_window : bool) : bool :=
  andb regular (andb (negb sender) (negb sent_in_window)).

Definition adoption_allowed
  (delegated : bool) (sender : bool) (reserve : MonadVM.Numeric.U256.t)
  : bool :=
  orb (negb delegated)
    (orb sender (MonadVM.Numeric.U256.op_eq reserve MonadVM.Numeric.U256.zero)).