TERM_DEF // MODULE_1_THE_STACK / OP_DUP
OP_DUP
OP_DUP. Duplicate the top stack item.
OP_DUP copies the top item and pushes the copy. The original remains in place. This is used in P2PKH to keep a copy of the public key for OP_CHECKSIG after hash160/">OP_HASH160 has consumed one copy for hashing.
This page sits in the Module 1 — The Stack section — Vocabulary introduced in the The Stack module. Read on for what it is, why it exists, how it works under the hood, and what to watch out for.
OP_DUP copies the top item and pushes the copy. The original remains in place. This is used in P2PKH to keep a copy of the public key for OP_CHECKSIG after hash160/">OP_HASH160 has consumed one copy for hashing.
This page sits in the Module 1 — The Stack section — Vocabulary introduced in the The Stack module. Read on for what it is, why it exists, how it works under the hood, and what to watch out for.
WHAT_OP_DUP_IS
OP_DUP — at a glance
MODULE 1
OP_DUP is a Bitcoin Script opcode in the STACK family. Its stack effect is
x → x x. Duplicate the top stack item. Heavy use in P2PKH. Duplicate the top stack item.OP_DUP copies the top item and pushes the copy. The original remains in place. This is used in P2PKH to keep a copy of the public key for OP_CHECKSIG after OP_HASH160 has consumed one copy for hashing.
Why it exists
DESIGN
OP_DUP exists because A stack-based VM needs explicit, deterministic stack-manipulation primitives so any script's effect on the stack is auditable.
HOW_IT_WORKS
Mechanism
HOW IT WORKS
Every UTXO is locked by a scriptPubKey — the output's locking script. To spend it, you provide a scriptSig (or witness) containing data that satisfies the lock. The node concatenates them, runs the combined script on a stack machine, and accepts the spend if and only if execution finishes with a single truthy value on the stack. OP_DUP contributes a specific stack effect within that process — opcodes either push, pop, copy, hash, branch, or verify, and they do so left-to-right deterministically.
1. The script is parsed into a sequence of opcodes and push-data items.
2. Execution starts with an empty stack and an empty alt-stack.
3. Each opcode runs in order — push opcodes add to the stack, others consume the top items and may push results.
4. When OP_DUP is reached, it performs its specific stack effect (see below).
5. Final state: a single non-zero (truthy) value on top → the spend is authorised. Anything else (empty stack, false, error) → the script fails and the tx is rejected.
WORKED_EXAMPLE
OP_DUP — stack effect + canonical use
EXAMPLE
Opcode : OP_DUP
Family : STACK
Stack effect: x → x x
Behaviour : Duplicate the top stack item. Heavy use in P2PKH.
Open /playground in another tab and search for OP_DUP.
Drag the opcode in, watch the stack visualisation step through it
against any combination of inputs you choose.
KEY_PROPERTIES
FAMILY
Belongs to the STACK family of Script opcodes — siblings share validation rules and historical evolution.
STACK EFFECT
Exactly x → x x. Every full node enforces the same effect, byte-for-byte.
ACTIVE
Active on mainnet today; every spend that uses it is being validated by every full node.
COMMON_PITFALLS
Things that catch people out
PITFALLS
- Opcode semantics are consensus — verify against the latest Bitcoin Core source before relying on any subtle behaviour.
RELATED_CONCEPTS
Other terms from Module 1 — The Stack — click any to read its page:
TERMINOLOGY_INDEX
TERMINOLOGY
OP_DUP
Duplicate the top stack item.
Stack
Last-in, first-out scratch pad the Script VM uses.
LIFO
Last In, First Out — the ordering rule of a stack.
Opcode
A single instruction in a Bitcoin Script program.
Push
Place a value on top of the stack.
Pop
Remove the top value from the stack.
Script
The bytecode program that locks and unlocks Bitcoin.