Expand description
Bitcoin Script Opcode Constants
Complete set of opcode constants for Bitcoin script execution. All opcodes are defined with their hex values and descriptive comments.
Reference: BIP specifications and script/opcode definitions
Constants§
- DER_
SIGNATURE_ PREFIX - DER signature prefix (0x30 = SEQUENCE tag in DER encoding)
- OP_0
- OP_0 / OP_FALSE - Push empty array
- OP_
0NOTEQUAL - OP_0NOTEQUAL - Returns 0 if the input is 0. 1 otherwise
- OP_1
- OP_1 / OP_TRUE - Push 1 onto stack
- OP_2
- OP_2 - Push 2 onto stack
- OP_3
- OP_3 - Push 3 onto stack
- OP_4
- OP_4 - Push 4 onto stack
- OP_5
- OP_5 - Push 5 onto stack
- OP_6
- OP_6 - Push 6 onto stack
- OP_7
- OP_7 - Push 7 onto stack
- OP_8
- OP_8 - Push 8 onto stack
- OP_9
- OP_9 - Push 9 onto stack
- OP_1ADD
- OP_1ADD - 1 is added to the input
- OP_
1NEGATE - OP_1NEGATE - Push -1 onto stack
- OP_1SUB
- OP_1SUB - 1 is subtracted from the input
- OP_
1_ RANGE_ END - OP_
1_ RANGE_ START - Range for OP_1 through OP_16
- OP_2DIV
- OP_2DIV - The input is divided by 2 (disabled)
- OP_
2DROP - OP_2DROP - Removes the top two stack items
- OP_2DUP
- OP_2DUP - Duplicates the top two stack items
- OP_2MUL
- OP_2MUL - The input is multiplied by 2 (disabled)
- OP_
2OVER - OP_2OVER - Copies the pair of items two spaces back in the stack to the front
- OP_2ROT
- OP_2ROT - The fifth and sixth items back are moved to the top of the stack
- OP_
2SWAP - OP_2SWAP - Swaps the top two pairs of items
- OP_3DUP
- OP_3DUP - Duplicates the top three stack items
- OP_10
- OP_10 - Push 10 onto stack
- OP_11
- OP_11 - Push 11 onto stack
- OP_12
- OP_12 - Push 12 onto stack
- OP_13
- OP_13 - Push 13 onto stack
- OP_14
- OP_14 - Push 14 onto stack
- OP_15
- OP_15 - Push 15 onto stack
- OP_16
- OP_16 - Push 16 onto stack
- OP_ABS
- OP_ABS - The input is made positive
- OP_ADD
- OP_ADD - a is added to b
- OP_AND
- OP_AND - Boolean AND between each bit in the inputs (disabled)
- OP_
BOOLAND - OP_BOOLAND - If both a and b are not 0, the output is 1. Otherwise 0
- OP_
BOOLOR - OP_BOOLOR - If a or b is not 0, the output is 1. Otherwise 0
- OP_CAT
- OP_CAT - Concatenates two strings (disabled)
- OP_
CHECKLOCKTIMEVERIFY - OP_CHECKLOCKTIMEVERIFY (BIP65) - Marks transaction as invalid if the top stack item is greater than the transaction’s nLockTime field, otherwise script evaluation continues as if an OP_NOP was executed
- OP_
CHECKMULTISIG - OP_CHECKMULTISIG - Compares the first signature against each public key until it finds an ECDSA match. Starting with the subsequent public key, it compares the second signature against each remaining public key until it finds an ECDSA match. The process is repeated until all signatures have been checked or not enough public keys remain to produce a successful result. All signatures need to match a public key. Because public keys are not checked again if they fail any signature comparison, signatures must be placed in the scriptSig using the same order as their corresponding public keys were placed in the scriptPubKey or script. If all signatures are valid, 1 is returned, 0 otherwise
- OP_
CHECKMULTISIGVERIFY - OP_CHECKMULTISIGVERIFY - Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward
- OP_
CHECKSEQUENCEVERIFY - OP_CHECKSEQUENCEVERIFY (BIP112) - Marks transaction as invalid if the relative lock time of the input (enforced by BIP 68 with nSequence) is not equal to or longer than the value of the top stack item
- OP_
CHECKSIG - OP_CHECKSIG - The entire transaction’s outputs, inputs, and script (from the most recently-executed OP_CODESEPARATOR to the end) are hashed. The signature used must match the transaction and the public key or script verification fails
- OP_
CHECKSIGADD - OP_CHECKSIGADD (BIP342) - Tapscript opcode for signature aggregation
- OP_
CHECKSIGFROMSTACK - OP_CHECKSIGFROMSTACK (BIP348) - Verifies a BIP340 Schnorr signature against an arbitrary message
- OP_
CHECKSIGVERIFY - OP_CHECKSIGVERIFY - Same as OP_CHECKSIG, but OP_VERIFY is executed afterward
- OP_
CHECKTEMPLATEVERIFY - OP_CHECKTEMPLATEVERIFY (BIP119) - Verifies that the transaction matches a template hash
- OP_
CODESEPARATOR - OP_CODESEPARATOR - All of the signature checking words will only match signatures to the data after the most recently-executed OP_CODESEPARATOR
- OP_
DEPTH - OP_DEPTH - Puts the number of stack items onto the stack
- OP_
DISABLED_ BITWISE_ RANGE_ END - OP_
DISABLED_ BITWISE_ RANGE_ START - Range for disabled opcodes (bitwise operations)
- OP_
DISABLED_ NUMERIC_ RANGE_ END - OP_
DISABLED_ NUMERIC_ RANGE_ START - Range for disabled opcodes (numeric operations)
- OP_
DISABLED_ STRING_ RANGE_ END - OP_
DISABLED_ STRING_ RANGE_ START - Range for disabled opcodes (string operations)
- OP_DIV
- OP_DIV - a is divided by b (disabled)
- OP_DROP
- OP_DROP - Removes the top stack item
- OP_DUP
- OP_DUP - Duplicates the top stack item
- OP_ELSE
- OP_ELSE - If the preceding OP_IF or OP_NOTIF was not executed, these statements are
- OP_
ENDIF - OP_ENDIF - Ends an OP_IF/OP_NOTIF/OP_ELSE block
- OP_
EQUAL - OP_EQUAL - Returns 1 if the inputs are exactly equal, 0 otherwise
- OP_
EQUALVERIFY - OP_EQUALVERIFY - Same as OP_EQUAL, but runs OP_VERIFY afterward
- OP_
FALSE - OP_
FROMALTSTACK - OP_FROMALTSTACK - Puts the input onto the top of the main stack. Removes it from the alt stack
- OP_
GREATERTHAN - OP_GREATERTHAN - Returns 1 if a is greater than b, 0 otherwise
- OP_
GREATERTHANOREQUAL - OP_GREATERTHANOREQUAL - Returns 1 if a is greater than or equal to b, 0 otherwise
- OP_
HASH160 - OP_HASH160 - The input is hashed twice: first with SHA-256 and then with RIPEMD-160
- OP_
HASH256 - OP_HASH256 - The input is hashed two times with SHA-256
- OP_IF
- OP_IF - If top stack value is true, statements are executed
- OP_
IFDUP - OP_IFDUP - If the top stack value is not 0, duplicate it
- OP_
INVERT - OP_INVERT - Flips all of the bits in the input (disabled)
- OP_LEFT
- OP_LEFT - Keeps only characters left of the specified point in a string (disabled)
- OP_
LESSTHAN - OP_LESSTHAN - Returns 1 if a is less than b, 0 otherwise
- OP_
LESSTHANOREQUAL - OP_LESSTHANOREQUAL - Returns 1 if a is less than or equal to b, 0 otherwise
- OP_
LSHIFT - OP_LSHIFT - Shifts a left b bits, preserving sign (disabled)
- OP_MAX
- OP_MAX - Returns the larger of a and b
- OP_MIN
- OP_MIN - Returns the smaller of a and b
- OP_MOD
- OP_MOD - Returns the remainder after dividing a by b (disabled)
- OP_MUL
- OP_MUL - a is multiplied by b (disabled)
- OP_
NEGATE - OP_NEGATE - The sign of the input is flipped
- OP_NIP
- OP_NIP - Removes the second-to-top stack item
- OP_NOP
- OP_NOP - No operation
- OP_NOP1
- OP_NOP1 - Reserved for future use (was OP_EVAL, disabled)
- OP_NOP2
- OP_NOP3
- OP_NOP4
- OP_NOP5
- OP_NOP5 - Reserved for future use
- OP_NOP6
- OP_NOP6 - Reserved for future use
- OP_NOP7
- OP_NOP7 - Reserved for future use
- OP_NOP8
- OP_NOP8 - Reserved for future use
- OP_NOP9
- OP_NOP9 - Reserved for future use
- OP_
NOP10 - OP_NOP10 - Reserved for future use
- OP_
NOP_ RANGE_ END - OP_
NOP_ RANGE_ START - Range for OP_NOP opcodes (0xb0 - 0xb9)
- OP_NOT
- OP_NOT - If the input is 0 or 1, it is flipped. Otherwise the output is 0
- OP_
NOTIF - OP_NOTIF - If top stack value is false, statements are executed
- OP_
NUMEQUAL - OP_NUMEQUAL - Returns 1 if the numbers are equal, 0 otherwise
- OP_
NUMEQUALVERIFY - OP_NUMEQUALVERIFY - Same as OP_NUMEQUAL, but runs OP_VERIFY afterward
- OP_
NUMNOTEQUAL - OP_NUMNOTEQUAL - Returns 1 if the numbers are not equal, 0 otherwise
- OP_
N_ BASE - Base value for OP_1 through OP_16 (OP_1 = 0x50 + 1 = 0x51)
- OP_OR
- OP_OR - Boolean OR between each bit in the inputs (disabled)
- OP_OVER
- OP_OVER - Copies the second-to-top stack item to the top
- OP_PICK
- OP_PICK - The item n back in the stack is copied to the top
- OP_
PUSHDAT A1 - OP_PUSHDATA1 - Push next byte as data length
- OP_
PUSHDAT A2 - OP_PUSHDATA2 - Push next 2 bytes (little-endian) as data length
- OP_
PUSHDAT A4 - OP_PUSHDATA4 - Push next 4 bytes (little-endian) as data length
- OP_
RESERVED - OP_RESERVED - Reserved opcode, transaction invalid if present
- OP_
RESERVE D1 - OP_RESERVED1 - Reserved opcode
- OP_
RESERVE D2 - OP_RESERVED2 - Reserved opcode
- OP_
RETURN - OP_RETURN - Marks transaction as invalid
- OP_
RIGHT - OP_RIGHT - Keeps only characters right of the specified point in a string (disabled)
- OP_
RIPEM D160 - OP_RIPEMD160 - The input is hashed using RIPEMD-160
- OP_ROLL
- OP_ROLL - The item n back in the stack is moved to the top
- OP_ROT
- OP_ROT - The top three items on the stack are rotated to the left
- OP_
RSHIFT - OP_RSHIFT - Shifts a right b bits, preserving sign (disabled)
- OP_SHA1
- OP_SHA1 - The input is hashed using SHA-1
- OP_
SHA256 - OP_SHA256 - The input is hashed using SHA-256
- OP_SIZE
- OP_SIZE - Pushes the string length of the top element of the stack (without popping it)
- OP_SUB
- OP_SUB - b is subtracted from a
- OP_
SUBSTR - OP_SUBSTR - Returns a section of a string (disabled)
- OP_SWAP
- OP_SWAP - The top two items on the stack are swapped
- OP_
TOALTSTACK - OP_TOALTSTACK - Puts the input onto the top of the alt stack. Removes it from the main stack
- OP_TRUE
- OP_TUCK
- OP_TUCK - The item at the top of the stack is copied and inserted before the second-to-top item
- OP_VER
- OP_VER - Reserved opcode, disabled
- OP_
VERIF - OP_VERIF - Reserved opcode, disabled
- OP_
VERIFY - OP_VERIFY - Marks transaction as invalid if top stack value is not true
- OP_
VERNOTIF - OP_VERNOTIF - Reserved opcode, disabled
- OP_
WITHIN - OP_WITHIN - Returns 1 if x is within the specified range (left-inclusive), 0 otherwise
- OP_XOR
- OP_XOR - Boolean exclusive OR between each bit in the inputs (disabled)
- PUSH_
1_ BYTE - Push 1 byte (direct push; opcodes 0x01-0x4b are push N bytes)
- PUSH_
20_ BYTES - Push 20 bytes (used in P2WPKH: OP_0 0x14 <20-byte-hash>)
- PUSH_
32_ BYTES - Push 32 bytes (used in P2WSH and P2TR: OP_0/OP_1 0x20 <32-byte-hash>)
- PUSH_
33_ BYTES - Push 33 bytes (used in P2PK compressed pubkey: 0x21 <33-byte-pubkey>)
- PUSH_
36_ BYTES - Push 36 bytes (used in tests / OP_RETURN outputs)
- PUSH_
65_ BYTES - Push 65 bytes (used in P2PK uncompressed pubkey: 0x41 <65-byte-pubkey>)
- VARINT_
1BYTE_ MAX - Maximum value for 1-byte varint encoding (< 0xfd)
- VARINT_
2BYTE_ PREFIX - Prefix for 2-byte varint encoding (0xfd + 2 bytes)
- VARINT_
4BYTE_ PREFIX - Prefix for 4-byte varint encoding (0xfe + 4 bytes)
- VARINT_
8BYTE_ PREFIX - Prefix for 8-byte varint encoding (0xff + 8 bytes)