Opcode Enum
All opcodes are represented as a Rust enum with explicit byte values.Control Flow (0x00-0x0F)
HALT (0x00)
Encoding:[0x00] (1 byte)Gas: 0 Halts execution successfully.
NOP (0x01)
Encoding:[0x01] (1 byte)Gas: 0 No operation. Does nothing.
JUMP (0x02)
Encoding:[0x02, RRRR____] (2 bytes)Gas: 8 Unconditional jump to address in register.
Register containing jump destination
[0x02, 0x50]
JUMPI (0x03)
Encoding:[0x03, CCCC_TTTT] (2 bytes)Gas: 8 Conditional jump if condition register is non-zero.
Condition register (jump if non-zero)
Target address register
[0x03, 0x35]
CALL (0x04)
Encoding:[0x04] (1 byte)Gas: 700 Call external contract (placeholder - not fully implemented).
RET (0x05)
Encoding:[0x05] (1 byte)Gas: 0 Return from execution successfully.
REVERT (0x0F)
Encoding:[0x0F] (1 byte)Gas: 0 Revert execution and return error.
Arithmetic (0x10-0x1F)
ADD (0x10)
Encoding:[0x10, DDDD_SSS1, SSS2____] (3 bytes)Gas: 2 Add two registers with wrapping.
Destination register
First source register
Second source register
[0x10, 0x01, 0x20]
SUB (0x11)
Encoding:[0x11, DDDD_SSS1, SSS2____] (3 bytes)Gas: 2 Subtract two registers with wrapping.
[0x11, 0x34, 0x50]
MUL (0x12)
Encoding:[0x12, DDDD_SSS1, SSS2____] (3 bytes)Gas: 3 Multiply two registers with wrapping.
[0x12, 0x01, 0x20]
DIV (0x13)
Encoding:[0x13, DDDD_SSS1, SSS2____] (3 bytes)Gas: 5 Divide two registers. Returns error if divisor is zero.
[0x13, 0x01, 0x20]
Error: VmError::DivisionByZero if R2 == 0
MOD (0x14)
Encoding:[0x14, DDDD_SSS1, SSS2____] (3 bytes)Gas: 5 Modulo operation. Returns error if divisor is zero.
[0x14, 0x01, 0x20]
Error: VmError::DivisionByZero if R2 == 0
ADDI (0x15)
Encoding:[0x15, DDDD_SSSS, imm32] (6 bytes)Gas: 2 Add immediate 32-bit value to register.
Destination register
Source register
32-bit immediate value (little-endian)
[0x15, 0x01, 0xE8, 0x03, 0x00, 0x00]
Bitwise (0x20-0x2F)
AND (0x20)
Encoding:[0x20, DDDD_SSS1, SSS2____] (3 bytes)Gas: 2 Bitwise AND of two registers.
OR (0x21)
Encoding:[0x21, DDDD_SSS1, SSS2____] (3 bytes)Gas: 2 Bitwise OR of two registers.
XOR (0x22)
Encoding:[0x22, DDDD_SSS1, SSS2____] (3 bytes)Gas: 2 Bitwise XOR of two registers.
NOT (0x23)
Encoding:[0x23, RRRR____] (2 bytes)Gas: 2 Bitwise NOT (in-place).
SHL (0x24)
Encoding:[0x24, DDDD_SSS1, SSS2____] (3 bytes)Gas: 5 Shift left. Shift amount is masked to 6 bits (0-63).
SHR (0x25)
Encoding:[0x25, DDDD_SSS1, SSS2____] (3 bytes)Gas: 5 Logical shift right. Shift amount is masked to 6 bits (0-63).
Comparison (0x30-0x3F)
EQ (0x30)
Encoding:[0x30, DDDD_SSS1, SSS2____] (3 bytes)Gas: 2 Test equality. Result is 1 if equal, 0 otherwise.
NE (0x31)
Encoding:[0x31, DDDD_SSS1, SSS2____] (3 bytes)Gas: 2 Test inequality.
LT (0x32)
Encoding:[0x32, DDDD_SSS1, SSS2____] (3 bytes)Gas: 2 Test less than.
GT (0x33)
Encoding:[0x33, DDDD_SSS1, SSS2____] (3 bytes)Gas: 2 Test greater than.
LE (0x34)
Encoding:[0x34, DDDD_SSS1, SSS2____] (3 bytes)Gas: 2 Test less than or equal.
GE (0x35)
Encoding:[0x35, DDDD_SSS1, SSS2____] (3 bytes)Gas: 2 Test greater than or equal.
ISZERO (0x36)
Encoding:[0x36, RRRR____] (2 bytes)Gas: 2 Test if register is zero (in-place).
Memory - RAM (0x40-0x4F)
LOAD8 (0x40)
Encoding:[0x40, DDDD_AAAA] (2 bytes)Gas: 3 Load 8-bit value from memory.
Destination register
Register containing memory address
LOAD64 (0x41)
Encoding:[0x41, DDDD_AAAA] (2 bytes)Gas: 3 Load 64-bit value from memory (little-endian).
STORE8 (0x42)
Encoding:[0x42, AAAA_VVVV] (2 bytes)Gas: 3 Store 8-bit value to memory.
Register containing memory address
Register containing value to store
STORE64 (0x43)
Encoding:[0x43, AAAA_VVVV] (2 bytes)Gas: 3 Store 64-bit value to memory (little-endian).
MSIZE (0x44)
Encoding:[0x44, RRRR____] (2 bytes)Gas: 2 Get current memory size in bytes.
MCOPY (0x45)
Encoding:[0x45, DDDD_SSSS, LLLL____] (3 bytes)Gas: 3 Copy memory region.
Destination address register
Source address register
Length register (number of bytes)
Storage - Disk (0x50-0x5F)
SLOAD (0x50)
Encoding:[0x50, DDDD_KKKK] (2 bytes)Gas: 100 Load from persistent storage. Key is 64-bit value from register, expanded to 32 bytes.
Destination register
Storage key register
SSTORE (0x51)
Encoding:[0x51, KKKK_VVVV] (2 bytes)Gas: 20,000 (set) or 5,000 (reset) Store to persistent storage.
Storage key register
Value register
Immediate (0x70-0x7F)
LOADI (0x70)
Encoding:[0x70, RRRR____, imm64] (10 bytes)Gas: 2 Load 64-bit immediate value into register.
Destination register
64-bit immediate value (little-endian)
[0x70, 0x00, 0xF0, 0xDE, 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12]
MOV (0x71)
Encoding:[0x71, DDDD_SSSS] (2 bytes)Gas: 2 Move value from one register to another.
Context (0x80-0x8F)
CALLER (0x80)
Encoding:[0x80, RRRR____] (2 bytes)Gas: 2 Get caller address (first 8 bytes as u64).
CALLVALUE (0x81)
Encoding:[0x81, RRRR____] (2 bytes)Gas: 2 Get call value.
ADDRESS (0x82)
Encoding:[0x82, RRRR____] (2 bytes)Gas: 2 Get current contract address (first 8 bytes as u64).
BLOCKNUMBER (0x83)
Encoding:[0x83, RRRR____] (2 bytes)Gas: 2 Get current block number.
TIMESTAMP (0x84)
Encoding:[0x84, RRRR____] (2 bytes)Gas: 2 Get current block timestamp.
GAS (0x85)
Encoding:[0x85, RRRR____] (2 bytes)Gas: 2 Get remaining gas.
Debug (0xF0-0xFF)
LOG (0xF0)
Encoding:[0xF0, RRRR____] (2 bytes)Gas: 2 Log register value for debugging.
Methods
from_byte
Parse a byte as an opcode.Byte to parse
Some(opcode) if valid, None otherwise
instruction_size
Get the number of bytes this instruction consumes.Total instruction size in bytes (including opcode)
Register Encoding Format
Registers are encoded in 4-bit fields (0-15):- Single register:
RRRR____(high nibble) - Two registers:
RRRR_SSSS(packed byte) - Three registers:
DDDD_SSS1, SSS2____(1.5 bytes)