OP_2DROP - Removing Two Stack Items
2. OP_2DROP — Removing Two Stack Items
Overview
OP_2DROP extends the concept of OP_DROP by popping two items off the top of the stack simultaneously. Rather than executing OP_DROP twice, OP_2DROP provides a single opcode that achieves the same result, saving one byte in the script.
Opcode Reference
Opcode: OP_2DROP
Hex: 0x6d
Word: 2DROP
Input: x1 x2
Output: (nothing)
Stack Before: [ ..., x1, x2 ]
Stack After: [ ... ]
Here, x2 is the top of the stack and x1 is directly beneath it. Both are removed.
Execution Trace
Script: OP_1 OP_2 OP_3 OP_2DROP
Step 1 — OP_1: Stack: [ 1 ]
Step 2 — OP_2: Stack: [ 1, 2 ]
Step 3 — OP_3: Stack: [ 1, 2, 3 ]
Step 4 — OP_2DROP: Stack: [ 1 ] ← (2 and 3 are removed)
Practical Use Cases
OP_2DROP appears in scripts where two related values are pushed and used together — such as a signature and a public key in multisig-like constructs — but where the result of their combined verification leaves artifacts on the stack that need to be cleaned up.
Another common pattern is in script templates that use dual-branch logic:
<value_A> <value_B> OP_2DROP
This is sometimes used in covenant scripts and channel state scripts in Lightning Network implementations where intermediate values from prior computation must be discarded before the script proceeds to the final validation step.
Difference Between OP_DROP and OP_2DROP
OP_DROP → Removes 1 item → 1 opcode byte (0x75)
OP_2DROP → Removes 2 items → 1 opcode byte (0x6d)
Cost efficiency: OP_2DROP is more efficient when two items must be dropped.
Using OP_DROP twice:
OP_DROP OP_DROP → 2 bytes
Using OP_2DROP:
OP_2DROP → 1 byte
In Bitcoin, every byte in a script has a cost, so OP_2DROP is the preferred idiom when two items need to be removed.
Failure Conditions
-
If there are fewer than 2 items on the stack,
OP_2DROPcauses the script to fail. -
The interpreter strictly enforces stack depth checks before execution.
Example in a Real Script Pattern
A pattern used in some atomic swap constructs:
OP_SHA256 <hash> OP_EQUALVERIFY ← verify secret
OP_2DUP ← duplicate for later use
OP_CHECKSIGVERIFY ← verify first sig
OP_2DROP ← clean up duplicated items
OP_CHECKSIG ← final check
The OP_2DROP here cleans up the duplicated pair once partial verification is complete.
Summary
OP_2DROP is the efficient two-item discard opcode. It is used in situations where paired data items are pushed together and need to be removed together, offering a single-byte solution to what would otherwise require two OP_DROP instructions.
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: