Bitcoin Script 101 (4): Step‑by‑Step P2PKH Walkthrough
Walk through a P2PKH example step by step and watch the stack evolve.
Bitcoin Script 101 (4): Step‑by‑Step P2PKH Walkthrough
This post walks through a classic P2PKH example so the “script + stack execution” model becomes concrete.
1) Locking Script (scriptPubKey)
OP_DUP OP_HASH160 <PubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
Meaning:
- Duplicate the public key
- Hash and compare to the address hash
- Verify the signature if the hash matches
2) Unlocking Script (scriptSig)
<sig> <pubkey>
Meaning: provide signature and public key to prove ownership.
3) Concatenated Execution (Conceptual Steps)
Order: unlocking script first, then locking script.
Initial stack: empty
- Push
<sig> - Push
<pubkey> OP_DUPduplicates the pubkeyOP_HASH160hashes the pubkey- Push
<PubKeyHash> OP_EQUALVERIFYcompares hashes, fails if not equalOP_CHECKSIGverifies signature with the pubkey
If the signature matches the transaction, the stack ends with true and the input is valid.
4) Summary
P2PKH’s core logic is simple:
“Give me a signature + pubkey → I verify you own the private key.”
Once this is clear, you can read P2SH, multisig, and Taproot scripts more easily.
That’s the four‑part BTC Script 101 series. If you want, I can continue with multisig, timelocks (CLTV/CSV), and Taproot script paths.
Next: Back to Part 1 — Stack Model and Core Concepts