Library MonadVM.Delegation

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

Require Import MonadVM.Support.UintN.
Require MonadVM.Byte_string.
Require MonadVM.Numeric.

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.
Module Address := MonadVM.Byte_string.B20.

Definition eoa_delegation_prefix : MonadVM.Byte_string.Bytes.t :=
  String.String "239" (String.String "001" (String.String "000" "")).

Definition eoa_delegated_code_length : int :=
  RocqOfOCaml.OCamlInt.add
    (MonadVM.Byte_string.Bytes.length eoa_delegation_prefix) Address.byte_width.

Init function; without side-effects in Rocq
Definition _rocq_fallback_init_module_0 :
  ltac:(let typ := constr:(ltac:(first [unshelve refine ((unit)%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 init_module : unit :=
  if Z.eqb eoa_delegated_code_length 23 then tt else
    _rocq_fallback_init_module_0.

Definition magic : string := String.String "005" "".

Definition per_empty_account_cost : MonadVM.Support.UintN.t :=
  MonadVM.Support.UintN.op_tildedollar 25000.

Definition per_auth_base_cost : MonadVM.Support.UintN.t :=
  MonadVM.Support.UintN.op_tildedollar 12500.

is_valid_delegation code checks whether code starts with the delegation indicator (0xef0100) and is exactly 23 bytes (corresponding to the delegation indicator plus a 20-byte address)
delegation_code addr returns the delegation code for addr (the address prefixed by the delegation indicator), or the empty byte string if the address is zero.
If code is a valid delegation, get_delegated_address code returns the address where the delegated code is hosted, otherwise it returns None.
Definition _rocq_fallback_get_delegated_address_0 (code :
  MonadVM.Byte_string.Bytes.t) :
  ltac:(let typ := constr:(ltac:(first [unshelve refine ((MonadVM.Byte_string.Bytes.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 get_delegated_address (code : MonadVM.Byte_string.Bytes.t)
  : option Address.t :=
  if is_valid_delegation code then
    Some
      (Address.of_bytes_exn
        ((MonadVM.Byte_string.Bytes.sub
          ((_rocq_fallback_get_delegated_address_0 code))) code
          (MonadVM.Byte_string.Bytes.length eoa_delegation_prefix)
          Address.byte_width))
  else
    None.