OP_2OVER - Copying Second Pair to Top
9. OP_2OVER — Copying Second Pair to Top
Overview
OP_2OVER is the pair-wise analog of OP_OVER. It copies the second pair of items (positions 3 and 4 from the top) onto the top of the stack, preserving the originals. After execution, the stack grows by two items.
Opcode Reference
Opcode: OP_2OVER
Hex: 0x70
Word: 2OVER
Input: x1 x2 x3 x4
Output: x1 x2 x3 x4 x1 x2
Stack Before: [ ..., x1, x2, x3, x4 ]
Stack After: [ ..., x1, x2, x3, x4, x1, x2 ]
Execution Trace
Script: OP_1 OP_2 OP_3 OP_4 OP_2OVER
After pushes: Stack: [ 1, 2, 3, 4 ]
After OP_2OVER: Stack: [ 1, 2, 3, 4, 1, 2 ]
The pair (1, 2) — items at positions 4 and 3 from the top — is copied and placed on top.
Use Case: Paired Value Reuse
OP_2OVER is useful in scripts where a pair of values was pushed early in execution and needs to be referenced again after other values have been pushed:
<nonce_A> <nonce_B> <sig_C> <sig_D>
OP_2OVER
→ Stack: [ <nonce_A>, <nonce_B>, <sig_C>, <sig_D>, <nonce_A>, <nonce_B> ]
Now the nonce pair is available on top for a hash commitment check, while the original copy remains beneath for further processing.
Failure Conditions
- Requires at least 4 items on the stack.
Summary
OP_2OVER enables pair-level non-destructive copying from the second pair position. It is essential in scripts where two-item tuples must be referenced multiple times across distinct verification steps.
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: