TeachMeBitcoin

OP_2OVER - Copying Second Pair to Top

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

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

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.

☕ Help support TeachMeBitcoin

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:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!