Skip to main content
@tevm/voltaire
@tevm/voltaire / primitives/Opcode

primitives/Opcode

Type Aliases

BrandedOpcode

BrandedOpcode = number & object
Defined in: src/primitives/Opcode/OpcodeType.ts:6 Branded type for EVM opcodes (number 0x00-0xFF)

Type Declaration

[brand]
readonly [brand]: "Opcode"

Info

Info = object
Defined in: src/primitives/Opcode/OpcodeType.ts:23 Opcode metadata structure

Properties

gasCost
gasCost: number
Defined in: src/primitives/Opcode/OpcodeType.ts:25 Base gas cost (may be dynamic at runtime)
name
name: string
Defined in: src/primitives/Opcode/OpcodeType.ts:31 Opcode name
stackInputs
stackInputs: number
Defined in: src/primitives/Opcode/OpcodeType.ts:27 Number of stack items consumed
stackOutputs
stackOutputs: number
Defined in: src/primitives/Opcode/OpcodeType.ts:29 Number of stack items produced

Instruction

Instruction = object
Defined in: src/primitives/Opcode/OpcodeType.ts:11 Instruction with opcode and optional immediate data

Properties

immediate?
optional immediate: Uint8Array
Defined in: src/primitives/Opcode/OpcodeType.ts:17 Immediate data for PUSH operations
offset
offset: number
Defined in: src/primitives/Opcode/OpcodeType.ts:13 Program counter offset
opcode
opcode: BrandedOpcode
Defined in: src/primitives/Opcode/OpcodeType.ts:15 The opcode

Variables

ADD

const ADD: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:10

ADDMOD

const ADDMOD: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:17

ADDRESS

const ADDRESS: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:52

AND

const AND: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:37

AUTH

const AUTH: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:312

AUTHCALL

const AUTHCALL: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:313

BALANCE

const BALANCE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:55

BASEFEE

const BASEFEE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:121

BLOBBASEFEE

const BLOBBASEFEE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:127

BLOBHASH

const BLOBHASH: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:124

BLOCKHASH

const BLOCKHASH: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:97

BrandedOpcode

const BrandedOpcode: object
Defined in: src/primitives/Opcode/Opcode.js:164

Type Declaration

