Skip to content

Opcodes

The Phantasma VM opcode set and the base gas cost of each opcode.

Gas Cost Model

The VM assigns a small base gas cost per opcode before any interop-side native work is considered. Instructions that move data or compute on large numbers also charge by size; see The Work Table.

The current base costs are:

  • 0
    • NOP, RET
  • 1
    • most ordinary opcodes
  • 5
    • CALL, LOAD, PUT, GET
  • 10
    • EXTCALL, CTX
  • 100
    • SWITCH

Full Opcode Table

OpcodeArgsPurposeBase Gas
NOP-Do nothing.0
MOVEsrc, dstMove a register value by reference semantics.1
COPYsrc, dstCopy a register value by value semantics.1
PUSHsrcPush a register value onto the shared stack.1
POPdstPop the top stack value into a register.1
SWAPa, bSwap two register values.1
CALLcount, offsetEnter a new execution frame and jump to an offset.5
EXTCALLregExecute a native interop method named by the register value.10
JMPoffsetUnconditional jump.1
JMPIFoffset, regJump if the register evaluates to true.1
JMPNOToffset, regJump if the register evaluates to false.1
RET-Return from the current frame or context.0
THROWregAbort execution with a VM exception.1
LOADdst, type, dataLoad an immediate typed value into a register.5
CASTsrc, dst, typeConvert a value into another VM type.1
CATa, b, dstConcatenate values into a result.1
RANGEsrc, dst, index, lengthExtract a slice from a value.1
LEFTsrc, dst, lengthExtract the left-most portion of a value.1
RIGHTsrc, dst, lengthExtract the right-most portion of a value.1
SIZEsrc, dstReturn the serialized RAM size of a value.1
COUNTsrc, dstReturn the number of elements in a struct-like value.1
NOTsrc, dstBoolean negation.1
ANDa, b, dstBoolean or bitwise AND depending on value shape.1
ORa, b, dstBoolean or bitwise OR depending on value shape.1
XORa, b, dstBoolean or bitwise XOR depending on value shape.1
EQUALa, b, dstEquality comparison.1
LTa, b, dstLess-than comparison.1
GTa, b, dstGreater-than comparison.1
LTEa, b, dstLess-than-or-equal comparison.1
GTEa, b, dstGreater-than-or-equal comparison.1
INCregIncrement a numeric value.1
DECregDecrement a numeric value.1
SIGNsrc, dstReturn the sign of a numeric value.1
NEGATEsrc, dstNegate a numeric value.1
ABSsrc, dstReturn absolute value.1
ADDa, b, dstAddition.1
SUBa, b, dstSubtraction.1
MULa, b, dstMultiplication.1
DIVa, b, dstDivision.1
MODa, b, dstModulo.1
SHLa, b, dstShift left.1
SHRa, b, dstShift right.1
MINa, b, dstReturn the smaller value.1
MAXa, b, dstReturn the larger value.1
POWa, b, dstExponentiation.1
CTXsrc, dstResolve a named execution context.10
SWITCHregSwitch execution into a resolved context.100
PUTvalue, target, fieldWrite a field into a struct-like target.5
GETdst, target, fieldRead a field from a struct-like target.5
CLEARregReset a register to None.1
UNPACKsrc, dstDecode a serialized struct-like value.1
PACK-Reserved and unused.1
DEBUG-Debug breakpoint opcode. In code this is stored as DEBUG_.1

Notes For Contract Authors

  • EXTCALL is how VM code reaches native chain functionality such as token transfers, storage helpers, and contract lifecycle operations.
  • CTX and SWITCH are what make cross-context contract calls and trigger execution possible.
  • The base opcode gas above is only part of the final transaction cost. Heavy interops can add much larger native gas charges.