Skip to main content
@tevm/voltaire
@tevm/voltaire / index / BrandedOpcode

BrandedOpcode

Functions

_disassemble()

_disassemble(bytecode): string[]
Defined in: src/primitives/Opcode/disassemble.js:22 Disassemble bytecode to human-readable strings

Parameters

bytecode
Uint8Array<ArrayBufferLike> Raw bytecode bytes

Returns

string[] Array of formatted instruction strings

Example

const bytecode = new Uint8Array([0x60, 0x01, 0x60, 0x02, 0x01]);
const asm = Opcode.disassemble(bytecode);
// [
//   "0x0000: PUSH1 0x01",
//   "0x0002: PUSH1 0x02",
//   "0x0004: ADD"
// ]

_dupPosition()

_dupPosition(opcode): number | undefined
Defined in: src/primitives/Opcode/dupPosition.js:17 Get position for DUP instruction

Parameters

opcode
BrandedOpcode Opcode to query

Returns

number | undefined Stack position (1-16), or undefined if not a DUP

Example

Opcode.dupPosition(Opcode.DUP1); // 1
Opcode.dupPosition(Opcode.DUP16); // 16
Opcode.dupPosition(Opcode.ADD); // undefined

_format()

_format(instruction): string
Defined in: src/primitives/Opcode/format.js:20 Format instruction to human-readable string

Parameters

instruction
Instruction Instruction to format

Returns

string Human-readable string

Example

const inst = {
  offset: 0,
  opcode: Opcode.PUSH1,
  immediate: new Uint8Array([0x42])
};
Opcode.format(inst); // "0x0000: PUSH1 0x42"

_getCategory()

_getCategory(opcode): string
Defined in: src/primitives/Opcode/getCategory.js:18 Get opcode category

Parameters

opcode
BrandedOpcode Opcode to query

Returns

string Category name

Example

Opcode.getCategory(Opcode.ADD); // "arithmetic"
Opcode.getCategory(Opcode.SSTORE); // "storage"
Opcode.getCategory(Opcode.CALL); // "system"

_getDescription()

_getDescription(opcode): string
Defined in: src/primitives/Opcode/getDescription.js:140 Get human-readable description of an opcode

Parameters

opcode
BrandedOpcode Opcode to query

Returns

string Description or generated description for PUSH/DUP/SWAP

Example

const desc = Opcode.getDescription(Opcode.ADD);
// "Addition operation"

const desc2 = Opcode.getDescription(Opcode.PUSH1);
// "Place 1-byte item on stack"

_getGasCost()

_getGasCost(opcode): number | undefined
Defined in: src/primitives/Opcode/getGasCost.js:16 Get static gas cost for an opcode

Parameters

opcode
BrandedOpcode Opcode to query

Returns

number | undefined Static gas cost or undefined if invalid

Example

const gas = Opcode.getGasCost(Opcode.ADD); // 3
const gas2 = Opcode.getGasCost(Opcode.SSTORE); // 100 (base cost, may be higher at runtime)

_getName()

_getName(opcode): string
Defined in: src/primitives/Opcode/getName.js:16 Get mnemonic name of an opcode (alias for name)

Parameters

opcode
BrandedOpcode Opcode to query

Returns

string Opcode name or “UNKNOWN” if invalid

Example

const name = Opcode.getName(Opcode.ADD); // "ADD"
const name2 = Opcode.getName(0xFF); // "SELFDESTRUCT"

_getPushSize()

_getPushSize(opcode): number
Defined in: src/primitives/Opcode/getPushSize.js:18 Get PUSH data size in bytes

Parameters

opcode
BrandedOpcode Opcode to query

Returns

number Push size (0 for PUSH0, 1-32 for PUSH1-PUSH32, 0 for non-PUSH)

Example

Opcode.getPushSize(Opcode.PUSH0); // 0
Opcode.getPushSize(Opcode.PUSH1); // 1
Opcode.getPushSize(Opcode.PUSH32); // 32
Opcode.getPushSize(Opcode.ADD); // 0

_getStackEffect()

_getStackEffect(opcode): { pop: number; push: number; } | undefined
Defined in: src/primitives/Opcode/getStackEffect.js:19 Get stack effect for an opcode

Parameters

opcode
BrandedOpcode Opcode to query

Returns

{ pop: number; push: number; } | undefined Stack items consumed and produced

Example

const effect = Opcode.getStackEffect(Opcode.ADD);
// { pop: 2, push: 1 }

const effect2 = Opcode.getStackEffect(Opcode.DUP1);
// { pop: 1, push: 2 }

_getStackInput()

_getStackInput(opcode): number | undefined
Defined in: src/primitives/Opcode/getStackInput.js:16 Get number of stack items consumed by an opcode

Parameters

opcode
BrandedOpcode Opcode to query

Returns

number | undefined Number of stack items consumed

Example

const inputs = Opcode.getStackInput(Opcode.ADD); // 2
const inputs2 = Opcode.getStackInput(Opcode.PUSH1); // 0

_getStackOutput()

_getStackOutput(opcode): number | undefined
Defined in: src/primitives/Opcode/getStackOutput.js:16 Get number of stack items produced by an opcode

Parameters

opcode
BrandedOpcode Opcode to query

Returns

number | undefined Number of stack items produced

Example

const outputs = Opcode.getStackOutput(Opcode.ADD); // 1
const outputs2 = Opcode.getStackOutput(Opcode.PUSH1); // 1

_info()

_info(opcode): Info | undefined
Defined in: src/primitives/Opcode/info.js:17 Get metadata for an opcode

Parameters

opcode
BrandedOpcode Opcode to query

Returns

Info | undefined Metadata with gas cost and stack requirements

Example

const info = Opcode.info(Opcode.ADD);
console.log(info?.name); // "ADD"
console.log(info?.gasCost); // 3

_isDup()

_isDup(opcode): boolean
Defined in: src/primitives/Opcode/isDup.js:16 Check if opcode is a DUP instruction

Parameters

opcode
BrandedOpcode Opcode to check

Returns

boolean True if DUP1-DUP16

Example

Opcode.isDup(Opcode.DUP1); // true
Opcode.isDup(Opcode.ADD); // false

_isJump()

_isJump(opcode): boolean
Defined in: src/primitives/Opcode/isJump.js:17 Check if opcode is a jump

Parameters

opcode
BrandedOpcode Opcode to check

Returns

boolean True if JUMP or JUMPI

Example

Opcode.isJump(Opcode.JUMP); // true
Opcode.isJump(Opcode.JUMPI); // true
Opcode.isJump(Opcode.ADD); // false

_isJumpDestination()

_isJumpDestination(opcode): boolean
Defined in: src/primitives/Opcode/isJumpDestination.js:16 Check if opcode is JUMPDEST

Parameters

opcode
BrandedOpcode Opcode to check

Returns

boolean True if JUMPDEST

Example

Opcode.isJumpDestination(Opcode.JUMPDEST); // true
Opcode.isJumpDestination(Opcode.JUMP); // false

_isLog()

_isLog(opcode): boolean
Defined in: src/primitives/Opcode/isLog.js:16 Check if opcode is a LOG instruction

Parameters

opcode
BrandedOpcode Opcode to check

Returns

boolean True if LOG0-LOG4

Example

Opcode.isLog(Opcode.LOG1); // true
Opcode.isLog(Opcode.ADD); // false

_isPush()

_isPush(opcode): boolean
Defined in: src/primitives/Opcode/isPush.js:16 Check if opcode is a PUSH instruction

Parameters

opcode
BrandedOpcode Opcode to check

Returns

boolean True if PUSH0-PUSH32

Example

Opcode.isPush(Opcode.PUSH1); // true
Opcode.isPush(Opcode.ADD); // false

_isSwap()

_isSwap(opcode): boolean
Defined in: src/primitives/Opcode/isSwap.js:16 Check if opcode is a SWAP instruction

Parameters

opcode
BrandedOpcode Opcode to check

Returns

boolean True if SWAP1-SWAP16

Example

Opcode.isSwap(Opcode.SWAP1); // true
Opcode.isSwap(Opcode.ADD); // false

_isTerminating()

_isTerminating(opcode): boolean
Defined in: src/primitives/Opcode/isTerminating.js:16 Check if opcode terminates execution

Parameters

opcode
BrandedOpcode Opcode to check

Returns

boolean True if STOP, RETURN, REVERT, INVALID, or SELFDESTRUCT

Example

Opcode.isTerminating(Opcode.RETURN); // true
Opcode.isTerminating(Opcode.ADD); // false

_isTerminator()

_isTerminator(opcode): boolean
Defined in: src/primitives/Opcode/isTerminator.js:16 Check if opcode terminates execution (alias for isTerminating)

Parameters

opcode
BrandedOpcode Opcode to check

Returns

boolean True if STOP, RETURN, REVERT, INVALID, or SELFDESTRUCT

Example

Opcode.isTerminator(Opcode.RETURN); // true
Opcode.isTerminator(Opcode.ADD); // false

_isValid()

_isValid(opcode): opcode is BrandedOpcode
Defined in: src/primitives/Opcode/isValid.js:16 Check if opcode is valid

Parameters

opcode
number Byte value to check

Returns

opcode is BrandedOpcode True if opcode is defined in the EVM

Example

Opcode.isValid(0x01); // true (ADD)
Opcode.isValid(0x0c); // false (undefined)

_isValidJumpDest()

_isValidJumpDest(bytecode, offset): boolean
Defined in: src/primitives/Opcode/isValidJumpDest.js:18 Check if offset is a valid jump destination

Parameters

bytecode
Uint8Array<ArrayBufferLike> Raw bytecode bytes
offset
number Byte offset to check

Returns

boolean True if offset is a JUMPDEST and not inside immediate data

Example

const bytecode = new Uint8Array([0x5b, 0x60, 0x01]);
Opcode.isValidJumpDest(bytecode, 0); // true (JUMPDEST)
Opcode.isValidJumpDest(bytecode, 2); // false (immediate data)

_isValidOpcode()

_isValidOpcode(value): boolean
Defined in: src/primitives/Opcode/isValidOpcode.js:17 Check if value is a valid opcode (alias for isValid)

Parameters

value
number Value to check

Returns

boolean True if valid opcode

Example

Opcode.isValidOpcode(0x01); // true (ADD)
Opcode.isValidOpcode(0xFF); // true (SELFDESTRUCT)
Opcode.isValidOpcode(0x0C); // false

_jumpDests()

_jumpDests(bytecode): Set<number>
Defined in: src/primitives/Opcode/jumpDests.js:17 Find all valid JUMPDEST locations

Parameters

bytecode
Uint8Array<ArrayBufferLike> Raw bytecode bytes

Returns

Set<number> Set of valid jump destinations (byte offsets)

Example

const bytecode = new Uint8Array([0x5b, 0x60, 0x01, 0x5b]);
const dests = Opcode.jumpDests(bytecode); // Set { 0, 3 }

_logTopics()

_logTopics(opcode): number | undefined
Defined in: src/primitives/Opcode/logTopics.js:17 Get number of topics for LOG instruction

Parameters

opcode
BrandedOpcode Opcode to query

Returns

number | undefined Number of topics (0-4), or undefined if not a LOG

Example

Opcode.logTopics(Opcode.LOG0); // 0
Opcode.logTopics(Opcode.LOG4); // 4
Opcode.logTopics(Opcode.ADD); // undefined

_name()

_name(opcode): string
Defined in: src/primitives/Opcode/name.js:15 Get name of an opcode

Parameters

opcode
BrandedOpcode Opcode to query

Returns

string Opcode name or “UNKNOWN” if invalid

Example

const name = Opcode.name(Opcode.ADD); // "ADD"

_parse()

_parse(bytecode): Instruction[]
Defined in: src/primitives/Opcode/parse.js:21 Parse bytecode into instructions

Parameters

bytecode
Uint8Array<ArrayBufferLike> Raw bytecode bytes

Returns

Instruction[] Array of parsed instructions

Example

const bytecode = new Uint8Array([0x60, 0x01, 0x60, 0x02, 0x01]);
const instructions = Opcode.parse(bytecode);
// [
//   { offset: 0, opcode: PUSH1, immediate: [0x01] },
//   { offset: 2, opcode: PUSH1, immediate: [0x02] },
//   { offset: 4, opcode: ADD }
// ]

_pushBytes()

_pushBytes(opcode): number | undefined
Defined in: src/primitives/Opcode/pushBytes.js:18 Get number of bytes pushed by PUSH instruction

Parameters

opcode
BrandedOpcode Opcode to query

Returns

number | undefined Number of bytes (0-32), or undefined if not a PUSH

Example

Opcode.pushBytes(Opcode.PUSH1); // 1
Opcode.pushBytes(Opcode.PUSH32); // 32
Opcode.pushBytes(Opcode.PUSH0); // 0
Opcode.pushBytes(Opcode.ADD); // undefined

_pushOpcode()

_pushOpcode(bytes): BrandedOpcode
Defined in: src/primitives/Opcode/pushOpcode.js:19 Get PUSH opcode for given byte count

Parameters

bytes
number Number of bytes (0-32)

Returns

BrandedOpcode PUSH opcode for that size

Throws

If bytes is not 0-32

Example

Opcode.pushOpcode(1); // Opcode.PUSH1
Opcode.pushOpcode(32); // Opcode.PUSH32
Opcode.pushOpcode(0); // Opcode.PUSH0

_swapPosition()

_swapPosition(opcode): number | undefined
Defined in: src/primitives/Opcode/swapPosition.js:17 Get position for SWAP instruction

Parameters

opcode
BrandedOpcode Opcode to query

Returns

number | undefined Stack position (1-16), or undefined if not a SWAP

Example

Opcode.swapPosition(Opcode.SWAP1); // 1
Opcode.swapPosition(Opcode.SWAP16); // 16
Opcode.swapPosition(Opcode.ADD); // undefined

disassemble()

disassemble(bytecode): string[]
Defined in: src/primitives/Opcode/disassemble.js:22 Disassemble bytecode to human-readable strings

Parameters

bytecode
Uint8Array<ArrayBufferLike> Raw bytecode bytes

Returns

string[] Array of formatted instruction strings

Example

const bytecode = new Uint8Array([0x60, 0x01, 0x60, 0x02, 0x01]);
const asm = Opcode.disassemble(bytecode);
// [
//   "0x0000: PUSH1 0x01",
//   "0x0002: PUSH1 0x02",
//   "0x0004: ADD"
// ]

dupPosition()

dupPosition(opcode): number | undefined
Defined in: src/primitives/Opcode/dupPosition.js:17 Get position for DUP instruction

Parameters

opcode
BrandedOpcode Opcode to query

Returns

number | undefined Stack position (1-16), or undefined if not a DUP

Example

Opcode.dupPosition(Opcode.DUP1); // 1
Opcode.dupPosition(Opcode.DUP16); // 16
Opcode.dupPosition(Opcode.ADD); // undefined

format()

format(instruction): string
Defined in: src/primitives/Opcode/format.js:20 Format instruction to human-readable string

Parameters

instruction
Instruction Instruction to format

Returns

string Human-readable string

Example

const inst = {
  offset: 0,
  opcode: Opcode.PUSH1,
  immediate: new Uint8Array([0x42])
};
Opcode.format(inst); // "0x0000: PUSH1 0x42"

getCategory()

getCategory(opcode): string
Defined in: src/primitives/Opcode/getCategory.js:18 Get opcode category

Parameters

opcode
BrandedOpcode Opcode to query

Returns

string Category name

Example

Opcode.getCategory(Opcode.ADD); // "arithmetic"
Opcode.getCategory(Opcode.SSTORE); // "storage"
Opcode.getCategory(Opcode.CALL); // "system"

getDescription()

getDescription(opcode): string
Defined in: src/primitives/Opcode/getDescription.js:140 Get human-readable description of an opcode

Parameters

opcode
BrandedOpcode Opcode to query

Returns

string Description or generated description for PUSH/DUP/SWAP

Example

const desc = Opcode.getDescription(Opcode.ADD);
// "Addition operation"

const desc2 = Opcode.getDescription(Opcode.PUSH1);
// "Place 1-byte item on stack"

getGasCost()

getGasCost(opcode): number | undefined
Defined in: src/primitives/Opcode/getGasCost.js:16 Get static gas cost for an opcode

Parameters

opcode
BrandedOpcode Opcode to query

Returns

number | undefined Static gas cost or undefined if invalid

Example

const gas = Opcode.getGasCost(Opcode.ADD); // 3
const gas2 = Opcode.getGasCost(Opcode.SSTORE); // 100 (base cost, may be higher at runtime)

getName()

getName(opcode): string
Defined in: src/primitives/Opcode/getName.js:16 Get mnemonic name of an opcode (alias for name)

Parameters

opcode
BrandedOpcode Opcode to query

Returns

string Opcode name or “UNKNOWN” if invalid

Example