ADD
ADD: BrandedOpcode
ADDMOD
ADDMOD: BrandedOpcode
ADDRESS
ADDRESS: BrandedOpcode
AND
AND: BrandedOpcode
AUTH
AUTH: BrandedOpcode
AUTHCALL
AUTHCALL: BrandedOpcode
BALANCE
BALANCE: BrandedOpcode
BASEFEE
BASEFEE: BrandedOpcode
BLOBBASEFEE
BLOBBASEFEE: BrandedOpcode
BLOBHASH
BLOBHASH: BrandedOpcode
BLOCKHASH
BLOCKHASH: BrandedOpcode
BYTE
BYTE: BrandedOpcode
CALL
CALL: BrandedOpcode
CALLCODE
CALLCODE: BrandedOpcode
CALLDATACOPY
CALLDATACOPY: BrandedOpcode
CALLDATALOAD
CALLDATALOAD: BrandedOpcode
CALLDATASIZE
CALLDATASIZE: BrandedOpcode
CALLER
CALLER: BrandedOpcode
CALLVALUE
CALLVALUE: BrandedOpcode
CHAINID
CHAINID: BrandedOpcode
CODECOPY
CODECOPY: BrandedOpcode
CODESIZE
CODESIZE: BrandedOpcode
COINBASE
COINBASE: BrandedOpcode
CREATE
CREATE: BrandedOpcode
CREATE2
CREATE2: BrandedOpcode
DELEGATECALL
DELEGATECALL: BrandedOpcode
DIFFICULTY
DIFFICULTY: BrandedOpcode
disassemble()
disassemble: (bytecode) => string[]
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"
// ]
DIV
DIV: BrandedOpcode
DUP1
DUP1: BrandedOpcode
DUP10
DUP10: BrandedOpcode
DUP11
DUP11: BrandedOpcode
DUP12
DUP12: BrandedOpcode
DUP13
DUP13: BrandedOpcode
DUP14
DUP14: BrandedOpcode
DUP15
DUP15: BrandedOpcode
DUP16
DUP16: BrandedOpcode
DUP2
DUP2: BrandedOpcode
DUP3
DUP3: BrandedOpcode
DUP4
DUP4: BrandedOpcode
DUP5
DUP5: BrandedOpcode
DUP6
DUP6: BrandedOpcode
DUP7
DUP7: BrandedOpcode
DUP8
DUP8: BrandedOpcode
DUP9
DUP9: BrandedOpcode
dupPosition()
dupPosition: (opcode) => number | undefined
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
EQ
EQ: BrandedOpcode
EXP
EXP: BrandedOpcode
EXTCODECOPY
EXTCODECOPY: BrandedOpcode
EXTCODEHASH
EXTCODEHASH: BrandedOpcode
EXTCODESIZE
EXTCODESIZE: BrandedOpcode
format()
format: (instruction) => string
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"
GAS
GAS: BrandedOpcode
GASLIMIT
GASLIMIT: BrandedOpcode
GASPRICE
GASPRICE: BrandedOpcode
getCategory()
getCategory: (opcode) => string
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
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
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
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
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
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
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
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
GT
GT: BrandedOpcode
info()
info: (opcode) => Info | undefined
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
INVALID
INVALID: BrandedOpcode
isDup()
isDup: (opcode) => boolean
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
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
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
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
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
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
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
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
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
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
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
ISZERO
ISZERO: BrandedOpcode
JUMP
JUMP: BrandedOpcode
JUMPDEST
JUMPDEST: BrandedOpcode
jumpDests()
jumpDests: (bytecode) => Set<number>
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 }
JUMPI
JUMPI: BrandedOpcode
KECCAK256
KECCAK256: BrandedOpcode
LOG0
LOG0: BrandedOpcode
LOG1
LOG1: BrandedOpcode
LOG2
LOG2: BrandedOpcode
LOG3
LOG3: BrandedOpcode
LOG4
LOG4: BrandedOpcode
logTopics()
logTopics: (opcode) => number | undefined
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
LT
LT: BrandedOpcode
MCOPY
MCOPY: BrandedOpcode
MLOAD
MLOAD: BrandedOpcode
MOD
MOD: BrandedOpcode
MSIZE
MSIZE: BrandedOpcode
MSTORE
MSTORE: BrandedOpcode
MSTORE8
MSTORE8: BrandedOpcode
MUL
MUL: BrandedOpcode
MULMOD
MULMOD: BrandedOpcode
name()
name: (opcode) => string
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"
NOT
NOT: BrandedOpcode
NUMBER
NUMBER: BrandedOpcode
OR
OR: BrandedOpcode
ORIGIN
ORIGIN: BrandedOpcode
parse()
parse: (bytecode) => Instruction[]
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 }
// ]
PC
PC: BrandedOpcode
POP
POP: BrandedOpcode
PUSH0
PUSH0: BrandedOpcode
PUSH1
PUSH1: BrandedOpcode
PUSH10
PUSH10: BrandedOpcode
PUSH11
PUSH11: BrandedOpcode
PUSH12
PUSH12: BrandedOpcode
PUSH13
PUSH13: BrandedOpcode
PUSH14
PUSH14: BrandedOpcode
PUSH15
PUSH15: BrandedOpcode
PUSH16
PUSH16: BrandedOpcode
PUSH17
PUSH17: BrandedOpcode
PUSH18
PUSH18: BrandedOpcode
PUSH19
PUSH19: BrandedOpcode
PUSH2
PUSH2: BrandedOpcode
PUSH20
PUSH20: BrandedOpcode
PUSH21
PUSH21: BrandedOpcode
PUSH22
PUSH22: BrandedOpcode
PUSH23
PUSH23: BrandedOpcode
PUSH24
PUSH24: BrandedOpcode
PUSH25
PUSH25: BrandedOpcode
PUSH26
PUSH26: BrandedOpcode
PUSH27
PUSH27: BrandedOpcode
PUSH28
PUSH28: BrandedOpcode
PUSH29
PUSH29: BrandedOpcode
PUSH3
PUSH3: BrandedOpcode
PUSH30
PUSH30: BrandedOpcode
PUSH31
PUSH31: BrandedOpcode
PUSH32
PUSH32: BrandedOpcode
PUSH4
PUSH4: BrandedOpcode
PUSH5
PUSH5: BrandedOpcode
PUSH6
PUSH6: BrandedOpcode
PUSH7
PUSH7: BrandedOpcode
PUSH8
PUSH8: BrandedOpcode
PUSH9
PUSH9: BrandedOpcode
pushBytes()
pushBytes: (opcode) => number | undefined
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
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
RETURN
RETURN: BrandedOpcode
RETURNDATACOPY
RETURNDATACOPY: BrandedOpcode
RETURNDATASIZE
RETURNDATASIZE: BrandedOpcode
REVERT
REVERT: BrandedOpcode
SAR
SAR: BrandedOpcode
SDIV
SDIV: BrandedOpcode
SELFBALANCE
SELFBALANCE: BrandedOpcode
SELFDESTRUCT
SELFDESTRUCT: BrandedOpcode
SGT
SGT: BrandedOpcode
SHL
SHL: BrandedOpcode
SHR
SHR: BrandedOpcode
SIGNEXTEND
SIGNEXTEND: BrandedOpcode
SLOAD
SLOAD: BrandedOpcode
SLT
SLT: BrandedOpcode
SMOD
SMOD: BrandedOpcode
SSTORE
SSTORE: BrandedOpcode
STATICCALL
STATICCALL: BrandedOpcode
STOP
STOP: BrandedOpcode
SUB
SUB: BrandedOpcode
SWAP1
SWAP1: BrandedOpcode
SWAP10
SWAP10: BrandedOpcode
SWAP11
SWAP11: BrandedOpcode
SWAP12
SWAP12: BrandedOpcode
SWAP13
SWAP13: BrandedOpcode
SWAP14
SWAP14: BrandedOpcode
SWAP15
SWAP15: BrandedOpcode
SWAP16
SWAP16: BrandedOpcode
SWAP2
SWAP2: BrandedOpcode
SWAP3
SWAP3: BrandedOpcode
SWAP4
SWAP4: BrandedOpcode
SWAP5
SWAP5: BrandedOpcode
SWAP6
SWAP6: BrandedOpcode
SWAP7
SWAP7: BrandedOpcode
SWAP8
SWAP8: BrandedOpcode
SWAP9
SWAP9: BrandedOpcode
swapPosition()
swapPosition: (opcode) => number | undefined
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
TIMESTAMP
TIMESTAMP: BrandedOpcode
TLOAD
TLOAD: BrandedOpcode
TSTORE
TSTORE: BrandedOpcode
XOR
XOR: BrandedOpcode

