Protocol specification · Source at 93ba635c

Lotus VM specification

Status: active development draft, summarizing and indexing the Lotus virtual machine defined across P03: VM semantics, P05: Resources and parameters, Script and wallet ABI, and Deferred checks (C12a). For the high-level contract language and compiler targeting this VM, see Lotus language and compiler.

Execution model

The Lotus VM is a deterministic, statically bounded stack machine designed for high-throughput UTXO validation. It is a clean-slate V2 virtual machine—not Bitcoin Script with legacy quirks.

Values and numeric arithmetic

Value kind Representation Rules
Byte strings 0..MAX_ELEMENT_BYTES raw bytes General stack items (hashes, public keys, signatures, templates, serialized records).
Signed integer N(x) 16..1024 bytes, little-endian two's complement 128-bit baseline (MIN_NUMERIC_BYTES = 16) up to 8,192-bit big-int (MAX_NUMERIC_BYTES = 1024). Constants, counts, indices, values, and LOG push 16-byte int128.
Unsigned integer U(x) 0..1024 bytes, little-endian unsigned Used by ADDCARRY, SUBCARRY, and MUL128_WIDE; shorter operands zero-pad to W = max(16, len(a), len(b)).
Canonical Boolean Exact 16-byte N(0) or N(1) All Boolean consumers (IF, NOTIF, VERIFY, NOT, BOOLAND, BOOLOR, COND_BREAK) reject any other byte string. Comparisons and signature checks always produce canonical Booleans.

Arithmetic is checked:

Bytecode framing and structured control flow

Instruction set overview

The canonical byte allocation lives in tools/opcodes.json and is defined instruction-by-instruction in P03: VM semantics.

Hex range Group Representative instructions
00–5d Literals and pushes ZERO, PUSH_1..PUSH_75, PUSHDATA, NEGATIVE_ONE, ONE..SIXTEEN
60–6d Control flow NOP, IF, NOTIF, ELSE, ENDIF, VERIFY, RETURN, ENUMERATE, ENDENUMERATE, BREAK, EMITLOG (sim-only), COND_BREAK
70–81 Stack TOALTSTACK, FROMALTSTACK, DEPTH, DROP, DUP, NIP, OVER, PICK, ROLL, ROT, SWAP, TUCK, 2DROP, 2DUP, 3DUP, 2OVER, 2ROT, 2SWAP
88–94 Byte strings CAT, SPLIT, NUM2BIN, BIN2NUM, SIZE, INVERT, AND, OR, XOR, EQUAL, EQUALVERIFY, LESSSWAP, RAWLEFTBITSHIFT
98–b4 Arithmetic 1ADD, 1SUB, NEGATE, ABS, NOT, 0NOTEQUAL, ADD, SUB, MUL, DIV, MOD, MULPOW2, BOOLAND, BOOLOR, NUMEQUAL, NUMEQUALVERIFY, NUMNOTEQUAL, LESSTHAN, GREATERTHAN, LESSTHANOREQUAL, GREATERTHANOREQUAL, MIN, MAX, WITHIN, ADDCARRY, SUBCARRY, MUL128_WIDE, LOG, SQRT
b8–c3 Cryptography and commitments SHA256, HASH256, BLAKE3, CHECKSIG, CHECKSIGVERIFY, CHECKDATASIG, LEAFHASH, NODEHASH, MERKLEROOT_SORTED, MERKLEROOT_INDEXED, SIGHASH, STATEHASH
c8–cf Transaction TXVERSION, TXINPUTCOUNT, TXOUTPUTCOUNT, TXMINTCOUNT, TXLOCKTIME, TXLOCKKIND, TXID, CHAINID
d0–df Inputs and resolved coins INPUTINDEX, INPUTFLAGS, OUTPOINTTXID, OUTPOINTINDEX, INPUTSEQUENCENUMBER, INPUTPATHINDEX, UTXOVALUE, UTXOTOKENID, UTXOBRANCHCOUNT, UTXOBRANCH, UTXOPATHCOUNT, UTXOPATH, UTXOOUTPUT, UTXOREQUIRESBRANCH, UTXOFLAGS, INPUTWITNESSARG
e0–ef Outputs, assets, and state OUTPUTFLAGS, OUTPUTVALUE, OUTPUTTOKENID, OUTPUTBRANCHCOUNT, OUTPUTBRANCH, OUTPUTPATHCOUNT, OUTPUTPATH, OUTPUTRECORD, OUTPUTREQUIRESBRANCH, OUTPUTEXCLUSIVEBRANCH, OUTPUTCONTINUESBRANCH, ENFORCEOUTPUT, TXTOKENBALANCE, STATEVERIFY, UTXOSTATEROOT, OUTPUTSTATEROOT
f0–f6, ff Invocation, locks, and extensions ACTIVEBYTECODE, INVOCATIONKIND, BRANCHROOT, CHECKLOCKTIMEVERIFY, CHECKSEQUENCEVERIFY, ACTIVEBRANCHINDEX, ACTIVEWITNESSINDEX, EXT2

Introspection, covenants, and contract state

Lotus provides first-class covenant and state primitives directly in the VM without requiring scripts to manually parse transaction bytes:

Static resource bounds and cost units (P05)

Because loops are statically bounded (<= 256 iterations, nesting depth <= 2), the node computes an exact static Cost Unit (cu) upper bound in one pass over the decoded AST before execution. There is no runtime "out of gas" revert that forfeits fees.

Extension points