Copyright | 2018 Simon Shine |
---|---|
License | MIT |
Maintainer | Simon Shine <shreddedglory@gmail.com> |
Safe Haskell | None |
Language | Haskell2010 |
This module exposes the LabelledOpcode
type for expressing Ethereum VM
opcodes with labelled jumps. Plain Ethereum VM Opcodes are not so ergonomic
because one has to know the exact byte offset of the target JUMPDEST
.
With Opcode
the byte offset is pushed to the stack via PUSH
, but the
offset to the JUMPDEST
depends on all occurrences of PUSH
prior to
the label, including the PUSH
to the label itself.
Synopsis
- type Label = Text
- type LabelledOpcode = Opcode' Label
- data TranslateError = TranslateError {}
- translate :: [LabelledOpcode] -> Either TranslateError [PositionalOpcode]
- labelPositions :: [LabelledOpcode] -> Either TranslateError (Map Label Position)
Documentation
type LabelledOpcode = Opcode' Label Source #
LabelledOpcode
s use Label
to represent jumps.
In particular,
, JUMP
"name"
and JUMPI
"name"
.JUMPDEST
"name"
All other opcodes remain the same.
data TranslateError Source #
Translation of LabelledOpcode
s into PositionalOpcode
s may fail if
a jump is made to a non-occurring JUMPDEST
or a JUMPDEST
occurs twice.
Instances
Eq TranslateError Source # | |
Defined in EVM.Opcode.Labelled (==) :: TranslateError -> TranslateError -> Bool # (/=) :: TranslateError -> TranslateError -> Bool # | |
Show TranslateError Source # | |
Defined in EVM.Opcode.Labelled showsPrec :: Int -> TranslateError -> ShowS # show :: TranslateError -> String # showList :: [TranslateError] -> ShowS # |
translate :: [LabelledOpcode] -> Either TranslateError [PositionalOpcode] Source #
Replace all labels with absolute positions.
Positions are calculated by fixed-point iteration to account for variable sizes of jumps. Labelled jumps don't have a size defined, the size of a positional jump depends on the address being jumped to.
For example, if jumping to the JUMPDEST
on the 256th position in a
[
, this requires a LabelledOpcode
]PUSH2
instruction which uses an
additional byte, which pushes the JUMPDEST
one byte ahead.
labelPositions :: [LabelledOpcode] -> Either TranslateError (Map Label Position) Source #