Transaction Structure
Overview
P2TR transactions can be spent using either the key path or the script path, each with different witness structures.
Key Path Spend
Key path spending is the simplest and most efficient way to spend a P2TR output. It requires only a single Schnorr signature created with the tweaked private key.
Script Path Spend
Script path spending allows funds to be spent by satisfying a script committed in the Merkle tree. This method is used when key path spending is not possible or when alternative spending conditions must be exercised, such as timelocks, recovery paths, or fallback multisig arrangements. A script path spend requires the witness to include the script inputs, the script itself, and a control block containing the internal public key and Merkle proof.
Output (Locking Script - ScriptPubKey)
The ScriptPubKey for P2TR consists of the witness version and the 32-byte tweaked public key.
OP_1 # Indicates witness version 1.
OP_PUSHBYTES_32 # Pushes the next 32 bytes onto the stack.
a5b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8091a2b3c4d5e6f7a8b9c0d1e2f3a4 # Tweaked public key.
# Hex value: 5120a5b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8091a2b3c4d5e6f7a8b9c0d1e2f3a4The ScriptPubKey for P2TR is identical regardless of whether the address will be spent via key path or script path. The differentiation occurs at spend time by examining the witness data.
Input (Unlocking Script - ScriptSig)
For native P2TR, the ScriptSig is empty.
All signature and script data is stored in the witness field.
Witness Data
For detailed information about witness data structure, refer to the P2TR MAST - Merklized Alternative Script Trees.
Key Path Spend
For a key path spend, the witness contains only the Schnorr signature.
Script Path Spend
For a script path spend, the witness contains the script inputs, the script itself, and the control block.
Script Execution
For detailed information about script verification and spending path, refer to the P2TR MAST - Merklized Alternative Script Trees.
Key Path
When validating a P2TR key path spend, the following steps are executed:
- Witness Version Detection
The node recognizes witness version 1 with a 32 bytes program in the ScriptPubKey, triggering P2TR validation rules. - Check Witness Structure
For key path, the witness contains exactly one item (the signature). - Push Signature
The 64 bytes Schnorr signature is pushed from the witness data. - Push Tweaked Public Key
The 32 bytes tweaked public key from the ScriptPubKey is pushed onto the stack. - Verify Schnorr Signature
The signature is verified against the tweaked public key and transaction data using BIP340 Schnorr verification. - Result
If verification succeeds, the transaction is valid and the funds are unlocked.
Script Path
When validating a P2TR script path spend, additional steps are required:
- Witness Version Detection
The node recognizes witness version 1 with a 32 bytes program, triggering P2TR validation rules. - Check Witness Structure
For script path, the witness contains more than one item. The last item is the control block, the second-to-last is the script. - Parse Control Block
Extract the leaf version, parity bit, internal public key, and Merkle proof from the control block. - Compute Script Leaf Hash
Hash the script with the leaf version using tagged hashing. - Verify Merkle Proof
Compute the Merkle root from the script leaf hash and the proof, then verify the tweaked public key matches. - Execute Script
Run the revealed script with the remaining witness items as inputs. - Result
If script execution succeeds with a true result, the transaction is valid.