Search documentation of Cartouche

# Cartouche.VM (Cartouche v0.1.2)

Copy Markdown View Source

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

## Summary

### Types

address()
code()
context_result()
exec_opts()
ffi()
ffis()
opcode()
signed()
unsigned()
vm_error()
word()

### Functions

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

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

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

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

## Types

# address()

    @type address() :: <<_::160>>

# code()

    @type code() :: [opcode()]

# context_result()

    @type context_result() :: {:ok, Cartouche.VM.Context.t()} | {:error, vm_error()}

# exec_opts()

    @type exec_opts() :: [callvalue: integer(), ffis: ffis()]

# ffi()

    @type ffi() :: (binary() -> {:return, binary()} | {:revert, binary()})

# ffis()

    @type ffis() :: %{required(address()) => ffi()}

# opcode()

    @type opcode() :: Cartouche.Assembly.opcode()

# signed()

    @type signed() :: integer()

# unsigned()

    @type unsigned() :: non_neg_integer()

# vm_error()

    @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()}

# word()

    @type word() :: <<_::256>>

## Functions

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

    @spec exec(code() | binary(), binary(), exec_opts()) ::
      {:ok, Cartouche.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.

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

    @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