Skip to main content

Module opcodes

Module opcodes 

Source
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_PUSHDATA1
OP_PUSHDATA1 - Push next byte as data length
OP_PUSHDATA2
OP_PUSHDATA2 - Push next 2 bytes (little-endian) as data length
OP_PUSHDATA4
OP_PUSHDATA4 - Push next 4 bytes (little-endian) as data length
OP_RESERVED
OP_RESERVED - Reserved opcode, transaction invalid if present
OP_RESERVED1
OP_RESERVED1 - Reserved opcode
OP_RESERVED2
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_RIPEMD160
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)