Appendix B: Complete Opcode Table

PRE-ALPHA WARNING: This is a pre-alpha version of The Sigma Book. Content may be incomplete, inaccurate, or subject to change. Do not use as a source of truth. For authoritative information, consult the official repositories:

Complete reference for all operation codes used in ErgoTree serialization12.

Opcode Ranges

Opcode Space Organization
══════════════════════════════════════════════════════════════════

Range           Usage                           Encoding
─────────────────────────────────────────────────────────────────
0x00            Reserved (invalid)              -
0x01-0x6F       Data types (constants)          Type code directly
0x70            LastConstantCode boundary       112
0x71-0xFF       Operations                      LastConstantCode + shift

Operation Categories:
─────────────────────────────────────────────────────────────────
0x71-0x79       Variables & references          ValUse, ConstPlaceholder
0x7A-0x7E       Type conversions               Upcast, Downcast
0x7F-0x8C       Constants & tuples             True, False, Tuple
0x8F-0x98       Relations & logic              Lt, Gt, Eq, And, Or
0x99-0xA2       Arithmetic                     Plus, Minus, Multiply
0xA3-0xAC       Context access                 HEIGHT, INPUTS, OUTPUTS
0xAD-0xB8       Collection operations          Map, Filter, Fold
0xC1-0xC7       Box extraction                 ExtractAmount, ExtractId
0xCB-0xD5       Crypto & serialization         Blake2b, ProveDlog
0xD6-0xE7       Blocks & functions             ValDef, FuncValue, Apply
0xEA-0xEB       Sigma operations               SigmaAnd, SigmaOr
0xEC-0xFF       Bitwise & misc                 BitOr, BitAnd, XorOf

Zig Opcode Definition

const OpCode = enum(u8) {
    // Constants region: 0x01-0x70 (type codes)
    // Operations start at LAST_CONSTANT_CODE + 1 = 113

    // Variable references
    tagged_variable = 0x71,      // Context variable by ID
    val_use = 0x72,              // Reference to ValDef binding
    constant_placeholder = 0x73, // Segregated constant reference
    subst_constants = 0x74,      // Substitute constants in tree

    // Type conversions
    long_to_byte_array = 0x7A,
    byte_array_to_bigint = 0x7B,
    byte_array_to_long = 0x7C,
    downcast = 0x7D,
    upcast = 0x7E,

    // Primitive constants
    true_const = 0x7F,
    false_const = 0x80,
    unit_constant = 0x81,
    group_generator = 0x82,

    // Collection & tuple construction
    concrete_collection = 0x83,
    concrete_collection_bool = 0x85,
    tuple = 0x86,
    select_1 = 0x87,
    select_2 = 0x88,
    select_3 = 0x89,
    select_4 = 0x8A,
    select_5 = 0x8B,
    select_field = 0x8C,

    // Relational operations
    lt = 0x8F,
    le = 0x90,
    gt = 0x91,
    ge = 0x92,
    eq = 0x93,
    neq = 0x94,

    // Control flow & logic
    if_op = 0x95,
    and_op = 0x96,
    or_op = 0x97,
    atleast = 0x98,

    // Arithmetic
    minus = 0x99,
    plus = 0x9A,
    xor = 0x9B,
    multiply = 0x9C,
    division = 0x9D,
    modulo = 0x9E,
    exponentiate = 0x9F,
    multiply_group = 0xA0,
    min = 0xA1,
    max = 0xA2,

    // Context access
    height = 0xA3,
    inputs = 0xA4,
    outputs = 0xA5,
    last_block_utxo_root_hash = 0xA6,
    self_box = 0xA7,
    miner_pubkey = 0xAC,

    // Collection operations
    map_collection = 0xAD,
    exists = 0xAE,
    forall = 0xAF,
    fold = 0xB0,
    size_of = 0xB1,
    by_index = 0xB2,
    append = 0xB3,
    slice = 0xB4,
    filter = 0xB5,
    avl_tree = 0xB6,
    avl_tree_get = 0xB7,
    flat_map = 0xB8,

    // Box extraction
    extract_amount = 0xC1,
    extract_script_bytes = 0xC2,
    extract_bytes = 0xC3,
    extract_bytes_with_no_ref = 0xC4,
    extract_id = 0xC5,
    extract_register_as = 0xC6,
    extract_creation_info = 0xC7,

    // Cryptographic operations
    calc_blake2b256 = 0xCB,
    calc_sha256 = 0xCC,
    prove_dlog = 0xCD,
    prove_diffie_hellman_tuple = 0xCE,
    sigma_prop_is_proven = 0xCF,
    sigma_prop_bytes = 0xD0,
    bool_to_sigma_prop = 0xD1,
    trivial_prop_false = 0xD2,
    trivial_prop_true = 0xD3,

    // Deserialization
    deserialize_context = 0xD4,
    deserialize_register = 0xD5,

    // Block & function definitions
    val_def = 0xD6,
    fun_def = 0xD7,
    block_value = 0xD8,
    func_value = 0xD9,
    func_apply = 0xDA,
    property_call = 0xDB,
    method_call = 0xDC,
    global = 0xDD,

    // Option operations
    some_value = 0xDE,
    none_value = 0xDF,
    get_var = 0xE3,
    option_get = 0xE4,
    option_get_or_else = 0xE5,
    option_is_defined = 0xE6,

    // Modular arithmetic (deprecated in v5+)
    mod_q = 0xE7,
    plus_mod_q = 0xE8,
    minus_mod_q = 0xE9,

    // Sigma operations
    sigma_and = 0xEA,
    sigma_or = 0xEB,

    // Binary operations
    bin_or = 0xEC,
    bin_and = 0xED,
    decode_point = 0xEE,
    logical_not = 0xEF,
    negation = 0xF0,

    // Bitwise operations
    bit_inversion = 0xF1,
    bit_or = 0xF2,
    bit_and = 0xF3,
    bin_xor = 0xF4,
    bit_xor = 0xF5,
    bit_shift_right = 0xF6,
    bit_shift_left = 0xF7,
    bit_shift_right_zeroed = 0xF8,

    // Collection bitwise operations
    coll_shift_right = 0xF9,
    coll_shift_left = 0xFA,
    coll_shift_right_zeroed = 0xFB,
    coll_rotate_left = 0xFC,
    coll_rotate_right = 0xFD,

    // Misc
    context = 0xFE,
    xor_of = 0xFF,

    pub fn isConstant(code: u8) bool {
        return code >= 0x01 and code <= 0x70;
    }

    pub fn isOperation(code: u8) bool {
        return code > 0x70;
    }

    pub fn fromShift(shift: u8) OpCode {
        return @enumFromInt(0x70 + shift);
    }
};

