Appendix A: Complete Type Code 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 type codes used in ErgoTree serialization12.

Type Code Ranges

Type Code Organization
══════════════════════════════════════════════════════════════════

Range          Usage
─────────────────────────────────────────────────────────────────
0x00           Reserved (invalid)
0x01-0x09      Primitive types (embeddable)
0x0A-0x0B      Reserved
0x0C           Collection type constructor
0x0D-0x17      Reserved
0x18           Nested collection (Coll[Coll[T]])
0x19-0x23      Reserved
0x24           Option type constructor
0x25-0x3B      Reserved
0x3C-0x5F      Pair type constructors
0x60           Tuple type constructor
0x61-0x6A      Object types (non-embeddable)
0x6B-0x6F      Reserved for future object types

Primitive Types (Embeddable)

Embeddable types can be used as element types in collections (Coll[T], Option[T]) and have compact type code encodings. They are "embedded" into composite type codes rather than being serialized separately. For example, Coll[Int] is encoded as 0x0C 0x04 where 0x04 (Int) is embedded directly after 0x0C (Coll).

DecHexTypeSizeZig Type
10x01SBoolean1 bitbool
20x02SByte8 bitsi8
30x03SShort16 bitsi16
40x04SInt32 bitsi32
50x05SLong64 bitsi64
60x06SBigInt256 bitsBigInt256
70x07SGroupElement33 bytesEcp (compressed)
80x08SSigmaPropvariableSigmaBoolean
90x09SUnsignedBigInt256 bitsUnsignedBigInt256

Object Types

DecHexTypeDescription
970x61SAnySupertype of all types
980x62SUnitUnit type (singleton)
990x63SBoxTransaction box
1000x64SAvlTreeAuthenticated dictionary
1010x65SContextExecution context
1020x66SStringString (ErgoScript only)
1030x67STypeVarType variable (internal)
1040x68SHeaderBlock header
1050x69SPreHeaderBlock pre-header
1060x6ASGlobalGlobal object (SigmaDslBuilder)

Type Constructors

DecHexConstructorExampleSerialized As
120x0CSCollColl[Byte]0x0C 0x02
240x18Nested SCollColl[Coll[Int]]0x18 0x04
360x24SOptionOption[Long]0x24 0x05
600x3CPair (first generic)(_, Byte)0x3C 0x02
720x48Pair (second generic)(Int, _)0x48 0x04
840x54Pair (symmetric)(Long, Long)0x54 0x05
960x60STuple(Int, Boolean, ...)0x60 len types...

Zig Type Definition

const TypeCode = enum(u8) {
    // Primitive types
    boolean = 0x01,
    byte = 0x02,
    short = 0x03,
    int = 0x04,
    long = 0x05,
    big_int = 0x06,
    group_element = 0x07,
    sigma_prop = 0x08,
    unsigned_big_int = 0x09,

    // Type constructors
    coll = 0x0C,
    nested_coll = 0x18,
    option = 0x24,
    pair_first = 0x3C,
    pair_second = 0x48,
    pair_symmetric = 0x54,
    tuple = 0x60,

    // Object types
    any = 0x61,
    unit = 0x62,
    box = 0x63,
    avl_tree = 0x64,
    context = 0x65,
    string = 0x66,
    type_var = 0x67,
    header = 0x68,
    pre_header = 0x69,
    global = 0x6A,

    pub fn isPrimitive(self: TypeCode) bool {
        return @intFromEnum(self) >= 0x01 and @intFromEnum(self) <= 0x09;
    }

    pub fn isEmbeddable(self: TypeCode) bool {
        return self.isPrimitive();
    }

    pub fn isNumeric(self: TypeCode) bool {
        return switch (self) {
            .byte, .short, .int, .long, .big_int, .unsigned_big_int => true,
            else => false,
        };
    }
};

Type Serialization

const SType = union(enum) {
    boolean,
    byte,
    short,
    int,
    long,
    big_int,
    group_element,
    sigma_prop,
    unsigned_big_int,
    coll: *const SType,
    option: *const SType,
    tuple: []const SType,
    box,
    avl_tree,
    context,
    header,
    pre_header,
    global,
    unit,
    any,

    pub fn typeCode(self: *const SType) u8 {
        return switch (self.*) {
            .boolean => 0x01,
            .byte => 0x02,
            .short => 0x03,
            .int => 0x04,
            .long => 0x05,
            .big_int => 0x06,
            .group_element => 0x07,
            .sigma_prop => 0x08,
            .unsigned_big_int => 0x09,
            .coll => |elem| blk: {
                if (elem.* == .coll) break :blk 0x18;
                break :blk 0x0C;
            },
            .option => 0x24,
            .tuple => 0x60,
            .box => 0x63,
            .avl_tree => 0x64,
            .context => 0x65,
            .header => 0x68,
            .pre_header => 0x69,
            .global => 0x6A,
            .unit => 0x62,
            .any => 0x61,
        };
    }
};

Encoding Rules

Type Encoding Examples
══════════════════════════════════════════════════════════════════

Simple Types:
  SInt           → [0x04]
  SBoolean       → [0x01]
  SGroupElement  → [0x07]

Collections:
  Coll[Byte]         → [0x0C, 0x02]      (coll + byte)
  Coll[Int]          → [0x0C, 0x04]      (coll + int)
  Coll[Coll[Byte]]   → [0x18, 0x02]      (nested_coll + byte)

Options:
  Option[Int]        → [0x24, 0x04]      (option + int)
  Option[Box]        → [0x24, 0x63]      (option + box)

Tuples (2 elements):
  (Int, Int)         → [0x54, 0x04]      (symmetric + int)
  (Int, Long)        → [0x48, 0x04, 0x05] (pair2 + int + long)
  (Long, Int)        → [0x3C, 0x05, 0x04] (pair1 + long + int)

Tuples (3+ elements):
  (Int, Long, Byte)  → [0x60, 0x03, 0x04, 0x05, 0x02]
                       (tuple + len + int + long + byte)

Constants

const TypeConstants = struct {
    /// First type code for primitive types
    pub const FIRST_PRIMITIVE_TYPE: u8 = 0x01;
    /// Last type code for primitive types
    pub const LAST_PRIMITIVE_TYPE: u8 = 0x09;
    /// Maximum supported type code
    pub const MAX_TYPE_CODE: u8 = 0x6A;
    /// Last data type (can be serialized as data)
    pub const LAST_DATA_TYPE: u8 = 111;
};

Previous: Chapter 31 | Next: Appendix B

1

Scala: SType.scala