const name = Opcode.getName(Opcode.ADD); // "ADD"
const name2 = Opcode.getName(0xFF); // "SELFDESTRUCT"

getPushSize()

getPushSize(opcode): number
Defined in: src/primitives/Opcode/getPushSize.js:18 Get PUSH data size in bytes

Parameters

opcode
BrandedOpcode Opcode to query

Returns

number Push size (0 for PUSH0, 1-32 for PUSH1-PUSH32, 0 for non-PUSH)

Example

Opcode.getPushSize(Opcode.PUSH0); // 0
Opcode.getPushSize(Opcode.PUSH1); // 1
Opcode.getPushSize(Opcode.PUSH32); // 32
Opcode.getPushSize(Opcode.ADD); // 0

getStackEffect()

getStackEffect(opcode): { pop: number; push: number; } | undefined
Defined in: src/primitives/Opcode/getStackEffect.js:19 Get stack effect for an opcode

Parameters

opcode
BrandedOpcode Opcode to query

Returns

{ pop: number; push: number; } | undefined Stack items consumed and produced

Example

const effect = Opcode.getStackEffect(Opcode.ADD);
// { pop: 2, push: 1 }

const effect2 = Opcode.getStackEffect(Opcode.DUP1);
// { pop: 1, push: 2 }

getStackInput()

getStackInput(opcode): number | undefined
Defined in: src/primitives/Opcode/getStackInput.js:16 Get number of stack items consumed by an opcode

Parameters

opcode
BrandedOpcode Opcode to query

Returns

number | undefined Number of stack items consumed

Example

const inputs = Opcode.getStackInput(Opcode.ADD); // 2
const inputs2 = Opcode.getStackInput(Opcode.PUSH1); // 0

getStackOutput()

getStackOutput(opcode): number | undefined
Defined in: src/primitives/Opcode/getStackOutput.js:16 Get number of stack items produced by an opcode

Parameters

opcode
BrandedOpcode Opcode to query

Returns

number | undefined Number of stack items produced

Example

const outputs = Opcode.getStackOutput(Opcode.ADD); // 1
const outputs2 = Opcode.getStackOutput(Opcode.PUSH1); // 1

info()

info(opcode): Info | undefined
Defined in: src/primitives/Opcode/info.js:17 Get metadata for an opcode

Parameters

opcode
BrandedOpcode Opcode to query

Returns

Info | undefined Metadata with gas cost and stack requirements

Example

const info = Opcode.info(Opcode.ADD);
console.log(info?.name); // "ADD"
console.log(info?.gasCost); // 3

isDup()

isDup(opcode): boolean
Defined in: src/primitives/Opcode/isDup.js:16 Check if opcode is a DUP instruction

Parameters

opcode
BrandedOpcode Opcode to check

Returns

boolean True if DUP1-DUP16

Example

Opcode.isDup(Opcode.DUP1); // true
Opcode.isDup(Opcode.ADD); // false

isJump()

isJump(opcode): boolean
Defined in: src/primitives/Opcode/isJump.js:17 Check if opcode is a jump

Parameters

opcode
BrandedOpcode Opcode to check

Returns

boolean True if JUMP or JUMPI

Example

Opcode.isJump(Opcode.JUMP); // true
Opcode.isJump(Opcode.JUMPI); // true
Opcode.isJump(Opcode.ADD); // false

isJumpDestination()

isJumpDestination(opcode): boolean
Defined in: src/primitives/Opcode/isJumpDestination.js:16 Check if opcode is JUMPDEST

Parameters

opcode
BrandedOpcode Opcode to check

Returns

boolean True if JUMPDEST

Example

Opcode.isJumpDestination(Opcode.JUMPDEST); // true
Opcode.isJumpDestination(Opcode.JUMP); // false

isLog()

isLog(opcode): boolean
Defined in: src/primitives/Opcode/isLog.js:16 Check if opcode is a LOG instruction

Parameters

opcode
BrandedOpcode Opcode to check

Returns

boolean True if LOG0-LOG4

Example

Opcode.isLog(Opcode.LOG1); // true
Opcode.isLog(Opcode.ADD); // false

isPush()

isPush(opcode): boolean
Defined in: src/primitives/Opcode/isPush.js:16 Check if opcode is a PUSH instruction

Parameters

opcode
BrandedOpcode Opcode to check

Returns

boolean True if PUSH0-PUSH32

Example

Opcode.isPush(Opcode.PUSH1); // true
Opcode.isPush(Opcode.ADD); // false

isSwap()

isSwap(opcode): boolean
Defined in: src/primitives/Opcode/isSwap.js:16 Check if opcode is a SWAP instruction

Parameters

opcode
BrandedOpcode Opcode to check

Returns

boolean True if SWAP1-SWAP16

Example

Opcode.isSwap(Opcode.SWAP1); // true
Opcode.isSwap(Opcode.ADD); // false

isTerminating()

isTerminating(opcode): boolean
Defined in: src/primitives/Opcode/isTerminating.js:16 Check if opcode terminates execution

Parameters

opcode
BrandedOpcode Opcode to check

Returns

boolean True if STOP, RETURN, REVERT, INVALID, or SELFDESTRUCT

Example

Opcode.isTerminating(Opcode.RETURN); // true
Opcode.isTerminating(Opcode.ADD); // false

isTerminator()

isTerminator(opcode): boolean
Defined in: src/primitives/Opcode/isTerminator.js:16 Check if opcode terminates execution (alias for isTerminating)

Parameters

opcode
BrandedOpcode Opcode to check

Returns

boolean True if STOP, RETURN, REVERT, INVALID, or SELFDESTRUCT

Example

Opcode.isTerminator(Opcode.RETURN); // true
Opcode.isTerminator(Opcode.ADD); // false

isValid()

isValid(opcode): opcode is BrandedOpcode
Defined in: src/primitives/Opcode/isValid.js:16 Check if opcode is valid

Parameters

opcode
number Byte value to check

Returns

opcode is BrandedOpcode True if opcode is defined in the EVM

Example

Opcode.isValid(0x01); // true (ADD)
Opcode.isValid(0x0c); // false (undefined)

isValidJumpDest()

isValidJumpDest(bytecode, offset): boolean
Defined in: src/primitives/Opcode/isValidJumpDest.js:18 Check if offset is a valid jump destination

Parameters

bytecode
Uint8Array<ArrayBufferLike> Raw bytecode bytes
offset
number Byte offset to check

Returns

boolean True if offset is a JUMPDEST and not inside immediate data

Example

const bytecode = new Uint8Array([0x5b, 0x60, 0x01]);
Opcode.isValidJumpDest(bytecode, 0); // true (JUMPDEST)
Opcode.isValidJumpDest(bytecode, 2); // false (immediate data)

isValidOpcode()

isValidOpcode(value): boolean
Defined in: src/primitives/Opcode/isValidOpcode.js:17 Check if value is a valid opcode (alias for isValid)

Parameters

value
number Value to check

Returns

boolean True if valid opcode

Example

Opcode.isValidOpcode(0x01); // true (ADD)
Opcode.isValidOpcode(0xFF); // true (SELFDESTRUCT)
Opcode.isValidOpcode(0x0C); // false

jumpDests()

jumpDests(bytecode): Set<number>
Defined in: src/primitives/Opcode/jumpDests.js:17 Find all valid JUMPDEST locations

Parameters

bytecode
Uint8Array<ArrayBufferLike> Raw bytecode bytes

Returns

Set<number> Set of valid jump destinations (byte offsets)

Example

const bytecode = new Uint8Array([0x5b, 0x60, 0x01, 0x5b]);
const dests = Opcode.jumpDests(bytecode); // Set { 0, 3 }

logTopics()

logTopics(opcode): number | undefined
Defined in: src/primitives/Opcode/logTopics.js:17 Get number of topics for LOG instruction

Parameters

opcode
BrandedOpcode Opcode to query

Returns

number | undefined Number of topics (0-4), or undefined if not a LOG

Example

Opcode.logTopics(Opcode.LOG0); // 0
Opcode.logTopics(Opcode.LOG4); // 4
Opcode.logTopics(Opcode.ADD); // undefined

name()

name(opcode): string
Defined in: src/primitives/Opcode/name.js:15 Get name of an opcode

Parameters

opcode
BrandedOpcode Opcode to query

Returns

string Opcode name or “UNKNOWN” if invalid

Example

const name = Opcode.name(Opcode.ADD); // "ADD"

parse()

parse(bytecode): Instruction[]
Defined in: src/primitives/Opcode/parse.js:21 Parse bytecode into instructions

Parameters

bytecode
Uint8Array<ArrayBufferLike> Raw bytecode bytes