Variable & Reference Operations

HexDecimalOperationDescription
0x71113TaggedVariableReference context variable by ID
0x72114ValUseUse value defined by ValDef
0x73115ConstantPlaceholderReference segregated constant
0x74116SubstConstantsSubstitute constants in tree

Type Conversion Operations

HexDecimalOperationDescription
0x7A122LongToByteArrayLong → Coll[Byte] (big-endian)
0x7B123ByteArrayToBigIntColl[Byte] → BigInt
0x7C124ByteArrayToLongColl[Byte] → Long
0x7D125DowncastNumeric downcast (may overflow)
0x7E126UpcastNumeric upcast (always safe)

Constants & Tuples

HexDecimalOperationDescription
0x7F127TrueBoolean true constant
0x80128FalseBoolean false constant
0x81129UnitConstantUnit () value
0x82130GroupGeneratorEC generator point G
0x83131ConcreteCollectionColl construction
0x85133ConcreteCollectionBoolOptimized Coll[Boolean]
0x86134TupleTuple construction
0x87-0x8B135-139Select1-5Tuple element access
0x8C140SelectFieldSelect by field index

Relational & Logic Operations

HexDecimalOperationDescription
0x8F143LtLess than (<)
0x90144LeLess or equal (≤)
0x91145GtGreater than (>)
0x92146GeGreater or equal (≥)
0x93147EqEqual (==)
0x94148NeqNot equal (≠)
0x95149IfIf-then-else
0x96150AndLogical AND (&&)
0x97151OrLogical OR (||)
0x98152AtLeastk-of-n threshold

Arithmetic Operations

HexDecimalOperationDescription
0x99153MinusSubtraction
0x9A154PlusAddition
0x9B155XorByte-array XOR
0x9C156MultiplyMultiplication
0x9D157DivisionInteger division
0x9E158ModuloRemainder
0x9F159ExponentiateBigInt exponentiation
0xA0160MultiplyGroupEC point multiplication
0xA1161MinMinimum
0xA2162MaxMaximum

Context Access Operations

HexDecimalOperationDescription
0xA3163HeightCurrent block height
0xA4164InputsTransaction inputs (INPUTS)
0xA5165OutputsTransaction outputs (OUTPUTS)
0xA6166LastBlockUtxoRootHashUTXO tree root hash
0xA7167SelfCurrent box (SELF)
0xAC172MinerPubkeyMiner's public key
0xFE254ContextContext object

Collection Operations

