Skip to main content

Module opcodes

Module opcodes 

Source
Expand description

Bitcoin Script opcode constant definitions. Bitcoin script opcode definitions.

All standard opcodes from OP_0 (0x00) through OP_INVALIDOPCODE (0xff). Includes opcode-to-string and string-to-opcode mappings for ASM output, plus utility functions for classifying opcodes.

Constants§

OP_0
Push an empty byte array (false/zero) onto the stack.
OP_0NOTEQUAL
Push 0 if the top item is 0, push 1 otherwise.
OP_1
Push the number 1 onto the stack.
OP_2
Push the number 2 onto the stack.
OP_3
Push the number 3 onto the stack.
OP_4
Push the number 4 onto the stack.
OP_5
Push the number 5 onto the stack.
OP_6
Push the number 6 onto the stack.
OP_7
Push the number 7 onto the stack.
OP_8
Push the number 8 onto the stack.
OP_9
Push the number 9 onto the stack.
OP_1ADD
Add 1 to the top stack item.
OP_1NEGATE
Push the number -1 onto the stack.
OP_1SUB
Subtract 1 from the top stack item.
OP_2DIV
Divide the top stack item by 2 (disabled).
OP_2DROP
Remove the top two stack items.
OP_2DUP
Duplicate the top two stack items.
OP_2MUL
Multiply the top stack item by 2 (disabled).
OP_2OVER
Copy the pair of items two spaces back to the front of the stack.
OP_2ROT
Move the fifth and sixth items to the top of the stack.
OP_2SWAP
Swap the top two pairs of items on the stack.
OP_3DUP
Duplicate the top three stack items.
OP_10
Push the number 10 onto the stack.
OP_11
Push the number 11 onto the stack.
OP_12
Push the number 12 onto the stack.
OP_13
Push the number 13 onto the stack.
OP_14
Push the number 14 onto the stack.
OP_15
Push the number 15 onto the stack.
OP_16
Push the number 16 onto the stack.
OP_ABS
Replace the top stack item with its absolute value.
OP_ADD
Pop two items, push their sum.
OP_AND
Bitwise AND of the top two stack items.
OP_BASE
Base value for small integer opcodes (OP_1 through OP_16 = OP_BASE + N).
OP_BIN2NUM
Convert a byte array to a numeric value.
OP_BOOLAND
Push 1 if both top two items are non-zero, 0 otherwise.
OP_BOOLOR
Push 1 if either of the top two items is non-zero, 0 otherwise.
OP_CAT
Concatenate the top two stack items.
OP_CHECKLOCKTIMEVERIFY
Verify that the transaction locktime is at least the given value (BTC only, NOP in BSV).
OP_CHECKMULTISIG
Pop N public keys and M signatures, push 1 if all signatures are valid, 0 otherwise.
OP_CHECKMULTISIGVERIFY
Same as OP_CHECKMULTISIG, then OP_VERIFY. Marks transaction invalid if check fails.
OP_CHECKSEQUENCEVERIFY
Verify that the input sequence number is at least the given value (BTC only, NOP in BSV).
OP_CHECKSIG
Pop a public key and signature, push 1 if the signature is valid, 0 otherwise.
OP_CHECKSIGVERIFY
Same as OP_CHECKSIG, then OP_VERIFY. Marks transaction invalid if signature check fails.
OP_CODESEPARATOR
Mark the beginning of signature-checked code.
OP_DATA_1
Push the next 1 byte onto the stack.
OP_DATA_2
Push the next 2 bytes onto the stack.
OP_DATA_3
Push the next 3 bytes onto the stack.
OP_DATA_4
Push the next 4 bytes onto the stack.
OP_DATA_5
Push the next 5 bytes onto the stack.
OP_DATA_6
Push the next 6 bytes onto the stack.
OP_DATA_7
Push the next 7 bytes onto the stack.
OP_DATA_8
Push the next 8 bytes onto the stack.
OP_DATA_9
Push the next 9 bytes onto the stack.
OP_DATA_10
Push the next 10 bytes onto the stack.
OP_DATA_11
Push the next 11 bytes onto the stack.
OP_DATA_12
Push the next 12 bytes onto the stack.
OP_DATA_13
Push the next 13 bytes onto the stack.
OP_DATA_14
Push the next 14 bytes onto the stack.
OP_DATA_15
Push the next 15 bytes onto the stack.
OP_DATA_16
Push the next 16 bytes onto the stack.
OP_DATA_17
Push the next 17 bytes onto the stack.
OP_DATA_18
Push the next 18 bytes onto the stack.
OP_DATA_19
Push the next 19 bytes onto the stack.
OP_DATA_20
Push the next 20 bytes onto the stack.
OP_DATA_21
Push the next 21 bytes onto the stack.
OP_DATA_22
Push the next 22 bytes onto the stack.
OP_DATA_23
Push the next 23 bytes onto the stack.
OP_DATA_24
Push the next 24 bytes onto the stack.
OP_DATA_25
Push the next 25 bytes onto the stack.
OP_DATA_26
Push the next 26 bytes onto the stack.
OP_DATA_27
Push the next 27 bytes onto the stack.
OP_DATA_28
Push the next 28 bytes onto the stack.
OP_DATA_29
Push the next 29 bytes onto the stack.
OP_DATA_30
Push the next 30 bytes onto the stack.
OP_DATA_31
Push the next 31 bytes onto the stack.
OP_DATA_32
Push the next 32 bytes onto the stack.
OP_DATA_33
Push the next 33 bytes onto the stack.
OP_DATA_34
Push the next 34 bytes onto the stack.
OP_DATA_35
Push the next 35 bytes onto the stack.
OP_DATA_36
Push the next 36 bytes onto the stack.
OP_DATA_37
Push the next 37 bytes onto the stack.
OP_DATA_38
Push the next 38 bytes onto the stack.
OP_DATA_39
Push the next 39 bytes onto the stack.
OP_DATA_40
Push the next 40 bytes onto the stack.
OP_DATA_41
Push the next 41 bytes onto the stack.
OP_DATA_42
Push the next 42 bytes onto the stack.
OP_DATA_43
Push the next 43 bytes onto the stack.
OP_DATA_44
Push the next 44 bytes onto the stack.
OP_DATA_45
Push the next 45 bytes onto the stack.
OP_DATA_46
Push the next 46 bytes onto the stack.
OP_DATA_47
Push the next 47 bytes onto the stack.
OP_DATA_48
Push the next 48 bytes onto the stack.
OP_DATA_49
Push the next 49 bytes onto the stack.
OP_DATA_50
Push the next 50 bytes onto the stack.
OP_DATA_51
Push the next 51 bytes onto the stack.
OP_DATA_52
Push the next 52 bytes onto the stack.
OP_DATA_53
Push the next 53 bytes onto the stack.
OP_DATA_54
Push the next 54 bytes onto the stack.
OP_DATA_55
Push the next 55 bytes onto the stack.
OP_DATA_56
Push the next 56 bytes onto the stack.
OP_DATA_57
Push the next 57 bytes onto the stack.
OP_DATA_58
Push the next 58 bytes onto the stack.
OP_DATA_59
Push the next 59 bytes onto the stack.
OP_DATA_60
Push the next 60 bytes onto the stack.
OP_DATA_61
Push the next 61 bytes onto the stack.
OP_DATA_62
Push the next 62 bytes onto the stack.
OP_DATA_63
Push the next 63 bytes onto the stack.
OP_DATA_64
Push the next 64 bytes onto the stack.
OP_DATA_65
Push the next 65 bytes onto the stack.
OP_DATA_66
Push the next 66 bytes onto the stack.
OP_DATA_67
Push the next 67 bytes onto the stack.
OP_DATA_68
Push the next 68 bytes onto the stack.
OP_DATA_69
Push the next 69 bytes onto the stack.
OP_DATA_70
Push the next 70 bytes onto the stack.
OP_DATA_71
Push the next 71 bytes onto the stack.
OP_DATA_72
Push the next 72 bytes onto the stack.
OP_DATA_73
Push the next 73 bytes onto the stack.
OP_DATA_74
Push the next 74 bytes onto the stack.
OP_DATA_75
Push the next 75 bytes onto the stack.
OP_DEPTH
Push the number of items on the stack onto the stack.
OP_DIV
Pop two items, push the integer quotient of the second divided by the top.
OP_DROP
Remove the top stack item.
OP_DUP
Duplicate the top stack item.
OP_ELSE
Execute the following statements if the preceding OP_IF/OP_NOTIF was not executed.
OP_ENDIF
End an if/else block.
OP_EQUAL
Push 1 if the top two stack items are exactly equal, 0 otherwise.
OP_EQUALVERIFY
Same as OP_EQUAL, then OP_VERIFY. Marks transaction invalid if not equal.
OP_FALSE
Push an empty byte array (false/zero) onto the stack. Alias for OP_0.
OP_FROMALTSTACK
Move the top item from the alt stack to the main stack.
OP_GREATERTHAN
Push 1 if the second item is greater than the top item, 0 otherwise.
OP_GREATERTHANOREQUAL
Push 1 if the second item is greater than or equal to the top item, 0 otherwise.
OP_HASH160
Hash the top item with SHA-256 then RIPEMD-160 (Bitcoin address hash).
OP_HASH256
Hash the top item with double SHA-256 (Bitcoin transaction hash).
OP_IF
Execute the following statements if the top stack value is true (non-zero).
OP_IFDUP
Duplicate the top stack item if it is non-zero.
OP_INVALIDOPCODE
Invalid opcode that always causes script failure.
OP_INVERT
Flip all bits of the top stack item.
OP_LESSTHAN
Push 1 if the second item is less than the top item, 0 otherwise.
OP_LESSTHANOREQUAL
Push 1 if the second item is less than or equal to the top item, 0 otherwise.
OP_LSHIFT
Left-shift the second item by the number of bits given by the top item.
OP_MAX
Push the larger of the top two stack items.
OP_MIN
Push the smaller of the top two stack items.
OP_MOD
Pop two items, push the remainder of the second divided by the top.
OP_MUL
Pop two items, push their product.
OP_NEGATE
Negate the top stack item (flip its sign).
OP_NIP
Remove the second-to-top stack item.
OP_NOP
Do nothing.
OP_NOP1
No operation (reserved for future soft-fork upgrades).
OP_NOP2
No operation (reserved for future soft-fork upgrades). Alias for OP_CHECKLOCKTIMEVERIFY in BTC.
OP_NOP3
No operation (reserved for future soft-fork upgrades). Alias for OP_CHECKSEQUENCEVERIFY in BTC.
OP_NOP4
No operation (reserved for future soft-fork upgrades).
OP_NOP5
No operation (reserved for future soft-fork upgrades).
OP_NOP6
No operation (reserved for future soft-fork upgrades).
OP_NOP7
No operation (reserved for future soft-fork upgrades).
OP_NOP8
No operation (reserved for future soft-fork upgrades).
OP_NOP9
No operation (reserved for future soft-fork upgrades).
OP_NOP10
No operation (reserved for future soft-fork upgrades).
OP_NOT
Push 1 if the top item is 0, push 0 otherwise.
OP_NOTIF
Execute the following statements if the top stack value is false (zero).
OP_NUM2BIN
Convert the top numeric value to a byte array of the specified length.
OP_NUMEQUAL
Push 1 if the top two items are numerically equal, 0 otherwise.
OP_NUMEQUALVERIFY
Same as OP_NUMEQUAL, then OP_VERIFY. Marks transaction invalid if not equal.
OP_NUMNOTEQUAL
Push 1 if the top two items are not numerically equal, 0 otherwise.
OP_OR
Bitwise OR of the top two stack items.
OP_OVER
Copy the second-to-top stack item to the top.
OP_PICK
Copy the item N positions back in the stack to the top.
OP_PUBKEY
Internal pseudo-opcode representing a public key (used in template matching).
OP_PUBKEYHASH
Internal pseudo-opcode representing a public key hash (used in template matching).
OP_PUBKEYS
Internal pseudo-opcode representing multiple public keys (used in template matching).
OP_PUSHDATA1
Read the next 1 byte as a length N, then push the next N bytes onto the stack.
OP_PUSHDATA2
Read the next 2 bytes as a little-endian length N, then push the next N bytes onto the stack.
OP_PUSHDATA4
Read the next 4 bytes as a little-endian length N, then push the next N bytes onto the stack.
OP_RESERVED
Reserved opcode. Transaction is invalid if executed.
OP_RESERVED1
Reserved opcode. Transaction is invalid if executed.
OP_RESERVED2
Reserved opcode. Transaction is invalid if executed.
OP_RETURN
Mark the transaction output as unspendable (provably prunable).
OP_RIPEMD160
Hash the top item with RIPEMD-160.
OP_ROLL
Move the item N positions back in the stack to the top.
OP_ROT
Rotate the top three items on the stack (third item moves to top).
OP_RSHIFT
Right-shift the second item by the number of bits given by the top item.
OP_SHA1
Hash the top item with SHA-1.
OP_SHA256
Hash the top item with SHA-256.
OP_SIZE
Push the byte length of the top stack item (without popping it).
OP_SMALLINTEGER
Internal pseudo-opcode representing a small integer (used in template matching).
OP_SPLIT
Split the second-to-top item at position given by the top item.
OP_SUB
Pop two items, push the second minus the top.
OP_SWAP
Swap the top two stack items.
OP_TOALTSTACK
Move the top stack item to the alt stack.
OP_TRUE
Push the number 1 onto the stack. Alias for OP_1.
OP_TUCK
Copy the top stack item and insert it below the second-to-top item.
OP_UNKNOWN186
Unknown opcode 186 (0xba). Undefined behavior.
OP_UNKNOWN187
Unknown opcode 187 (0xbb). Undefined behavior.
OP_UNKNOWN188
Unknown opcode 188 (0xbc). Undefined behavior.
OP_UNKNOWN189
Unknown opcode 189 (0xbd). Undefined behavior.
OP_UNKNOWN190
Unknown opcode 190 (0xbe). Undefined behavior.
OP_UNKNOWN191
Unknown opcode 191 (0xbf). Undefined behavior.
OP_UNKNOWN192
Unknown opcode 192 (0xc0). Undefined behavior.
OP_UNKNOWN193
Unknown opcode 193 (0xc1). Undefined behavior.
OP_UNKNOWN194
Unknown opcode 194 (0xc2). Undefined behavior.
OP_UNKNOWN195
Unknown opcode 195 (0xc3). Undefined behavior.
OP_UNKNOWN196
Unknown opcode 196 (0xc4). Undefined behavior.
OP_UNKNOWN197
Unknown opcode 197 (0xc5). Undefined behavior.
OP_UNKNOWN198
Unknown opcode 198 (0xc6). Undefined behavior.
OP_UNKNOWN199
Unknown opcode 199 (0xc7). Undefined behavior.
OP_UNKNOWN200
Unknown opcode 200 (0xc8). Undefined behavior.
OP_UNKNOWN201
Unknown opcode 201 (0xc9). Undefined behavior.
OP_UNKNOWN202
Unknown opcode 202 (0xca). Undefined behavior.
OP_UNKNOWN203
Unknown opcode 203 (0xcb). Undefined behavior.
OP_UNKNOWN204
Unknown opcode 204 (0xcc). Undefined behavior.
OP_UNKNOWN205
Unknown opcode 205 (0xcd). Undefined behavior.
OP_UNKNOWN206
Unknown opcode 206 (0xce). Undefined behavior.
OP_UNKNOWN207
Unknown opcode 207 (0xcf). Undefined behavior.
OP_UNKNOWN208
Unknown opcode 208 (0xd0). Undefined behavior.
OP_UNKNOWN209
Unknown opcode 209 (0xd1). Undefined behavior.
OP_UNKNOWN210
Unknown opcode 210 (0xd2). Undefined behavior.
OP_UNKNOWN211
Unknown opcode 211 (0xd3). Undefined behavior.
OP_UNKNOWN212
Unknown opcode 212 (0xd4). Undefined behavior.
OP_UNKNOWN213
Unknown opcode 213 (0xd5). Undefined behavior.
OP_UNKNOWN214
Unknown opcode 214 (0xd6). Undefined behavior.
OP_UNKNOWN215
Unknown opcode 215 (0xd7). Undefined behavior.
OP_UNKNOWN216
Unknown opcode 216 (0xd8). Undefined behavior.
OP_UNKNOWN217
Unknown opcode 217 (0xd9). Undefined behavior.
OP_UNKNOWN218
Unknown opcode 218 (0xda). Undefined behavior.
OP_UNKNOWN219
Unknown opcode 219 (0xdb). Undefined behavior.
OP_UNKNOWN220
Unknown opcode 220 (0xdc). Undefined behavior.
OP_UNKNOWN221
Unknown opcode 221 (0xdd). Undefined behavior.
OP_UNKNOWN222
Unknown opcode 222 (0xde). Undefined behavior.
OP_UNKNOWN223
Unknown opcode 223 (0xdf). Undefined behavior.
OP_UNKNOWN224
Unknown opcode 224 (0xe0). Undefined behavior.
OP_UNKNOWN225
Unknown opcode 225 (0xe1). Undefined behavior.
OP_UNKNOWN226
Unknown opcode 226 (0xe2). Undefined behavior.
OP_UNKNOWN227
Unknown opcode 227 (0xe3). Undefined behavior.
OP_UNKNOWN228
Unknown opcode 228 (0xe4). Undefined behavior.
OP_UNKNOWN229
Unknown opcode 229 (0xe5). Undefined behavior.
OP_UNKNOWN230
Unknown opcode 230 (0xe6). Undefined behavior.
OP_UNKNOWN231
Unknown opcode 231 (0xe7). Undefined behavior.
OP_UNKNOWN232
Unknown opcode 232 (0xe8). Undefined behavior.
OP_UNKNOWN233
Unknown opcode 233 (0xe9). Undefined behavior.
OP_UNKNOWN234
Unknown opcode 234 (0xea). Undefined behavior.
OP_UNKNOWN235
Unknown opcode 235 (0xeb). Undefined behavior.
OP_UNKNOWN236
Unknown opcode 236 (0xec). Undefined behavior.
OP_UNKNOWN237
Unknown opcode 237 (0xed). Undefined behavior.
OP_UNKNOWN238
Unknown opcode 238 (0xee). Undefined behavior.
OP_UNKNOWN239
Unknown opcode 239 (0xef). Undefined behavior.
OP_UNKNOWN240
Unknown opcode 240 (0xf0). Undefined behavior.
OP_UNKNOWN241
Unknown opcode 241 (0xf1). Undefined behavior.
OP_UNKNOWN242
Unknown opcode 242 (0xf2). Undefined behavior.
OP_UNKNOWN243
Unknown opcode 243 (0xf3). Undefined behavior.
OP_UNKNOWN244
Unknown opcode 244 (0xf4). Undefined behavior.
OP_UNKNOWN245
Unknown opcode 245 (0xf5). Undefined behavior.
OP_UNKNOWN246
Unknown opcode 246 (0xf6). Undefined behavior.
OP_UNKNOWN247
Unknown opcode 247 (0xf7). Undefined behavior.
OP_UNKNOWN248
Unknown opcode 248 (0xf8). Undefined behavior.
OP_UNKNOWN249
Unknown opcode 249 (0xf9). Undefined behavior.
OP_UNKNOWN252
Unknown opcode 252 (0xfc). Undefined behavior.
OP_VER
Reserved opcode. Transaction is invalid if executed.
OP_VERIF
Reserved opcode. Transaction is invalid even if not executed.
OP_VERIFY
Mark the transaction as invalid if the top stack value is false.
OP_VERNOTIF
Reserved opcode. Transaction is invalid even if not executed.
OP_WITHIN
Push 1 if the third item is within the range [second, top), 0 otherwise.
OP_XOR
Bitwise XOR of the top two stack items.

Functions§

is_push_data
Check if an opcode is a push data opcode (OP_DATA_1..OP_PUSHDATA4).
is_small_int_op
Check if an opcode represents a small integer (OP_0 or OP_1..OP_16).
opcode_to_string
Convert an opcode byte value to its string representation for ASM output.
string_to_opcode
Convert an opcode name string to its byte value.