Returns

Instruction[] Array of parsed instructions

Example

const bytecode = new Uint8Array([0x60, 0x01, 0x60, 0x02, 0x01]);
const instructions = Opcode.parse(bytecode);
// [
//   { offset: 0, opcode: PUSH1, immediate: [0x01] },
//   { offset: 2, opcode: PUSH1, immediate: [0x02] },
//   { offset: 4, opcode: ADD }
// ]

pushBytes()

pushBytes(opcode): number | undefined
Defined in: src/primitives/Opcode/pushBytes.js:18 Get number of bytes pushed by PUSH instruction

Parameters

opcode
BrandedOpcode Opcode to query

Returns

number | undefined Number of bytes (0-32), or undefined if not a PUSH

Example

Opcode.pushBytes(Opcode.PUSH1); // 1
Opcode.pushBytes(Opcode.PUSH32); // 32
Opcode.pushBytes(Opcode.PUSH0); // 0
Opcode.pushBytes(Opcode.ADD); // undefined

pushOpcode()

pushOpcode(bytes): BrandedOpcode
Defined in: src/primitives/Opcode/pushOpcode.js:19 Get PUSH opcode for given byte count

Parameters

bytes
number Number of bytes (0-32)

Returns

BrandedOpcode PUSH opcode for that size

Throws

If bytes is not 0-32

Example

Opcode.pushOpcode(1); // Opcode.PUSH1
Opcode.pushOpcode(32); // Opcode.PUSH32
Opcode.pushOpcode(0); // Opcode.PUSH0

swapPosition()

swapPosition(opcode): number | undefined
Defined in: src/primitives/Opcode/swapPosition.js:17 Get position for SWAP instruction

Parameters

opcode
BrandedOpcode Opcode to query

Returns

number | undefined Stack position (1-16), or undefined if not a SWAP

Example

Opcode.swapPosition(Opcode.SWAP1); // 1
Opcode.swapPosition(Opcode.SWAP16); // 16
Opcode.swapPosition(Opcode.ADD); // undefined

References

ADD

Re-exports ADD

ADDMOD

Re-exports ADDMOD

ADDRESS

Re-exports ADDRESS

AND

Re-exports AND

AUTH

Re-exports AUTH

AUTHCALL

Re-exports AUTHCALL

BALANCE

Re-exports BALANCE

BASEFEE

Re-exports BASEFEE

BLOBBASEFEE

Re-exports BLOBBASEFEE

BLOBHASH

Re-exports BLOBHASH

BLOCKHASH

Re-exports BLOCKHASH

BrandedOpcode

Re-exports BrandedOpcode

BYTE

Re-exports BYTE

CALL

Re-exports CALL

CALLCODE

Re-exports CALLCODE

CALLDATACOPY

Re-exports CALLDATACOPY

CALLDATALOAD

Re-exports CALLDATALOAD

CALLDATASIZE

Re-exports CALLDATASIZE

CALLER

Re-exports CALLER

CALLVALUE

Re-exports CALLVALUE

CHAINID

Re-exports CHAINID

CODECOPY

Re-exports CODECOPY

CODESIZE

Re-exports CODESIZE

COINBASE

Re-exports COINBASE

CREATE

Re-exports CREATE

CREATE2

Re-exports CREATE2

DELEGATECALL

Re-exports DELEGATECALL

DIFFICULTY

Re-exports DIFFICULTY

DIV

Re-exports DIV

DUP1

Re-exports DUP1

DUP10

Re-exports DUP10

DUP11

Re-exports DUP11

DUP12

Re-exports DUP12

DUP13

Re-exports DUP13

DUP14

Re-exports DUP14

DUP15

Re-exports DUP15

DUP16

Re-exports DUP16

DUP2

Re-exports DUP2

DUP3

Re-exports DUP3

DUP4

Re-exports DUP4

DUP5

Re-exports DUP5

DUP6

Re-exports DUP6

DUP7

Re-exports DUP7

DUP8

Re-exports DUP8

DUP9

Re-exports DUP9

EQ

Re-exports EQ

EXP

Re-exports EXP

EXTCODECOPY

Re-exports EXTCODECOPY

EXTCODEHASH

Re-exports EXTCODEHASH

EXTCODESIZE

Re-exports EXTCODESIZE

GAS

Re-exports GAS

GASLIMIT

Re-exports GASLIMIT

GASPRICE

Re-exports GASPRICE

GT

Re-exports GT

Info

Re-exports Info

Instruction

Re-exports Instruction

INVALID

Re-exports INVALID

ISZERO

Re-exports ISZERO

JUMP

Re-exports JUMP

JUMPDEST

Re-exports JUMPDEST

JUMPI

Re-exports JUMPI

KECCAK256

Re-exports KECCAK256

LOG0

Re-exports LOG0

LOG1

Re-exports LOG1

LOG2

Re-exports LOG2

LOG3

Re-exports LOG3

LOG4

Re-exports LOG4

LT

Re-exports LT

MCOPY

Re-exports MCOPY

MLOAD

Re-exports MLOAD

MOD

Re-exports MOD

MSIZE

Re-exports MSIZE

MSTORE

Re-exports MSTORE

MSTORE8

Re-exports MSTORE8

MUL

Re-exports MUL

MULMOD

Re-exports MULMOD

NOT

Re-exports NOT

NUMBER

Re-exports NUMBER

Opcode

Re-exports Opcode

OR

Re-exports OR

ORIGIN

Re-exports ORIGIN

PC

Re-exports PC

POP

Re-exports POP

PUSH0

Re-exports PUSH0

PUSH1

Re-exports PUSH1

PUSH10

Re-exports PUSH10

PUSH11

Re-exports PUSH11

PUSH12

Re-exports PUSH12

PUSH13

Re-exports PUSH13

PUSH14

Re-exports PUSH14

PUSH15

Re-exports PUSH15

PUSH16

Re-exports PUSH16

PUSH17

Re-exports PUSH17

PUSH18

Re-exports PUSH18

PUSH19

Re-exports PUSH19

PUSH2

Re-exports PUSH2

PUSH20

Re-exports PUSH20

PUSH21

Re-exports PUSH21

PUSH22

Re-exports PUSH22

PUSH23

Re-exports PUSH23

PUSH24

Re-exports PUSH24

PUSH25

Re-exports PUSH25

PUSH26

Re-exports PUSH26

PUSH27

Re-exports PUSH27

PUSH28

Re-exports PUSH28

PUSH29

Re-exports PUSH29

PUSH3

Re-exports PUSH3

PUSH30

Re-exports PUSH30

PUSH31

Re-exports PUSH31

PUSH32

Re-exports PUSH32

PUSH4

Re-exports PUSH4

PUSH5

Re-exports PUSH5

PUSH6

Re-exports PUSH6

PUSH7

Re-exports PUSH7

PUSH8

Re-exports PUSH8

PUSH9

Re-exports PUSH9

RETURN

Re-exports RETURN

RETURNDATACOPY

Re-exports RETURNDATACOPY

RETURNDATASIZE

Re-exports RETURNDATASIZE

REVERT

Re-exports REVERT

SAR

Re-exports SAR

SDIV

Re-exports SDIV

SELFBALANCE

Re-exports SELFBALANCE

SELFDESTRUCT

Re-exports SELFDESTRUCT

SGT

Re-exports SGT

SHL

Re-exports SHL

SHR

Re-exports SHR

SIGNEXTEND

Re-exports SIGNEXTEND

SLOAD

Re-exports SLOAD

SLT

Re-exports SLT

SMOD

Re-exports SMOD

SSTORE

Re-exports SSTORE

STATICCALL

Re-exports STATICCALL

STOP

Re-exports STOP

SUB

Re-exports SUB

SWAP1

Re-exports SWAP1

SWAP10

Re-exports SWAP10

SWAP11

Re-exports SWAP11

SWAP12

Re-exports SWAP12

SWAP13

Re-exports SWAP13

SWAP14

Re-exports SWAP14

SWAP15

Re-exports SWAP15

SWAP16

Re-exports SWAP16

SWAP2

Re-exports SWAP2

SWAP3

Re-exports SWAP3

SWAP4

Re-exports SWAP4

SWAP5

Re-exports SWAP5

SWAP6

Re-exports SWAP6

SWAP7

Re-exports SWAP7

SWAP8

Re-exports SWAP8

SWAP9

Re-exports SWAP9

TIMESTAMP

Re-exports TIMESTAMP

TLOAD

Re-exports TLOAD

TSTORE

Re-exports TSTORE

XOR

Re-exports XOR