P2TR ScriptPubKey Structure
P2TR ScriptPubKey Structure
The Taproot locking script is the pinnacle of minimalist design. It doesn't contain hashes or complex opcodes; it simply presents a single public key and tells the validator which version of the rules to apply.
1. The Locking Script (ScriptPubKey)
A P2TR script is exactly 34 bytes long:
51 20 [32-Byte Tweaked Public Key]
-
0x51: This is the opcode for OP_1. It signals that this output uses Witness Version 1.
-
0x20: The push-data opcode for 32 bytes (hex
0x20). -
[32-Byte Public Key]: Known as the Output Key (Q).
2. Why 32 bytes instead of 33?
Legacy and SegWit public keys are 33 bytes (1 byte prefix + 32 byte X-coordinate).
-
Taproot uses Schnorr Signatures, which only require the X-coordinate.
-
The 'parity' of the Y-coordinate is handled by the Schnorr math, allowing us to drop 1 byte from every public key on the blockchain.
3. The "Tweaked" Key
The 32-byte key in the script is not just a standard public key. It is a Tweaked Key (Q).
Q = P + h(P, m)G
-
P: The "Internal Key" (the base public key).
-
m: The root of a Merkle tree containing hidden scripts.
-
h: A cryptographic hash. This math allows the single key
Qto "commit" to an entire tree of scripts without revealing any of them.
4. No Hashing
Notice that unlike P2WPKH or P2WSH, Taproot does not store a hash of the key. It stores the Public Key itself.
-
This is safe because the public key is already a 32-byte value.
-
It saves the step of hashing during validation, making Taproot spends slightly more efficient for nodes to process.
| Attribute | P2WSH (V0) | P2TR (V1) |
|---|---|---|
| Witness Version | 0x00 |
0x51 (OP_1) |
| Data Length | 32 Bytes | 32 Bytes |
| Data Type | Hash of Script | The Tweaked Public Key |
| Key Type | ECDSA (33b) | Schnorr (32b) |
In the next section, we will explore the Key Path vs. Script Path spending mechanisms.
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: