evm v0.1.8 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
Link to this type
t()
t() :: %EVM.MachineState{active_words: integer, gas: EVM.Gas.t, memory: memory, pc: pc, previously_active_words: term, stack: EVM.Stack.t}
Link to this section Functions
Link to this function
maybe_set_active_words(machine_state, last_word)
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, previously_active_words: 1} |> EVM.MachineState.maybe_set_active_words(1)
%EVM.MachineState{active_words: 2, previously_active_words: 2}
iex> %EVM.MachineState{active_words: 2, previously_active_words: 1} |> EVM.MachineState.maybe_set_active_words(3)
%EVM.MachineState{active_words: 3, previously_active_words: 2}
iex> %EVM.MachineState{active_words: 2, previously_active_words: 1} |> EVM.MachineState.maybe_set_active_words(1)
%EVM.MachineState{active_words: 2, previously_active_words: 2}
Link to this function
next_pc(machine_state, operation)
next_pc(EVM.MachineState.t, atom) :: EVM.MachineState.t
Increments the program counter
Examples
iex> EVM.MachineState.next_pc(%EVM.MachineState{pc: 9}, :add)
%EVM.MachineState{pc: 10}
Link to this function
pop_n(machine_state, n)
pop_n(EVM.MachineState.t, pc) :: {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]}}
Link to this function
push(machine_state, value)
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]}