BYTE

const BYTE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:41

CALL

const CALL: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:300

CALLCODE

const CALLCODE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:301

CALLDATACOPY

const CALLDATACOPY: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:71

CALLDATALOAD

const CALLDATALOAD: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:67

CALLDATASIZE

const CALLDATASIZE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:69

CALLER

const CALLER: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:61

CALLVALUE

const CALLVALUE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:64

CHAINID

const CHAINID: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:115

CODECOPY

const CODECOPY: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:76

CODESIZE

const CODESIZE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:73

COINBASE

const COINBASE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:100

CREATE

const CREATE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:297

CREATE2

const CREATE2: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:309

DELEGATECALL

const DELEGATECALL: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:307

DIFFICULTY

const DIFFICULTY: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:109

DIV

const DIV: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:13

DUP1

const DUP1: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:240

DUP10

const DUP10: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:249

DUP11

const DUP11: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:250

DUP12

const DUP12: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:251

DUP13

const DUP13: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:252

DUP14

const DUP14: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:253

DUP15

const DUP15: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:254

DUP16

const DUP16: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:255

DUP2

const DUP2: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:241

DUP3

const DUP3: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:242

DUP4

const DUP4: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:243

DUP5

const DUP5: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:244

DUP6

const DUP6: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:245

DUP7

const DUP7: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:246

DUP8

const DUP8: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:247

DUP9

const DUP9: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:248

EQ

const EQ: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:33

EXP

const EXP: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:23

EXTCODECOPY

const EXTCODECOPY: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:85

EXTCODEHASH

const EXTCODEHASH: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:92

EXTCODESIZE

const EXTCODESIZE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:82

GAS

const GAS: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:148

GASLIMIT

const GASLIMIT: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:112

GASPRICE

const GASPRICE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:79

