evm v0.1.1 EVM.MachineCode
Functions for helping read a contract’s machine code.
Link to this section Summary
Functions
Builds machine code for a given set of instructions and data
Returns the current instruction being executed. In the
Yellow Paper, this is often referred to as w
, and is
defined in Eq.(125) and again in Eq.(221)
Returns true if the given new pc is a valid jump destination for the machine code, false otherwise
Returns the legal jump locations in the given machine code
Link to this section Types
Link to this section Functions
Builds machine code for a given set of instructions and data.
Examples
iex> EVM.MachineCode.compile([:push1, 3, :push1, 5, :add, :return])
<<0x60, 0x03, 0x60, 0x05, 0x01, 0xf3>>
iex> EVM.MachineCode.compile([])
<<>>
current_instruction(EVM.MachineState.t, EVM.ExecEnv.t) :: EVM.Instruction.opcode
Returns the current instruction being executed. In the
Yellow Paper, this is often referred to as w
, and is
defined in Eq.(125) and again in Eq.(221).
Examples
iex> EVM.MachineCode.current_instruction(%EVM.MachineState{pc: 0}, %EVM.ExecEnv{machine_code: <<0x15::8, 0x11::8, 0x12::8>>})
0x15
iex> EVM.MachineCode.current_instruction(%EVM.MachineState{pc: 1}, %EVM.ExecEnv{machine_code: <<0x15::8, 0x11::8, 0x12::8>>})
0x11
iex> EVM.MachineCode.current_instruction(%EVM.MachineState{pc: 2}, %EVM.ExecEnv{machine_code: <<0x15::8, 0x11::8, 0x12::8>>})
0x12
valid_jump_dest?(EVM.MachineState.pc, t) :: boolean
Returns true if the given new pc is a valid jump destination for the machine code, false otherwise.
TODO: Memoize
Examples
iex> EVM.MachineCode.valid_jump_dest?(0, EVM.MachineCode.compile([:push1, 3, :push1, 5, :jumpdest, :add, :return, :jumpdest, :stop]))
false
iex> EVM.MachineCode.valid_jump_dest?(4, EVM.MachineCode.compile([:push1, 3, :push1, 5, :jumpdest, :add, :return, :jumpdest, :stop]))
true
iex> EVM.MachineCode.valid_jump_dest?(6, EVM.MachineCode.compile([:push1, 3, :push1, 5, :jumpdest, :add, :return, :jumpdest, :stop]))
false
iex> EVM.MachineCode.valid_jump_dest?(7, EVM.MachineCode.compile([:push1, 3, :push1, 5, :jumpdest, :add, :return, :jumpdest, :stop]))
true
iex> EVM.MachineCode.valid_jump_dest?(100, EVM.MachineCode.compile([:push1, 3, :push1, 5, :jumpdest, :add, :return, :jumpdest, :stop]))
false
valid_jump_destinations(t) :: [EVM.MachineState.pc]
Returns the legal jump locations in the given machine code.
TODO: Memoize
Example
iex> EVM.MachineCode.valid_jump_destinations(EVM.MachineCode.compile([:push1, 3, :push1, 5, :jumpdest, :add, :return, :jumpdest, :stop]))
[4, 7]