OP_PICK vs OP_ROLL - Key Difference
From TeachMeBitcoin, the free encyclopedia
Reading time: 1 min
18. OP_PICK vs OP_ROLL — Key Difference
Overview
OP_PICK and OP_ROLL are companion opcodes that differ in exactly one fundamental behavior: OP_PICK copies the target item, while OP_ROLL moves it. Understanding this distinction is critical for writing correct Bitcoin scripts.
Side-by-Side Comparison
Starting Stack: [ A, B, C, D ] (D is top)
Push n = 2: [ A, B, C, D, 2 ]
OP_PICK result: [ A, B, C, D, B ]
- B (position 2) is COPIED to top
- Original B remains at its position
- Stack size UNCHANGED (n consumed, copy added)
- Net items: 5 → 5
OP_ROLL result: [ A, C, D, B ]
- B (position 2) is MOVED to top
- Original B is REMOVED from position 2
- Stack COMPACTED
- Net items: 5 → 4
Visualization Table
``` Operation | Effect on Target | Stack Size | Original Preserved?
☕ 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