HexDecimalOperationDescription
0xAD173MapCollectionTransform elements
0xAE174ExistsAny element matches
0xAF175ForAllAll elements match
0xB0176FoldReduce to single value
0xB1177SizeOfCollection length
0xB2178ByIndexElement at index
0xB3179AppendConcatenate collections
0xB4180SliceExtract sub-collection
0xB5181FilterKeep matching elements
0xB6182AvlTreeAVL tree construction
0xB7183AvlTreeGetAVL tree lookup
0xB8184FlatMapMap and flatten

Box Extraction Operations

HexDecimalOperationDescription
0xC1193ExtractAmountBox.value (nanoErgs)
0xC2194ExtractScriptBytesBox.propositionBytes
0xC3195ExtractBytesBox.bytes (full)
0xC4196ExtractBytesWithNoRefBox.bytesWithoutRef
0xC5197ExtractIdBox.id (32 bytes)
0xC6198ExtractRegisterAsBox.Rx[T]
0xC7199ExtractCreationInfoBox.creationInfo

Cryptographic Operations

HexDecimalOperationDescription
0xCB203CalcBlake2b256Blake2b256 hash
0xCC204CalcSha256SHA-256 hash
0xCD205ProveDlogDLog proposition
0xCE206ProveDHTupleDHT proposition
0xCF207SigmaPropIsProvenCheck proven
0xD0208SigmaPropBytesSerialize SigmaProp
0xD1209BoolToSigmaPropBool → SigmaProp
0xD2210TrivialPropFalseAlways false
0xD3211TrivialPropTrueAlways true
0xEE238DecodePointBytes → GroupElement

Block & Function Operations

HexDecimalOperationDescription
0xD4212DeserializeContextDeserialize from context
0xD5213DeserializeRegisterDeserialize from register
0xD6214ValDefDefine value binding
0xD7215FunDefDefine function
0xD8216BlockValueBlock expression { }
0xD9217FuncValueLambda expression
0xDA218FuncApplyApply function
0xDB219PropertyCallProperty access
0xDC220MethodCallMethod invocation
0xDD221GlobalGlobal object

Option Operations

HexDecimalOperationDescription
0xDE222SomeValueSome(x) construction
0xDF223NoneValueNone construction
0xE3227GetVarGet context variable
0xE4228OptionGetOption.get (may fail)
0xE5229OptionGetOrElseOption.getOrElse
0xE6230OptionIsDefinedOption.isDefined

Sigma Operations

HexDecimalOperationDescription
0xEA234SigmaAndSigma AND (∧)
0xEB235SigmaOrSigma OR (∨)

Bitwise Operations (v6+)

HexDecimalOperationDescription
0xEF239LogicalNotBoolean NOT (!)
0xF0240NegationNumeric negation (-x)
0xF1241BitInversionBitwise NOT (~)
0xF2242BitOrBitwise OR (|)
0xF3243BitAndBitwise AND (&)
0xF4244BinXorBinary XOR
0xF5245BitXorBitwise XOR (^)
0xF6246BitShiftRightArithmetic right shift (>>)
0xF7247BitShiftLeftLeft shift (<<)
0xF8248BitShiftRightZeroedLogical right shift (>>>)

Collection Bitwise Operations (v6+)

HexDecimalOperationDescription
0xF9249CollShiftRightCollection shift right
0xFA250CollShiftLeftCollection shift left
0xFB251CollShiftRightZeroedCollection logical shift right
0xFC252CollRotateLeftCollection rotate left
0xFD253CollRotateRightCollection rotate right
0xFF255XorOfXOR of collection elements

Opcode Parsing

const OpCodeParser = struct {
    /// Parse opcode from byte, determining if constant or operation
    pub fn parse(byte: u8) ParseResult {
        if (byte == 0) return .invalid;
        if (byte <= 0x70) return .{ .constant = byte };
        return .{ .operation = @enumFromInt(byte) };
    }

    /// Check if opcode requires additional data
    pub fn hasPayload(op: OpCode) bool {
        return switch (op) {
            .val_use,
            .constant_placeholder,
            .tagged_variable,
            .extract_register_as,
            .by_index,
            .select_field,
            .method_call,
            .property_call,
            => true,
            else => false,
        };
    }

    const ParseResult = union(enum) {
        invalid,
        constant: u8,
        operation: OpCode,
    };
};

Constants

const OpCodeConstants = struct {
    /// First valid data type code
    pub const FIRST_DATA_TYPE: u8 = 0x01;
    /// Last data type code
    pub const LAST_DATA_TYPE: u8 = 111; // 0x6F
    /// Boundary between constants and operations
    pub const LAST_CONSTANT_CODE: u8 = 112; // 0x70
    /// First operation code
    pub const FIRST_OP_CODE: u8 = 113; // 0x71
    /// Maximum opcode value
    pub const MAX_OP_CODE: u8 = 255; // 0xFF
};

Previous: Appendix A | Next: Appendix C

1

Scala: OpCodes.scala