Assembly Reference

Complete reference for all GateVM Assembly operations. All instructions are case-insensitive.

Target & Slot

OperationParametersDescription
SET_TARGETaddress [chainid]Set target contract address (chain ID accepted but ignored for now, supports spaces or commas)
TARGET-Set target from top of stack
SET_SLOTuint256Set storage slot (supports decimal/hex, full uint256)
SLOT-Set slot from top of stack
OFFSETuint256Add value to current slot (supports decimal/hex, full uint256)
ADD_SLOT-Add to current slot (pops value from stack)
FOLLOW-Follow mapping key (pops from stack)
FOLLOW_INDEX-Hash current slot and add offset (used for arrays)
GET_TARGET-Get current target address
GET_SLOT-Get current slot

Stack

OperationParametersDescription
PUSHvaluePush value to stack
PUSH_0-Push 0 bytes to stack
PUSH_1-Push 1 byte to stack
PUSH_2-31-Push 2-31 bytes to stack
PUSH_32-Push 32 bytes to stack
PUSH_BYTEShexPush hex bytes
PUSH_STRstringPush UTF-8 string
PUSH_PROGRAMprogramPush encoded program (bytecode)
PUSH_OUTPUT[index]Push output to stack. With index: pushes output[index]. Without index: pops index from stack, then pushes output[index]
PUSH_STACKindexPush stack item by index (default: 0) - ⚠️ Indexing works in reverse: 0 = bottom of stack
DUPindexPush duplicate of item at index (default: 0, supports decimal/hex)
DUP2-Duplicate top two items on stack
POP-Pop top item from stack
SWAPindexSwap top item with item at index from top (default: 1, supports decimal/hex)

Storage

OperationParametersDescription
READ_SLOT-Read current slot
READ-Alias for READ_SLOT
READ_BYTES-Read as bytes
READ_ARRAY-Read array element
READ_HASHED_BYTES-Read hashed bytes
READ_SLOTScountRead multiple slots (supports decimal/hex, full uint256)

Output

OperationParametersDescription
SET_OUTPUTindexSet output value (default: 0)
OUTPUT-Set output from stack (pops index and value)

String

OperationParametersDescription
CONCAT-Pops: b, a. Push: concatenated string/bytes
SLICEstart lengthPops: length, start, string/bytes. Push: sliced string/bytes (supports decimal/hex, spaces or commas)
LENGTH-Pops: string/bytes. Push: length as number

Math

OperationParametersDescription
PLUS-Pops: b, a. Push: a + b
SUBTRACT-Pops: b, a. Push: a - b
TWOS_COMPLEMENT-Pops: a. Push: -a (two's complement)
TIMES-Pops: b, a. Push: a * b
DIVIDE-Pops: b, a. Push: a / b
MOD-Pops: b, a. Push: a % b
POW-Pops: b, a. Push: a^b
MIN-Pops: b, a. Push: min(a, b)
MAX-Pops: b, a. Push: max(a, b)

Bitwise

OperationParametersDescription
AND-Pops: b, a. Push: a & b
OR-Pops: b, a. Push: a | b
XOR-Pops: b, a. Push: a ^ b
SHIFT_LEFTbitsPops: b, a. Push: a << b (supports decimal/hex)
SHIFT_RIGHTbitsPops: b, a. Push: a >> b (supports decimal/hex)
NOT-Pops: a. Push: ~a

Comparison

OperationParametersDescription
IS_ZERO-Pops: a. Push: 1 if a == 0, 0 otherwise
EQ-Pops: b, a. Push: 1 if a == b, 0 otherwise
NEQ-Pops: b, a. Push: 1 if a != b, 0 otherwise
LT-Pops: b, a. Push: 1 if a < b, 0 otherwise
LTE-Pops: b, a. Push: 1 if a <= b, 0 otherwise
GT-Pops: b, a. Push: 1 if a > b, 0 otherwise
GTE-Pops: b, a. Push: 1 if a >= b, 0 otherwise

Control

OperationParametersDescription
FOR_INDEXstart end incrementLoop with index variable. Expands to individual instructions. Body must be indented 2+ spaces. Index variables: INDEX, index, I, i. Example: "FOR_INDEX 0 5 1" generates indices 0,1,2,3,4,5. "FOR_INDEX 5 0 -1" generates 5,4,3,2,1,0. Cannot contain nested programs.
EVAL_LOOPcount [flags]Before calling EVAL_LOOP, push one value for each loop iteration and the program using push_bytes 0x.... Executes program count times, using one stack item per iteration as input. Usage: "EVAL_LOOP 5" (count=5, flags=0), "EVAL_LOOP 5 1" (decimal flags), "EVAL_LOOP 5 0b0001" (binary flags with 0b prefix required). Special: "EVAL_LOOP 0" gets count from stack. Flags: 1=STOP_ON_SUCCESS, 2=STOP_ON_FAILURE, 4=ACQUIRE_STATE, 8=KEEP_ARGS. Combine flags by adding: 5=SUCCESS+ACQUIRE, 15=ALL_FLAGS
EVAL-Evaluate program (bytecode)
EVAL_IF-Pops: condition, program (bytecode). Execute program if condition is non-zero
ASSERTexitCodeAssert top stack value is non-zero, fail with exitCode if zero (supports decimal/hex)
EXITexitCodeExit with code (supports decimal/hex)
REQUIRE_CONTRACTexitCodeRequire target is contract (supports decimal/hex)
REQUIRE_NONZEROexitCodePops: top. Require value is non-zero (supports decimal/hex)

Utility

OperationParametersDescription
KECCAK-Pops: a. Push: keccak256(a)
IS_CONTRACT-Push: 1 if target is contract, 0 if not
STACK_SIZE-Push: current stack size
DEBUGmessageCapture state snapshot with message (useful for logging/export). No push or pop

Loops

FOR_INDEX Example

Complete example showing FOR_INDEX loop usage.

Note: FOR_INDEX body must be indented with 2+ spaces.

FOR_INDEX 0 2 1
  PUSH INDEX
  SET_SLOT INDEX
  READ_SLOT

PROGRAM test
  FOR_INDEX 10 12 1
    PUSH I
    READ_SLOT

PUSH_PROGRAM test
EVAL

This example:

  • • FOR_INDEX 0 2 1 expands to: PUSH 0, PUSH 1, PUSH 2
  • • Each iteration also runs SET_SLOT and READ_SLOT
  • • Nested FOR_INDEX in PROGRAM "test" uses I variable
  • • Index variables: INDEX, index, I, i all work

Programs

EVAL_LOOP Example

Complete example showing program definition and EVAL_LOOP usage.

Note: Program body must be indented with 2+ spaces.

STACK_VAL = 7

PROGRAM FOO
  PUSH STACK_VAL
  DUP
  TARGET
  SWAP
  ASSERT 1

PUSH 0
PUSH 1
PUSH 0
PUSH_PROGRAM FOO
EVAL_LOOP 3 0b1101

This example:

  • • Defines constant "STACK_VAL = 7"
  • • Uses EVAL_LOOP with count=3 and flags=0b1101
  • • Flags 0b1101 = STOP_ON_SUCCESS + ACQUIRE_STATE + KEEP_ARGS

Supported by

Unruggable Logo