GT

const GT: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:30

INVALID

const INVALID: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:322

ISZERO

const ISZERO: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:34

JUMP

const JUMP: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:144

JUMPDEST

const JUMPDEST: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:149

JUMPI

const JUMPI: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:145

KECCAK256

const KECCAK256: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:47

LOG0

const LOG0: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:290

LOG1

const LOG1: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:291

LOG2

const LOG2: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:292

LOG3

const LOG3: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:293

LOG4

const LOG4: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:294

LT

const LT: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:29

MCOPY

const MCOPY: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:156

MLOAD

const MLOAD: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:133

MOD

const MOD: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:15

MSIZE

const MSIZE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:147

MSTORE

const MSTORE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:134

MSTORE8

const MSTORE8: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:137

MUL

const MUL: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:11

MULMOD

const MULMOD: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:20

NOT

const NOT: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:40

NUMBER

const NUMBER: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:106

OR

const OR: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:38

ORIGIN

const ORIGIN: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:58

PC

const PC: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:146

POP

const POP: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:132

PUSH0

const PUSH0: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:157

PUSH1

const PUSH1: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:160

PUSH10

const PUSH10: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:169

PUSH11

const PUSH11: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:172

PUSH12

const PUSH12: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:175

PUSH13

const PUSH13: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:178

PUSH14

const PUSH14: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:181

PUSH15

const PUSH15: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:184

PUSH16

const PUSH16: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:187

PUSH17

const PUSH17: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:190

PUSH18

const PUSH18: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:193

PUSH19

const PUSH19: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:196

PUSH2

const PUSH2: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:161

PUSH20

const PUSH20: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:199

PUSH21

const PUSH21: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:202

PUSH22

const PUSH22: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:205

PUSH23

const PUSH23: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:208

PUSH24

const PUSH24: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:211

PUSH25

const PUSH25: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:214

PUSH26

const PUSH26: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:217

PUSH27

const PUSH27: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:220

PUSH28

const PUSH28: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:223

PUSH29

const PUSH29: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:226

PUSH3

const PUSH3: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:162

PUSH30

const PUSH30: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:229

PUSH31

const PUSH31: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:232

PUSH32

const PUSH32: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:235

PUSH4

const PUSH4: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:163

PUSH5

const PUSH5: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:164

PUSH6

const PUSH6: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:165

PUSH7

const PUSH7: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:166

PUSH8

const PUSH8: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:167

PUSH9

const PUSH9: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:168

RETURN

const RETURN: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:304

RETURNDATACOPY

const RETURNDATACOPY: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:90

RETURNDATASIZE

const RETURNDATASIZE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:88

REVERT

const REVERT: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:319

SAR

const SAR: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:44

SDIV

const SDIV: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:14

SELFBALANCE

const SELFBALANCE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:118

SELFDESTRUCT

const SELFDESTRUCT: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:325

SGT

const SGT: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:32

SHL

const SHL: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:42

SHR

const SHR: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:43

SIGNEXTEND

const SIGNEXTEND: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:24

SLOAD

const SLOAD: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:140

SLT

const SLT: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:31

SMOD

const SMOD: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:16

SSTORE

const SSTORE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:141

STATICCALL

const STATICCALL: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:316

STOP

const STOP: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:9

SUB

const SUB: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:12

SWAP1

const SWAP1: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:258

SWAP10

const SWAP10: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:267

SWAP11

const SWAP11: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:270

SWAP12

const SWAP12: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:273

SWAP13

const SWAP13: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:276

SWAP14

const SWAP14: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:279

SWAP15

const SWAP15: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:282

SWAP16

const SWAP16: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:285

SWAP2

const SWAP2: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:259

SWAP3

const SWAP3: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:260

SWAP4

const SWAP4: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:261

SWAP5

const SWAP5: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:262

SWAP6

const SWAP6: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:263

SWAP7

const SWAP7: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:264

SWAP8

const SWAP8: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:265

SWAP9

const SWAP9: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:266

TIMESTAMP

const TIMESTAMP: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:103

TLOAD

const TLOAD: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:152

TSTORE

const TSTORE: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:153

XOR

const XOR: BrandedOpcode
Defined in: src/primitives/Opcode/constants.js:39

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

Opcode

Re-exports Opcode