P2PK ScriptPubKey Structure
P2PK ScriptPubKey Structure
The beauty of P2PK lies in its simplicity. It is the most straightforward implementation of a "Smart Contract" in Bitcoin. It uses only two components: a piece of data (the public key) and one opcode.
1. The Locking Script (ScriptPubKey)
The script that "locks" the output looks like this:
[Public Key Bytes] OP_CHECKSIG
-
Public Key: Usually a 65-byte uncompressed key (starting with
04) or a 33-byte compressed key (starting with02or03). -
OP_CHECKSIG: The instruction that tells the Bitcoin Virtual Machine to verify a signature against the provided public key.
2. The Unlocking Script (ScriptSig)
To spend a P2PK output, the owner only needs to provide one thing in their input:
[Signature]
- They don't need to provide the public key in the ScriptSig because it is already provided in the ScriptPubKey.
3. The Execution Logic
When a node verifies the transaction, it combines the two scripts:
[Signature] [Public Key Bytes] OP_CHECKSIG
-
The
Signatureis pushed onto the stack. -
The
Public Keyis pushed onto the stack. -
OP_CHECKSIGpops both items, checks if the signature is valid for that public key, and pushes1(Success) or0(Failure) back onto the stack.
4. Raw Hex Example
A typical P2PK ScriptPubKey in raw hex would look like this:
41 04ae6a19...[65 bytes of key]... ac
-
41: The push-data opcode (65 bytes in decimal). -
04...: The uncompressed public key. -
ac: The hex code forOP_CHECKSIG.
| Component | Opcode / Value | Length |
|---|---|---|
| Push Data | 0x41 (or 0x21) |
1 Byte |
| Public Key | The Raw Key | 33/65 Bytes |
| Operation | 0xac (OP_CHECKSIG) |
1 Byte |
In the next section, we will discuss Quantum Security and the difference between P2PK and P2PKH.
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: