evm-opcodes-0.1.0: Opcode types for Ethereum Virtual Machine (EVM)
Copyright2018 Simon Shine
LicenseMIT
MaintainerSimon Shine <shreddedglory@gmail.com>
Safe HaskellNone
LanguageHaskell2010

EVM.Opcode.Labelled

Description

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

Documentation

type Label = Text Source #

For now, all labels are Text.

type LabelledOpcode = Opcode' Label Source #

LabelledOpcodes use Label to represent jumps.

In particular, JUMP "name", JUMPI "name" and JUMPDEST "name".

All other opcodes remain the same.

data TranslateError Source #

Translation of LabelledOpcodes into PositionalOpcodes may fail if a jump is made to a non-occurring JUMPDEST or a JUMPDEST occurs twice.

Instances

Instances details
Eq TranslateError Source # 
Instance details

Defined in EVM.Opcode.Labelled

Show TranslateError Source # 
Instance details

Defined in EVM.Opcode.Labelled

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 [LabelledOpcode], this requires a PUSH2 instruction which uses an additional byte, which pushes the JUMPDEST one byte ahead.

labelPositions :: [LabelledOpcode] -> Either TranslateError (Map Label Position) Source #

Extract a Map Label Position that describes where each JUMPDEST is located, taking into account the sizes of all prior opcodes.