Opcodes are the fundamental building blocks of Bitcoin's scripting language, defining conditions for spending transactions. Each opcode represents a specific instruction executed within Bitcoin's virtual machine, enabling complex scripting capabilities. Opcodes are executed sequentially to validate transactions against scriptPubKey and scriptSig, determining if inputs fulfill the conditions for spending outputs.
The scripting language employs opcodes to perform operations like data manipulation, conditional execution, cryptographic verification, and arithmetic computations. This limited set ensures predictable script evaluation, mitigating risks from malicious or indefinitely looping scripts.
Opcodes enable smart contracts and multi-signature wallets within Bitcoin. Conditional logic opcodes (e.g., OP_IF, OP_NOTIF) and cryptographic operations (e.g., OP_CHECKSIG, OP_CHECKMULTISIG) enforce specific spending conditions, such as requiring multiple signatures or locking funds until a certain block height or timestamp (via OP_CHECKLOCKTIMEVERIFY and OP_CHECKSEQUENCEVERIFY).
OpcodeDescriptionFunction
0OP_0, OP_FALSEPush false
76OP_PUSHDATA1Push data
77OP_PUSHDATA2Push data
78OP_PUSHDATA4Push data
79OP_1NEGATEPush -1
80-96OP_1-OP_16, OP_TRUEPush 1-16
97OP_NOPNo operation
99OP_IFIf conditional
100OP_NOTIFIf not conditional
103OP_ELSEElse conditional
104OP_ENDIFEnd if
105OP_VERIFYVerify condition
106OP_RETURNTerminate script
107-108OP_TOALTSTACK, OP_FROMALTSTACKStack transfer
109OP_2DROPDrop 2
110OP_2DUPDuplicate 2
111OP_3DUPDuplicate 3
112OP_2OVERCopy 2nd pair
113OP_2ROTRotate top 3 twice
114OP_2SWAPSwap top 2 pairs
115OP_IFDUPDuplicate if not 0
116OP_DEPTHStack size
117OP_DROPRemove top
118OP_DUPDuplicate top
119OP_NIPRemove 2nd
120OP_OVERCopy 2nd
121OP_PICKNth item
122OP_ROLLMove Nth top
123OP_ROTRotate top 3
124OP_SWAPSwap top 2
125OP_TUCKMove 3rd to top
130OP_SIZESize of top item
135OP_EQUALEquality check
136OP_EQUALVERIFYVerify equal
139OP_1ADDAdd 1
140OP_1SUBSubtract 1
143OP_NEGATENegate
144OP_ABSAbsolute value
145OP_NOTNot zero
146OP_0NOTEQUALNot equal to 0
147-148OP_ADD, OP_SUBArithmetic
149-154DisabledDisabled
155-158OP_BOOLAND, OP_BOOLOR, OP_NUMEQUAL, OP_NUMEQUALVERIFYBoolean logic
159-160OP_NUMNOTEQUAL, OP_LESSTHANComparison
161-162OP_GREATERTHAN, OP_LESSTHANOREQUALComparison
163-164OP_GREATERTHANOREQUAL, OP_MINMinimum/Maximum
165-166OP_MAX, OP_WITHINRange check
167-168OP_RIPEMD160, OP_SHA1Hashing
169OP_SHA256SHA-256
170OP_HASH160RIPEMD-160+SHA-256
171OP_HASH256SHA-256x2
172-175OP_CHECKSIG, OP_CHECKSIGVERIFY, OP_CHECKMULTISIGSignature check
176-177OP_CHECKMULTISIGVERIFYMultisig verify
178-181OP_NOP1-OP_NOP4No operation
182-185OP_CHECKLOCKTIMEVERIFY, OP_CHECKSEQUENCEVERIFYTiming checks
186-189OP_NOP6-OP_NOP9No operation
190-193OP_NOP10No operation
This is also a good site to learn about opcodes:
reply
Thank you! I just spent a long time looking at that site.
reply
Very good resource ! Thanks.
where is OP_SATS_BACK ?
reply
lol, thanks for the sats back!
reply