pyevmasm
pyevmasm copied to clipboard
Add instruction offsets to simplify source mapping
Summary
Instructions can be addressed using either the program counter or instruction offsets. The source maps generated by the Solidity compiler use instruction offsets. This PR makes the offset an optional property of a disassembled instruction to simplify working with source maps.
Quoting from the linked docs:
The encoding in the source mapping for the bytecode is more complicated: It is a list of
s:l:f:j:m
separated by;
. Each of these elements corresponds to an instruction, i.e., you cannot use the byte offset but have to use the instruction offset (push instructions are longer than a single byte)
Background
We're developing a Solidity debugger that uses Pyevmasm as a disassembler. We heavily use source maps, and by adding support for instruction offsets directly to Pyevmasm, we can safely switch between the two addressing schemes. Other developer tools might also profit from this change.