Skip to content

A Opcode Reference

This appendix accounts for every one of the 256 possible opcode bytes of script version 0. It is a summary: the normative definitions are the rules of Chapter 6, referenced below, and where this table and those rules differ, the rules govern. The table describes the operation performed when an opcode is executed, that is, when it is reached by the program counter in an executing branch; Table A.1 describes how each class of opcode behaves when it is reached in an unexecuted branch and whether it counts toward the limit of 255 operations per script.

A.1 Conventions

Stack effects are written [inputs] → [outputs], listing only the elements an opcode consumes and produces, bottom to top, with the top element last. In the arithmetic, bitwise and comparison opcodes, letters denote numeric operands, which must be minimally encoded script numbers of at most 4 bytes (at most 5 bytes for the lock-time operands, at most 1 byte for the signature type of OP_CHECKSIGALT); see Section 6.7.2. Booleans are pushed as 01 (true) and the empty string (false), and ε denotes the empty string. An opcode that needs more elements than the stack holds fails with ErrInvalidStackOperation. Flag values refer to Table 6.15.

The processing steps common to all opcodes (the checks for disabled and always-illegal opcodes, the operation count, the element size limit and the minimal-push rule) are given in Rule 6.6. Every executed push must be minimal (Rule 6.7).

Table A.1. Opcode classes
ClassWhen executedWhen reached in an unexecuted branchCounts as op
P pushPushes its value; must be minimal.No effect, but data longer than 2048 bytes still fails.no
C conditionalOpens, toggles or closes a block.Still processed: OP_IF/OP_NOTIF open a block without popping; OP_ELSE and OP_ENDIF act as specified.yes
A activePerforms its operation.No effect.yes
G flag-gatedWith its flag: as listed. Without: as class U.No effect.yes
N no-opNo effect, under all flags.No effect.yes
U upgradable no-opNo effect; fails only under the policy flag 0x01.No effect.yes
R reservedFails (ErrReservedOpcode).No effect.yes, except 0x50
I always illegalFails (ErrReservedOpcode).Fails.n/a (fails first)
D disabledFails (ErrDisabledOpcode).Fails.n/a (fails first)

The rule that decides whether an opcode counts toward the operation limit is purely numeric: every opcode whose byte value is greater than 0x60 counts, every other opcode does not. In addition, an executed OP_CHECKMULTISIG(VERIFY) adds its key count 𝑛.

A.2 Map of Byte Values

Table A.2 shows the class of every byte value at a glance. There are 96 push opcodes, 4 conditional opcodes, 70 active opcodes, 6 flag-gated opcodes, 7 no-operations, 61 upgradable no-operations, 9 reserved opcodes, 2 always illegal opcodes and 1 disabled opcode.

Table A.2. Class of every byte value (row: high nibble, column: low nibble)
0123456789abcdef
0PPPPPPPPPPPPPPPP
1PPPPPPPPPPPPPPPP
2PPPPPPPPPPPPPPPP
3PPPPPPPPPPPPPPPP
4PPPPPPPPPPPPPPPP
5RPPPPPPPPPPPPPPP
6PNRCCIICCAAAAAAA
7AAAAAAAAAAAAAAAA
8AAAAAAAAAAAAANNA
9AAAAAAAAAAAAAAAA
aAAAAAAAAAAADAAAA
bUGGUUUUUUUNNNNAA
cGGGGUUUUUUUUUUUU
dUUUUUUUUUUUUUUUU
eUUUUUUUUUUUUUUUU
fUUUUUUUUURRRRRRR

A.3 Opcode Table

Ranges of consecutive bytes with identical behaviour are given in a single row; together the rows of Table A.3 cover all 256 values.

