Assembly Reference
Complete reference for all GateVM Assembly operations. All instructions are case-insensitive.
Target & Slot
| Operation | Parameters | Description |
|---|---|---|
| SET_TARGET | address [chainid] | Set target contract address (chain ID accepted but ignored for now, supports spaces or commas) |
| TARGET | - | Set target from top of stack |
| SET_SLOT | uint256 | Set storage slot (supports decimal/hex, full uint256) |
| SLOT | - | Set slot from top of stack |
| OFFSET | uint256 | Add 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
| Operation | Parameters | Description |
|---|---|---|
| PUSH | value | Push 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_BYTES | hex | Push hex bytes |
| PUSH_STR | string | Push UTF-8 string |
| PUSH_PROGRAM | program | Push 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_STACK | index | Push stack item by index (default: 0) - ⚠️ Indexing works in reverse: 0 = bottom of stack |
| DUP | index | Push duplicate of item at index (default: 0, supports decimal/hex) |
| DUP2 | - | Duplicate top two items on stack |
| POP | - | Pop top item from stack |
| SWAP | index | Swap top item with item at index from top (default: 1, supports decimal/hex) |
Storage
| Operation | Parameters | Description |
|---|---|---|
| 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_SLOTS | count | Read multiple slots (supports decimal/hex, full uint256) |
Output
| Operation | Parameters | Description |
|---|---|---|
| SET_OUTPUT | index | Set output value (default: 0) |
| OUTPUT | - | Set output from stack (pops index and value) |
String
| Operation | Parameters | Description |
|---|---|---|
| CONCAT | - | Pops: b, a. Push: concatenated string/bytes |
| SLICE | start length | Pops: length, start, string/bytes. Push: sliced string/bytes (supports decimal/hex, spaces or commas) |
| LENGTH | - | Pops: string/bytes. Push: length as number |
Math
| Operation | Parameters | Description |
|---|---|---|
| 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
| Operation | Parameters | Description |
|---|---|---|
| AND | - | Pops: b, a. Push: a & b |
| OR | - | Pops: b, a. Push: a | b |
| XOR | - | Pops: b, a. Push: a ^ b |
| SHIFT_LEFT | bits | Pops: b, a. Push: a << b (supports decimal/hex) |
| SHIFT_RIGHT | bits | Pops: b, a. Push: a >> b (supports decimal/hex) |
| NOT | - | Pops: a. Push: ~a |
Comparison
| Operation | Parameters | Description |
|---|---|---|
| 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
| Operation | Parameters | Description |
|---|---|---|
| FOR_INDEX | start end increment | Loop 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_LOOP | count [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 |
| ASSERT | exitCode | Assert top stack value is non-zero, fail with exitCode if zero (supports decimal/hex) |
| EXIT | exitCode | Exit with code (supports decimal/hex) |
| REQUIRE_CONTRACT | exitCode | Require target is contract (supports decimal/hex) |
| REQUIRE_NONZERO | exitCode | Pops: top. Require value is non-zero (supports decimal/hex) |
Utility
| Operation | Parameters | Description |
|---|---|---|
| KECCAK | - | Pops: a. Push: keccak256(a) |
| IS_CONTRACT | - | Push: 1 if target is contract, 0 if not |
| STACK_SIZE | - | Push: current stack size |
| DEBUG | message | Capture 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
EVALThis 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 0b1101This example:
- • Defines constant "STACK_VAL = 7"
- • Uses EVAL_LOOP with count=3 and flags=0b1101
- • Flags 0b1101 = STOP_ON_SUCCESS + ACQUIRE_STATE + KEEP_ARGS
