evm v0.1.14 EVM.MachineState
Module for tracking the current machine state, which is roughly equivilant to the VM state for an executing contract.
This is most often seen as µ in the Yellow Paper.
Link to this section Summary
Functions
After a memory operation, we may have incremented the total number of active words. This function takes a memory offset accessed and updates the machine state accordingly
Increments the program counter
Pops n values off the stack
Push a values onto the stack
Returns a new execution environment less the amount of gas specified
Link to this section Types
t() :: %EVM.MachineState{active_words: integer, gas: EVM.Gas.t, memory: memory, previously_active_words: term, program_counter: program_counter, stack: EVM.Stack.t}
Link to this section Functions
After a memory operation, we may have incremented the total number of active words. This function takes a memory offset accessed and updates the machine state accordingly.
Examples
iex> %EVM.MachineState{active_words: 2} |> EVM.MachineState.maybe_set_active_words(1)
%EVM.MachineState{active_words: 2}
iex> %EVM.MachineState{active_words: 2} |> EVM.MachineState.maybe_set_active_words(3)
%EVM.MachineState{active_words: 3}
iex> %EVM.MachineState{active_words: 2} |> EVM.MachineState.maybe_set_active_words(1)
%EVM.MachineState{active_words: 2}
move_program_counter(EVM.MachineState.t, EVM.Operation.Metadata.t, [EVM.val]) :: EVM.MachineState.t
Increments the program counter
Examples
iex> EVM.MachineState.move_program_counter(%EVM.MachineState{program_counter: 9}, EVM.Operation.metadata(:add), [1, 1])
%EVM.MachineState{program_counter: 10}
pop_n(EVM.MachineState.t, integer) :: {EVM.MachineState.t, [EVM.val]}
Pops n values off the stack
Examples
iex> EVM.MachineState.pop_n(%EVM.MachineState{stack: [1, 2, 3]}, 2)
{[1 ,2], %EVM.MachineState{stack: [3]}}
push(EVM.MachineState.t, EVM.val) :: EVM.MachineState.t
Push a values onto the stack
Examples
iex> EVM.MachineState.push(%EVM.MachineState{stack: [2, 3]}, 1)
%EVM.MachineState{stack: [1, 2, 3]}
subtract_gas(EVM.MachineState.t, ExecEnv.t) :: EVM.MachineState.t
Returns a new execution environment less the amount of gas specified.
Examples
iex> machine_state = %EVM.MachineState{gas: 10, stack: [1, 1], program_counter: 0}
iex> exec_env = %EVM.ExecEnv{machine_code: <<EVM.Operation.metadata(:add).id>>}
iex> EVM.MachineState.subtract_gas(machine_state, exec_env)
%EVM.MachineState{gas: 7, stack: [1, 1]}