Table A.3. All opcode values
ByteNameClassStack effectSemantics when executed
0x00OP_0P[] → [ε]Push the empty string (OP_FALSE).
0x01–0x4bOP_DATA_1 … OP_DATA_75P[] → [d]Push the next 𝑛 = byte value data bytes. Minimal unless the data is a single byte 01–10 or 81.
0x4cOP_PUSHDATA1P[] → [d]1-byte length 𝑛 follows, then 𝑛 data bytes; push them. Minimal only for 76–255 bytes.
0x4dOP_PUSHDATA2P[] → [d]2-byte LE length 𝑛 follows, then 𝑛 bytes; push them. Minimal only for 256–65535 bytes.
0x4eOP_PUSHDATA4P[] → [d]4-byte LE length 𝑛 follows, then 𝑛 bytes. Never minimal: always fails when executed.
0x4fOP_1NEGATEP[] → [-1]Push 81.
0x50OP_RESERVEDR—Fails if executed (ErrReservedOpcode). Not counted as an operation. Counts as push-only.
0x51–0x60OP_1 … OP_16P[] → [n]Push the number 𝑛 = byte − 0x50. OP_1 is also OP_TRUE.
0x61OP_NOPN[] → []No operation; never discouraged.
0x62OP_VERR—Fails if executed (ErrReservedOpcode).
0x63OP_IFC[x] → []Pop 𝑥 if executing; open a block, disabled if 𝑥 is false (Rule 6.8).
0x64OP_NOTIFC[x] → []As OP_IF with the condition inverted.
0x65OP_VERIFI—Fails whenever reached, even unexecuted (ErrReservedOpcode).
0x66OP_VERNOTIFI—Fails whenever reached, even unexecuted (ErrReservedOpcode).
0x67OP_ELSEC[] → []Toggle execution of the innermost block; fails if no block is open.
0x68OP_ENDIFC[] → []Close the innermost block; fails if no block is open.
0x69OP_VERIFYA[x] → []Fail (ErrVerify) if 𝑥 is false.
0x6aOP_RETURNA—Fail (ErrEarlyReturn).
0x6bOP_TOALTSTACKA[x] → []Move 𝑥 to the alternate stack.
0x6cOP_FROMALTSTACKA[] → [x]Move the top of the alternate stack to the data stack; fails if empty.
0x6dOP_2DROPA[a b] → []Drop two.
0x6eOP_2DUPA[a b] → [a b a b]Duplicate two.
0x6fOP_3DUPA[a b c] → [a b c a b c]Duplicate three.
0x70OP_2OVERA[a b c d] → [a b c d a b]Copy the pair below the top pair.
0x71OP_2ROTA[a b c d e f] → [c d e f a b]Rotate three pairs.
0x72OP_2SWAPA[a b c d] → [c d a b]Swap two pairs.
0x73OP_IFDUPA[x] → [x x] / [x]Duplicate 𝑥 if it is true.
0x74OP_DEPTHA[] → [n]Push the data stack depth (before the push).
0x75OP_DROPA[x] → []Drop.
0x76OP_DUPA[x] → [x x]Duplicate.
0x77OP_NIPA[a b] → [b]Remove the second element.
0x78OP_OVERA[a b] → [a b a]Copy the second element.
0x79OP_PICKA[… n] → [… xₙ]Pop 𝑛 (4 bytes); copy the element 𝑛 below the top; 0≤𝑛< depth.
0x7aOP_ROLLA[… n] → [… xₙ]Pop 𝑛 (4 bytes); move the element 𝑛 below the top to the top.
0x7bOP_ROTA[a b c] → [b c a]Rotate three.
0x7cOP_SWAPA[a b] → [b a]Swap.
0x7dOP_TUCKA[a b] → [b a b]Copy the top below the second.
0x7eOP_CATA[a b] → [a‖b]Concatenate; result ≤2048 bytes (ErrElementTooBig).
0x7fOP_SUBSTRA[s e b] → [s[b:e]]Substring; start index on top; empty 𝑠 gives empty; otherwise 0≤𝑏≤𝑒≤|𝑠| (Rule 6.14).
0x80OP_LEFTA[s n] → [s[0:n]]Left part; 0≤𝑛≤|𝑠| unless 𝑠 empty.
0x81OP_RIGHTA[s n] → [s[n:]]Right part; 0≤𝑛≤|𝑠| unless 𝑠 empty.
0x82OP_SIZEA[x] → [x n]Push |𝑥|; 𝑥 kept.
0x83OP_INVERTA[a] → [~a]Bitwise NOT of int32 𝑎.
0x84OP_ANDA[a b] → [a&b]Bitwise AND of int32 values.
0x85OP_ORA[a b] → [a|b]Bitwise OR of int32 values.
0x86OP_XORA[a b] → [a^b]Bitwise XOR of int32 values.
0x87OP_EQUALA[a b] → [bool]Byte-string equality.
0x88OP_EQUALVERIFYA[a b] → []OP_EQUAL then verify (ErrEqualVerify).
0x89OP_ROTRA[v c] → [r]Rotate uint32(v) right by 𝑐∈[0,31], result as int32.
0x8aOP_ROTLA[v c] → [r]Rotate uint32(v) left by 𝑐∈[0,31], result as int32.
0x8bOP_1ADDA[a] → [a+1]Increment (exact).
0x8cOP_1SUBA[a] → [a-1]Decrement (exact).
0x8dOP_2MULN[] → []No operation (not a multiplication); never discouraged.
0x8eOP_2DIVN[] → []No operation (not a division); never discouraged.
0x8fOP_NEGATEA[a] → [-a]Negate.
0x90OP_ABSA[a] → [|a|]Absolute value.
0x91OP_NOTA[a] → [a=0]1 if 𝑎=0 else 0 (numeric operand).
0x92OP_0NOTEQUALA[a] → [a≠0]0 if 𝑎=0 else 1.
0x93OP_ADDA[a b] → [a+b]Add (exact).
0x94OP_SUBA[a b] → [a-b]Subtract (exact).
0x95OP_MULA[a b] → [a·b]Multiply, wrapping to int32.
0x96OP_DIVA[a b] → [a/b]Truncating division; 𝑏=0 fails (ErrDivideByZero).
0x97OP_MODA[a b] → [a%b]Truncating remainder (sign of 𝑎); 𝑏=0 fails.
0x98OP_LSHIFTA[v c] → [v<<c]int32 left shift, 𝑐∈[0,32]; 𝑐=32 gives 0.
0x99OP_RSHIFTA[v c] → [v>>c]int32 arithmetic right shift, 𝑐∈[0,32].
0x9aOP_BOOLANDA[a b] → [bool]1 if 𝑎≠0 and 𝑏≠0.
0x9bOP_BOOLORA[a b] → [bool]1 if 𝑎≠0 or 𝑏≠0.
0x9cOP_NUMEQUALA[a b] → [bool]1 if 𝑎=𝑏.
0x9dOP_NUMEQUALVERIFYA[a b] → []OP_NUMEQUAL then verify (ErrNumEqualVerify).
0x9eOP_NUMNOTEQUALA[a b] → [bool]1 if 𝑎≠𝑏.
0x9fOP_LESSTHANA[a b] → [bool]1 if 𝑎<𝑏.
0xa0OP_GREATERTHANA[a b] → [bool]1 if 𝑎>𝑏.
0xa1OP_LESSTHANOREQUALA[a b] → [bool]1 if 𝑎≤𝑏.
0xa2OP_GREATERTHANOREQUALA[a b] → [bool]1 if 𝑎≥𝑏.
0xa3OP_MINA[a b] → [min]Smaller of 𝑎, 𝑏.
0xa4OP_MAXA[a b] → [max]Larger of 𝑎, 𝑏.
0xa5OP_WITHINA[x lo hi] → [bool]1 if lo≤𝑥<hi.
0xa6OP_RIPEMD160A[x] → [h]RIPEMD-160.
0xa7OP_SHA1A[x] → [h]SHA-1.
0xa8OP_BLAKE256A[x] → [h]BLAKE-256.
0xa9OP_HASH160A[x] → [h]RIPEMD-160(BLAKE-256(x)).
0xaaOP_HASH256A[x] → [h]BLAKE-256(BLAKE-256(x)).
0xabOP_CODESEPARATORD—Fails whenever reached, even unexecuted (ErrDisabledOpcode).
0xacOP_CHECKSIGA[sig pk] → [bool]ECDSA signature check (Rule 6.27).
0xadOP_CHECKSIGVERIFYA[sig pk] → []OP_CHECKSIG then verify (ErrCheckSigVerify).
0xaeOP_CHECKMULTISIGA[sigs m pks n] → [bool]𝑚-of-𝑛 ECDSA check, no dummy element; adds 𝑛 to the operation count (Rule 6.28).
0xafOP_CHECKMULTISIGVERIFYA[sigs m pks n] → []OP_CHECKMULTISIG then verify.
0xb0OP_NOP1U[] → []Upgradable no-operation.
0xb1OP_CHECKLOCKTIMEVERIFYG[L] → [L]Lock-time check with flag 0x02 (Rule 6.19); else upgradable no-op (OP_NOP2).
0xb2OP_CHECKSEQUENCEVERIFYG[s] → [s]Relative lock-time check with flag 0x04 (Rule 6.20); else upgradable no-op (OP_NOP3).
0xb3–0xb9OP_NOP4 … OP_NOP10U[] → []Upgradable no-operations.
0xbaOP_SSTXN[] → []Stake tag; no operation. Recognized in P2SH detection; forbidden in redeem scripts.
0xbbOP_SSGENN[] → []Stake tag; no operation. Recognized in P2SH detection; forbidden in redeem scripts.
0xbcOP_SSRTXN[] → []Stake tag; no operation. Recognized in P2SH detection; forbidden in redeem scripts.
0xbdOP_SSTXCHANGEN[] → []Stake tag; no operation. Recognized in P2SH detection; forbidden in redeem scripts.
0xbeOP_CHECKSIGALTA[sig pk t] → [bool]Alternative-suite check: 𝑡 = 1 Ed25519, 2 Schnorr; 0 pushes false, others push true (Rule 6.29).
0xbfOP_CHECKSIGALTVERIFYA[sig pk t] → []OP_CHECKSIGALT then verify (ErrCheckSigAltVerify).
0xc0OP_SHA256G[x] → [h]SHA-256 with flag 0x20; else upgradable no-op (OP_UNKNOWN192).
0xc1OP_TADDG[] → []Treasury tag with flag 0x40 (no operation); else upgradable no-op (OP_UNKNOWN193).
0xc2OP_TSPENDG[] → []Treasury tag with flag 0x40; else OP_UNKNOWN194. One signature operation when treasury rules apply.
0xc3OP_TGENG[] → []Treasury tag with flag 0x40; else upgradable no-op (OP_UNKNOWN195).
0xc4–0xf8OP_UNKNOWN196 … OP_UNKNOWN248U[] → []Unassigned; upgradable no-operations.
0xf9OP_INVALID249R—Fails if executed (ErrReservedOpcode).
0xfaOP_SMALLINTEGERR—Fails if executed (ErrReservedOpcode).
0xfbOP_PUBKEYSR—Fails if executed (ErrReservedOpcode).
0xfcOP_UNKNOWN252R—Fails if executed (ErrReservedOpcode).
0xfdOP_PUBKEYHASHR—Fails if executed (ErrReservedOpcode).
0xfeOP_PUBKEYR—Fails if executed (ErrReservedOpcode).
0xffOP_INVALIDOPCODER—Fails if executed (ErrReservedOpcode).

