Skip to content

evmdasm registry

tintin edited this page Oct 11, 2018 · 2 revisions

Library

accessing the instruction registry

  • registry.INSTRUCTIONS holds instruction templates. These are the initial set ob instructions available to the evm. Keep the templates static/unchanged.
  • To create a new instruction from a template either use instruction.clone() or registry.create_instruction(name=; or opcode=). Feel free to do anything you want with this new instance of an evm instruction.
  • To add new instructions just create an Instruction(...) object and put it into registry.INSTRUCTIONS
from evm_instruction import registry

# access via named dict
jmp = registry.instruction.JUMP

# access via dict
## accessing the template objects (avoid modifying them)

jmp = registry.INSTRUCTIONS_BY_OPCODE["JUMP"]  # get the template object from the instruction registry 
jmp = registry.INSTRUCTIONS_BY_NAME["JUMP"]  # get the template object from the instruction registry 

jmp = jmp.clone()  # clone a new instruction from the template object

## creating new instruction objects from the template 
jmp = registry.create_instruction(name="JUMP")  # create a new jump instruction object in order to keep (

# access via categories lookup
terminating_instructions = registry.INSTRUCTIONS_BY_CATEGORY["terminate"]

# access all instructions as a list (no guarantee this is sorted in the future)
list_of_all_instructions = registry.INSTRUCTIONS

# extract certain instructions
list_of_gas_heavy_instructions = [i for i in registry.INSTRUCTIONS if i.gas > 500]

Clone this wiki locally