Appendix D: Method Reference

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 methods available on each type12.

Method Organization

Method System Architecture
══════════════════════════════════════════════════════════════════

                    ┌────────────────────────┐
                    │    STypeCompanion      │
                    │  type_code: TypeCode   │
                    │  methods: []SMethod    │
                    └──────────┬─────────────┘
                               │
       ┌───────────────────────┼───────────────────────┐
       ▼                       ▼                       ▼
┌──────────────┐       ┌──────────────┐       ┌──────────────┐
│  SNumeric    │       │    SBox      │       │   SColl      │
│  methods.len │       │  methods.len │       │ methods.len  │
│     = 13     │       │     = 10     │       │    = 20+     │
└──────────────┘       └──────────────┘       └──────────────┘

Method Lookup:
─────────────────────────────────────────────────────────────────
  receiver.methodCall(type_code=99, method_id=1)
       │
       ▼
  STypeCompanion::Box.method_by_id(1)
       │
       ▼
  SMethod { name: "value", tpe: Box => Long, cost: 10 }

Zig Method Descriptors

const SMethod = struct {
    name: []const u8,
    method_id: u8,
    tpe: SFunc,
    cost_kind: CostKind,
    min_version: ?ErgoTreeVersion = null,

    pub fn isV6Only(self: *const SMethod) bool {
        return self.min_version != null and
            @intFromEnum(self.min_version.?) >= 3;
    }
};

const SFunc = struct {
    t_dom: []const SType,  // Domain (receiver + args)
    t_range: SType,        // Return type

    pub fn unary(recv: SType, ret: SType) SFunc {
        return .{ .t_dom = &[_]SType{recv}, .t_range = ret };
    }

    pub fn binary(recv: SType, arg: SType, ret: SType) SFunc {
        return .{ .t_dom = &[_]SType{ recv, arg }, .t_range = ret };
    }
};

Numeric Types (SByte, SShort, SInt, SLong)3

IDMethodSignaturev5v6Cost
1toByteT → Byte10
2toShortT → Short10
3toIntT → Int10
4toLongT → Long10
5toBigIntT → BigInt30
6toBytesT → Coll[Byte]-5
7toBitsT → Coll[Boolean]-5
8bitwiseInverseT → T-5
9bitwiseOr(T, T) → T-5
10bitwiseAnd(T, T) → T-5
11bitwiseXor(T, T) → T-5
12shiftLeft(T, Int) → T-5
13shiftRight(T, Int) → T-5

SBigInt4

IDMethodSignaturev5v6Cost
1-5toXxxConversions10-30
6-13bitwiseBitwise ops-5-10
14toUnsignedBigInt → UnsignedBigInt-5
15toUnsignedMod(BigInt, UBI) → UBI-10

SUnsignedBigInt (v6+)5

IDMethodSignatureCost
14modInverse(UBI, UBI) → UBI50
15plusMod(UBI, UBI, UBI) → UBI10
16subtractMod(UBI, UBI, UBI) → UBI10
17multiplyMod(UBI, UBI, UBI) → UBI15
18mod(UBI, UBI) → UBI10
19toSignedUBI → BigInt5

SGroupElement6

IDMethodSignaturev5v6Cost
2getEncodedGE → Coll[Byte]250
3exp(GE, BigInt) → GE900
4multiply(GE, GE) → GE40
5negateGE → GE45
6expUnsigned(GE, UBI) → GE-900

SSigmaProp7

IDMethodSignatureCost
1propBytesSigmaProp → Coll[Byte]35
2isProvenSigmaProp → Boolean10

SBox8

IDMethodSignatureCost
1valueBox → Long1
2propositionBytesBox → Coll[Byte]10
3bytesBox → Coll[Byte]10
4bytesWithoutRefBox → Coll[Byte]10
5idBox → Coll[Byte]10
6creationInfoBox → (Int, Coll[Byte])10
7getReg[T](Box, Int) → Option[T]50
8tokensBox → Coll[(Coll[Byte], Long)]15

Register Access

const BoxMethods = struct {
    // R0-R3: mandatory registers
    pub const R0 = makeRegMethod(0);  // monetary value
    pub const R1 = makeRegMethod(1);  // guard script
    pub const R2 = makeRegMethod(2);  // tokens
    pub const R3 = makeRegMethod(3);  // creation info
    // R4-R9: optional registers
    pub const R4 = makeRegMethod(4);
    pub const R5 = makeRegMethod(5);
    pub const R6 = makeRegMethod(6);
    pub const R7 = makeRegMethod(7);
    pub const R8 = makeRegMethod(8);
    pub const R9 = makeRegMethod(9);

    fn makeRegMethod(comptime idx: u8) SMethod {
        return .{
            .method_id = 7,  // getReg opcode
            .name = "R" ++ &[_]u8{'0' + idx},
            .cost_kind = .{ .fixed = .{ .cost = .{ .value = 50 } } },
        };
    }
};

SAvlTree9

IDMethodSignatureCost
1digestAvlTree → Coll[Byte]15
2enabledOperationsAvlTree → Byte15
3keyLengthAvlTree → Int15
4valueLengthOptAvlTree → Option[Int]15
5isInsertAllowedAvlTree → Boolean15
6isUpdateAllowedAvlTree → Boolean15
7isRemoveAllowedAvlTree → Boolean15
8updateOperations(AvlTree, Byte) → AvlTree20
9contains(AvlTree, key, proof) → Booleandynamic
10get(AvlTree, key, proof) → Option[Coll[Byte]]dynamic
11getMany(AvlTree, keys, proof) → Coll[Option[...]]dynamic
12insert(AvlTree, entries, proof) → Option[AvlTree]dynamic
13update(AvlTree, operations, proof) → Option[AvlTree]dynamic
14remove(AvlTree, keys, proof) → Option[AvlTree]dynamic
15updateDigest(AvlTree, Coll[Byte]) → AvlTree20

