View Source Signet.VM (Signet v1.3.8)

An Ethereum VM in Signet, that can only execute pure functions.

Summary

Types

@type address() :: <<_::160>>
@type code() :: [opcode()]
@type context_result() :: {:ok, Context.t()} | {:error, vm_error()}
@type exec_opts() :: [callvalue: integer(), ffis: ffis()]
@type ffis() :: %{required(address()) => code()}
@type opcode() :: Signet.Assembly.opcode()
@type signed() :: integer()
@type unsigned() :: non_neg_integer()
@type vm_error() ::
  :pc_out_of_bounds
  | :value_overflow
  | :stack_underflow
  | :signed_integer_out_of_bounds
  | :out_of_memory
  | :invalid_operation
  | {:unknown_ffi, address()}
  | {:invalid_push, integer(), binary()}
  | {:impure, opcode()}
  | {:not_implemented, opcode()}
@type word() :: <<_::256>>

Functions

Link to this function

cap_to_range(x, min, max)

View Source
@spec cap_to_range(integer(), integer(), integer()) :: integer()
Link to this function

exec(code, calldata, opts \\ [])

View Source
@spec exec(code() | binary(), binary(), exec_opts()) ::
  {:ok, Signet.VM.ExecutionResult.t()} | {:error, vm_error()}

Executes the Ethereum Virtual Machine (EVM) with the given code and input.

Parameters

  • code: The bytecode to be executed, either as a binary or decoded.
  • calldata: The call data for the execution.
  • opts: Execution options (see below)

Options

  • :callvalue: value passed as callvalue for the execution.
  • :ffis: A mapping of address to functions to run as natively implemented ffis

Returns the result of the execution.

Link to this function

exec_call(code, calldata, opts \\ [])

View Source
@spec exec_call(code() | binary(), binary(), exec_opts()) ::
  {:ok, binary()} | {:revert, binary()}

Runs the given EVM, returning the RETURN data or the REVERT data.

Raises on any other exceptional state.

Parameters

  • code: The bytecode to be executed, either as a binary or decoded.
  • calldata: The call data for the execution.
  • opts: Execution options (see below)

Options

  • :callvalue: value passed as callvalue for the execution.
  • :ffis: A mapping of address to functions to run as natively implemented ffis
Link to this function

inc_pc(context_result, operation)

View Source
@spec inc_pc(context_result(), opcode()) :: context_result()
@spec pad_to_word(binary()) :: {:ok, <<_::256>>} | {:error, vm_error()}
@spec peek(Signet.VM.Context.t(), integer()) :: {:ok, word()} | {:error, vm_error()}
@spec pop2(Signet.VM.Context.t()) ::
  {:ok, Signet.VM.Context.t(), word(), word()} | {:error, vm_error()}
@spec pop2_unsigned(Signet.VM.Context.t()) ::
  {:ok, Signet.VM.Context.t(), unsigned(), unsigned()} | {:error, vm_error()}
Link to this function

pop2_unsigned_word(context)

View Source
@spec pop2_unsigned_word(Signet.VM.Context.t()) ::
  {:ok, Signet.VM.Context.t(), unsigned(), word()} | {:error, vm_error()}
@spec pop3(Signet.VM.Context.t()) ::
  {:ok, Signet.VM.Context.t(), word(), word(), word()} | {:error, vm_error()}
@spec pop3_unsigned(Signet.VM.Context.t()) ::
  {:ok, Signet.VM.Context.t(), unsigned(), unsigned(), unsigned()}
  | {:error, vm_error()}
@spec pop(Signet.VM.Context.t()) ::
  {:ok, Signet.VM.Context.t(), word()} | {:error, vm_error()}
@spec pop_unsigned(Signet.VM.Context.t()) ::
  {:ok, Signet.VM.Context.t(), unsigned()} | {:error, vm_error()}
@spec push_word(Signet.VM.Context.t(), word()) ::
  {:ok, Signet.VM.Context.t()} | {:error, vm_error()}
Link to this function

run_single_op(context, input, opts)

View Source
@spec sint_to_word(signed()) :: {:ok, binary()} | {:error, atom()}
@spec uint_to_word(unsigned()) :: {:ok, binary()} | {:error, vm_error()}
@spec word_to_sint(binary()) :: {:ok, signed()} | {:error, vm_error()}
@spec word_to_uint(binary()) :: {:ok, unsigned()} | {:error, vm_error()}