A.4 Remarks

  • Names and aliases. OP_FALSE is 0x00, OP_TRUE is 0x51, OP_NOP2 is 0xb1 and OP_NOP3 is 0xb2. When the corresponding flags are not set, 0xc0–0xc3 are called OP_UNKNOWN192–OP_UNKNOWN195. The names OP_INVALID249, OP_SMALLINTEGER, OP_PUBKEYS, OP_UNKNOWN252, OP_PUBKEYHASH, OP_PUBKEY and OP_INVALIDOPCODE (0xf9–0xff) are inherited labels with no function other than failing when executed.
  • Differences from Bitcoin. OP_CAT, OP_SUBSTR, OP_LEFT, OP_RIGHT, OP_INVERT, OP_AND, OP_OR, OP_XOR, OP_MUL, OP_DIV, OP_MOD, OP_LSHIFT and OP_RSHIFT are enabled with the semantics of Section 6.8; OP_2MUL and OP_2DIV are no-operations; OP_CODESEPARATOR is disabled; 0x89 and 0x8a are the rotations OP_ROTR and OP_ROTL; OP_HASH160 and OP_HASH256 use BLAKE-256; OP_CHECKMULTISIG takes no dummy element; and 0xa8, 0xba–0xc3 are Decred-specific. In particular 0xa8, which is OP_SHA256 in Bitcoin, is OP_BLAKE256 here, and Decred’s OP_SHA256 is 0xc0, available only when its flag is set. OP_INVERT, OP_AND, OP_OR and OP_XOR act on 32-bit numbers, whereas Bitcoin’s original versions acted on byte strings.
  • Parsing. Every byte value parses as a one-byte opcode except 0x01–0x4e, which carry inline data (Rule 6.2). A script must parse completely before any of it executes, so the bytes after an OP_RETURN must still form valid opcodes.