SContext10

IDMethodSignatureCost
1dataInputsContext → Coll[Box]15
2headersContext → Coll[Header]15
3preHeaderContext → PreHeader10
4INPUTSContext → Coll[Box]10
5OUTPUTSContext → Coll[Box]10
6HEIGHTContext → Int26
7SELFContext → Box10
8selfBoxIndexContext → Int20
9LastBlockUtxoRootHashContext → AvlTree15
10minerPubKeyContext → Coll[Byte]20
11getVar[T](Context, Byte) → Option[T]dynamic

SHeader11

IDMethodSignatureCost
1idHeader → Coll[Byte]10
2versionHeader → Byte10
3parentIdHeader → Coll[Byte]10
4ADProofsRootHeader → Coll[Byte]10
5stateRootHeader → AvlTree10
6transactionsRootHeader → Coll[Byte]10
7timestampHeader → Long10
8nBitsHeader → Long10
9heightHeader → Int10
10extensionRootHeader → Coll[Byte]10
11minerPkHeader → GroupElement10
12powOnetimePkHeader → GroupElement10
13powNonceHeader → Coll[Byte]10
14powDistanceHeader → BigInt10
15votesHeader → Coll[Byte]10
16checkPowHeader → Boolean (v6+)500

SPreHeader12

IDMethodSignatureCost
1versionPreHeader → Byte10
2parentIdPreHeader → Coll[Byte]10
3timestampPreHeader → Long10
4nBitsPreHeader → Long10
5heightPreHeader → Int10
6minerPkPreHeader → GroupElement10
7votesPreHeader → Coll[Byte]10

SGlobal13

IDMethodSignaturev5v6Cost
1groupGeneratorGlobal → GroupElement10
2xor(Coll[Byte], Coll[Byte]) → Coll[Byte]PerItem
3serialize[T]T → Coll[Byte]-dynamic
4fromBigEndianBytes[T]Coll[Byte] → T-10
5encodeNBitsBigInt → Long-20
6decodeNBitsLong → BigInt-20
7powHit(Int, ...) → BigInt-500

SCollection14

IDMethodSignatureCost
1sizeColl[T] → Int14
2apply(Coll[T], Int) → T14
3getOrElse(Coll[T], Int, T) → Tdynamic
4map[R](Coll[T], T → R) → Coll[R]PerItem(20,1,10)
5exists(Coll[T], T → Bool) → BoolPerItem(20,5,10)
6fold[R](Coll[T], R, (R,T) → R) → RPerItem(20,1,10)
7forall(Coll[T], T → Bool) → BoolPerItem(20,5,10)
8slice(Coll[T], Int, Int) → Coll[T]PerItem(10,2,100)
9filter(Coll[T], T → Bool) → Coll[T]PerItem(20,5,10)
10append(Coll[T], Coll[T]) → Coll[T]PerItem(20,2,100)
14indicesColl[T] → Coll[Int]PerItem(20,2,128)
15flatMap[R](Coll[T], T → Coll[R]) → Coll[R]PerItem(20,5,10)
19patch (v6)(Coll[T], Int, Coll[T], Int) → Coll[T]dynamic
20updated (v6)(Coll[T], Int, T) → Coll[T]20
21updateMany (v6)(Coll[T], Coll[Int], Coll[T]) → Coll[T]PerItem
26indexOf(Coll[T], T, Int) → IntPerItem(20,1,10)
29zip[U](Coll[T], Coll[U]) → Coll[(T,U)]PerItem(10,1,10)
30reverse (v6)Coll[T] → Coll[T]PerItem
31startsWith (v6)(Coll[T], Coll[T]) → BooleanPerItem
32endsWith (v6)(Coll[T], Coll[T]) → BooleanPerItem
33get (v6)(Coll[T], Int) → Option[T]14

SOption15

IDMethodSignatureCost
2isDefinedOption[T] → Boolean10
3getOption[T] → T10
4getOrElse(Option[T], T) → T10
7map[R](Option[T], T → R) → Option[R]dynamic
8filter(Option[T], T → Bool) → Option[T]dynamic

STuple

Tuples support component access by position:

const TupleMethods = struct {
    /// Access tuple component by index (1-based like Scala)
    pub fn component(comptime idx: usize) SMethod {
        return .{
            .name = "_" ++ std.fmt.comptimePrint("{}", .{idx}),
            .method_id = @intCast(idx),
            .cost_kind = .{ .fixed = .{ .cost = .{ .value = 12 } } },
        };
    }
};

// Usage: tuple._1, tuple._2, ... up to tuple._255

Previous: Appendix C | Next: Appendix E

1

Scala: methods.scala

3

Scala: methods.scala (SNumericTypeMethods)

4

Scala: methods.scala (SBigIntMethods)

5

Scala: methods.scala (SUnsignedBigIntMethods)

7

Scala: methods.scala (SSigmaPropMethods)

8

Rust: sbox.rs:29-92

9

Rust: savltree.rs

10

Rust: scontext.rs

11

Rust: sheader.rs

12

Rust: spreheader.rs

13

Rust: sglobal.rs

14

Rust: scoll.rs:22-266

15

Rust: soption.rs