# P2TR

> Pay-to-Taproot, Pearl's everyday output: 51 20 plus a tweaked key. How the key path and the script path work, with the control block checked step by step.

Source: https://pearlcodex.com/technical/script/p2tr/ · Last updated: 2026-11-02 · Checked against Pearl's source code at v1.5.5

[Pay-to-Taproot](https://pearlcodex.com/glossary/#p2tr) is the output nearly every Pearl coin sits in. It looks like a single public key, and most of the time it is used like one. But that key can also carry a hidden list of scripts, any one of which could spend the coin instead.

Two ways in, then: the **key path**, one signature, and the **script path**, a script plus proof that it was part of the deal from the start. From the outside, you can’t tell whether a Taproot output has scripts at all until one is used.

## Try it

Turn a private key into a Taproot output key and address.

_Interactive: Key forge. Try it on the page: <https://pearlcodex.com/technical/script/p2tr/>_

## What does a Taproot output look like?

- **Size:** 34 bytes
- **Type:** Witness version 1 program
- **Format:** 51 20 ‖ 32-byte output key Q

`51` is OP_1 (witness version 1), `20` pushes 32 bytes, and those bytes are the x-only [output key](https://pearlcodex.com/technical/keys/taproot-tweak/) Q. Here is one from a real payment:

**A typical payment: 1 input, 2 outputs · 205 bytes**

```
01000000 00 01 01 5939557091bae792be66f26cbd83fc78f16a690a854109e8a1d115e253812133 ab020000 00 ffffffff 02 b0359f1100000000 22 5120d7ab02c96a342bdddb5d07b9f3ebd6c04e077ff41418110b9a1e5997439416b2 00c2eb0b00000000 22 512062e9da3682aab288392cf7218bafc36287288abb3ce200c5d1a50aa234073b2b 01 40 4686c7014749649b25555874c7772ecb7a44e85454893ed5888db11ebcdc82a22d74ce1a1671d02810f5ba1dca3277409e95a653ba9644099f7da26be7a86ba2 00000000
```

| Field                                             | Bytes          | Value                                                                                                                                                                                                                  |
| ------------------------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Version (`version`)                               | 4, offset 0    | 1 · int32 little-endian. Pearl wallets and pearld coinbases use version 1; relay policy accepts 1-2.                                                                                                                   |
| Marker (`marker`)                                 | 1, offset 4    | 0x00 · Segwit marker (BIP-144): says witness data follows the outputs.                                                                                                                                                 |
| Flag (`flag`)                                     | 1, offset 5    | 0x01 · Witness flag; 0x01 is the only value Pearl accepts.                                                                                                                                                             |
| Input count (`vin.length`)                        | 1, offset 6    | 1 · CompactSize number of inputs.                                                                                                                                                                                      |
| Previous txid (`vin[0].txid`)                     | 32, offset 7   | 33218153e215d1a1e80941850a696af178fc83bd6cf266be92e7ba9170553959 · The transaction being spent, stored byte-reversed (internal order); shown here in normal display order.                                             |
| Output index (`vin[0].vout`)                      | 4, offset 39   | 683 · Which output of that transaction is spent (uint32 LE).                                                                                                                                                           |
| scriptSig length (`vin[0].scriptSig.length`)      | 1, offset 43   | 0 · Always 0 for non-coinbase inputs in Pearl: every spend uses the witness instead.                                                                                                                                   |
| Sequence (`vin[0].sequence`)                      | 4, offset 44   | 0xffffffff · Final (0xffffffff): no RBF signal, no relative locktime, and locktime is ignored for this input. Pearl wallets use this.                                                                                  |
| Output count (`vout.length`)                      | 1, offset 48   | 2 · CompactSize number of outputs.                                                                                                                                                                                     |
| Amount (`vout[0].value`)                          | 8, offset 49   | 295,646,640 grains (2.95646640 PRL) · int64 little-endian, in grains (1 PRL = 100,000,000 grains).                                                                                                                     |
| Script length (`vout[0].scriptPubKey.length`)     | 1, offset 57   | 34 · CompactSize length of the locking script.                                                                                                                                                                         |
| Locking script (`vout[0].scriptPubKey`)           | 34, offset 58  | prl1p674s9jt2xs4amk6aq7ul867kcp8qwll5zsvpzzu6revewsu5z6eqv9d5z4 · OP_1 OP_PUSHBYTES_32 \<output key Q>: a Taproot output.                                                                                              |
| Amount (`vout[1].value`)                          | 8, offset 92   | 200,000,000 grains (2.00000000 PRL) · int64 little-endian, in grains (1 PRL = 100,000,000 grains).                                                                                                                     |
| Script length (`vout[1].scriptPubKey.length`)     | 1, offset 100  | 34 · CompactSize length of the locking script.                                                                                                                                                                         |
| Locking script (`vout[1].scriptPubKey`)           | 34, offset 101 | prl1pvt5a5d5z42egswfv7uscht7rv2rj3z4m8n3qp3w35592ydq88v4seuhn70 · OP_1 OP_PUSHBYTES_32 \<output key Q>: a Taproot output.                                                                                              |
| Witness items (`witness[0].length`)               | 1, offset 135  | 1 · Number of witness stack items for input 0.                                                                                                                                                                         |
| Schnorr signature length (`witness[0][0].length`) | 1, offset 136  | 64 · CompactSize length of this witness item.                                                                                                                                                                          |
| Schnorr signature (`witness[0][0]`)               | 64, offset 137 | 4686c7014749649b25555874c7772ecb7a44e85454893ed5888db11ebcdc82a22d74ce1a1671d02810f5ba1dca3277409e95a653ba9644099f7da26be7a86ba2 · 64-byte BIP-340 signature (R.x ‖ s) with SIGHASH_DEFAULT: a Taproot key-path spend. |
| Locktime (`locktime`)                             | 4, offset 201  | 0 · 0: no time lock.                                                                                                                                                                                                   |

- **txid:** d919e02a4adfd739ceef31d98803f0ddd24e1b1fa67b0fe572cdec42c1b384c9
- **Size:** 205 bytes · 154 vbytes
- **Block:** 130,825
- **Fee:** 7,915 grains

Written as an address, that’s `prl1pvt5a5d5z42egswfv7uscht7rv2rj3z4m8n3qp3w35592ydq88v4seuhn70`. Q was made by tweaking an internal key P with the root of a script tree; for a plain wallet address, the tree is empty.

_A Taproot output commits to two ways of spending. The key path needs only a signature for Q; the script path reveals one leaf and proves it is in the tree._

## How does the key path work?

The witness holds exactly one item, a [Schnorr signature](https://pearlcodex.com/technical/cryptography/schnorr/), and the node checks it against Q and the transaction’s [sighash](https://pearlcodex.com/technical/transaction/sighash/):

**A typical payment: 1 input, 2 outputs · 205 bytes**

```
01000000 00 01 01 5939557091bae792be66f26cbd83fc78f16a690a854109e8a1d115e253812133 ab020000 00 ffffffff 02 b0359f1100000000 22 5120d7ab02c96a342bdddb5d07b9f3ebd6c04e077ff41418110b9a1e5997439416b2 00c2eb0b00000000 22 512062e9da3682aab288392cf7218bafc36287288abb3ce200c5d1a50aa234073b2b 01 40 4686c7014749649b25555874c7772ecb7a44e85454893ed5888db11ebcdc82a22d74ce1a1671d02810f5ba1dca3277409e95a653ba9644099f7da26be7a86ba2 00000000
```

| Field                                             | Bytes          | Value                                                                                                                                                                                                                  |
| ------------------------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Version (`version`)                               | 4, offset 0    | 1 · int32 little-endian. Pearl wallets and pearld coinbases use version 1; relay policy accepts 1-2.                                                                                                                   |
| Marker (`marker`)                                 | 1, offset 4    | 0x00 · Segwit marker (BIP-144): says witness data follows the outputs.                                                                                                                                                 |
| Flag (`flag`)                                     | 1, offset 5    | 0x01 · Witness flag; 0x01 is the only value Pearl accepts.                                                                                                                                                             |
| Input count (`vin.length`)                        | 1, offset 6    | 1 · CompactSize number of inputs.                                                                                                                                                                                      |
| Previous txid (`vin[0].txid`)                     | 32, offset 7   | 33218153e215d1a1e80941850a696af178fc83bd6cf266be92e7ba9170553959 · The transaction being spent, stored byte-reversed (internal order); shown here in normal display order.                                             |
| Output index (`vin[0].vout`)                      | 4, offset 39   | 683 · Which output of that transaction is spent (uint32 LE).                                                                                                                                                           |
| scriptSig length (`vin[0].scriptSig.length`)      | 1, offset 43   | 0 · Always 0 for non-coinbase inputs in Pearl: every spend uses the witness instead.                                                                                                                                   |
| Sequence (`vin[0].sequence`)                      | 4, offset 44   | 0xffffffff · Final (0xffffffff): no RBF signal, no relative locktime, and locktime is ignored for this input. Pearl wallets use this.                                                                                  |
| Output count (`vout.length`)                      | 1, offset 48   | 2 · CompactSize number of outputs.                                                                                                                                                                                     |
| Amount (`vout[0].value`)                          | 8, offset 49   | 295,646,640 grains (2.95646640 PRL) · int64 little-endian, in grains (1 PRL = 100,000,000 grains).                                                                                                                     |
| Script length (`vout[0].scriptPubKey.length`)     | 1, offset 57   | 34 · CompactSize length of the locking script.                                                                                                                                                                         |
| Locking script (`vout[0].scriptPubKey`)           | 34, offset 58  | prl1p674s9jt2xs4amk6aq7ul867kcp8qwll5zsvpzzu6revewsu5z6eqv9d5z4 · OP_1 OP_PUSHBYTES_32 \<output key Q>: a Taproot output.                                                                                              |
| Amount (`vout[1].value`)                          | 8, offset 92   | 200,000,000 grains (2.00000000 PRL) · int64 little-endian, in grains (1 PRL = 100,000,000 grains).                                                                                                                     |
| Script length (`vout[1].scriptPubKey.length`)     | 1, offset 100  | 34 · CompactSize length of the locking script.                                                                                                                                                                         |
| Locking script (`vout[1].scriptPubKey`)           | 34, offset 101 | prl1pvt5a5d5z42egswfv7uscht7rv2rj3z4m8n3qp3w35592ydq88v4seuhn70 · OP_1 OP_PUSHBYTES_32 \<output key Q>: a Taproot output.                                                                                              |
| Witness items (`witness[0].length`)               | 1, offset 135  | 1 · Number of witness stack items for input 0.                                                                                                                                                                         |
| Schnorr signature length (`witness[0][0].length`) | 1, offset 136  | 64 · CompactSize length of this witness item.                                                                                                                                                                          |
| Schnorr signature (`witness[0][0]`)               | 64, offset 137 | 4686c7014749649b25555874c7772ecb7a44e85454893ed5888db11ebcdc82a22d74ce1a1671d02810f5ba1dca3277409e95a653ba9644099f7da26be7a86ba2 · 64-byte BIP-340 signature (R.x ‖ s) with SIGHASH_DEFAULT: a Taproot key-path spend. |
| Locktime (`locktime`)                             | 4, offset 201  | 0 · 0: no time lock.                                                                                                                                                                                                   |

- **txid:** d919e02a4adfd739ceef31d98803f0ddd24e1b1fa67b0fe572cdec42c1b384c9
- **Size:** 205 bytes · 154 vbytes
- **Block:** 130,825
- **Fee:** 7,915 grains

64 bytes means the default sighash; 65 bytes means the last byte is an explicit type. The signer uses the tweaked private key d + t, which wallets derive from the internal key whenever they sign. Nothing about scripts is revealed, or even whether there are any. This is a [key-path spend](https://pearlcodex.com/glossary/#key-path-spend), and it’s what Pearl’s wallet does for every coin.

## How does the script path work?

The witness holds the script’s inputs, then the script, then a [control block](https://pearlcodex.com/glossary/#control-block):

| Field                  | Size   | Description                                                                        |
| ---------------------- | ------ | ---------------------------------------------------------------------------------- |
| leaf version \| parity | 1      | `c0` (tapscript) OR the parity of Q’s y coordinate (0 or 1): `c0` or `c1`.         |
| internal key P         | 32     | The x-only key that was tweaked to make Q.                                         |
| Merkle path            | 32 × m | The sibling hashes from the leaf up to the root; m is the leaf’s depth (0 to 128). |

Then the node checks the commitment, in four steps:

1. **Hash the leaf**

   TapLeaf hash = TaggedHash(“TapLeaf”, `c0` ‖ script length ‖ script).

2. **Climb the tree**

   Combine it with each path hash in turn: TaggedHash(“TapBranch”, smaller ‖ larger). The last result is the root.

3. **Redo the tweak**

   t = TaggedHash(“TapTweak”, P ‖ root), and Q’ = P + t·G.

4. **Compare**

   Q’ must equal the output’s Q, and its y parity must match the control block’s low bit. Then the script runs as tapscript, with the witness items before it as its starting stack.

### A worked example

This test vector was produced with Pearl’s own code by the research for this site. Its previous outpoint is made up; everything else is real Pearl behavior, and Pearl’s engine accepted it.

|                  | Value                                                                       |
| ---------------- | --------------------------------------------------------------------------- |
| Internal key P   | `79be667e…16f81798` (the generator, private key 1)                          |
| The one leaf     | `20 e493dbf1…c4cd13 ac`: push the key of private key 4, then OP_CHECKSIG    |
| Leaf hash = root | `0e167d3d619d2b16fb08736a6e696eb6814c6d99a578c8c268d4195aeb9f72d1`          |
| Output key Q     | `3bb7c61536fc47c697ed6d21042fc79a6f491ef982f605ba7ca277bbd79aa25c` (even y) |
| Address          | `prl1p8wmuv9fkl3rud9ldd5ssgt78nfh5j8hestmqtwnu5fmmh4u65fwqm3tz0r`           |

**Script-path witness (test vector) · 135 bytes**

```
03 40 a4fdc52f6cf77234304c7452440ca89c3d230df22a478134e13c2b52d89c01b07d9073af64632775a3bd6b39374e768523515829759ae0c055dc196c11bd6e33 22 20e493dbf1c10d80f3581e4904930b1404cc6c13900ee0758474fa94abe8c4cd13ac 21 c079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
```

| Field             | Bytes          | Value                                                                                                                            |
| ----------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| item count        | 1, offset 0    | 3 items                                                                                                                          |
| length            | 1, offset 1    | 64                                                                                                                               |
| signature (key 4) | 64, offset 2   | a4fdc52f6cf77234304c7452440ca89c3d230df22a478134e13c2b52d89c01b07d9073af64632775a3bd6b39374e768523515829759ae0c055dc196c11bd6e33 |
| length            | 1, offset 66   | 34                                                                                                                               |
| leaf script       | 34, offset 67  | \<key 4> OP_CHECKSIG                                                                                                             |
| length            | 1, offset 101  | 33                                                                                                                               |
| control block     | 33, offset 102 | c0 (parity 0) ‖ P; no path                                                                                                       |

_From the research's Pearl-code test vector 15.G. Made-up outpoint; the 64-byte signature is by private key 4._

The leaf starts with the signature on its stack, pushes key 4, and OP_CHECKSIG checks the signature: true, success. Mainnet has script-path Taproot spends too; one in block 130,690 used a 33-byte control block like this one.

## Why do wallets prefer the key path?

Because it’s smaller and it says less.

| Spend                               | Witness bytes | Witness vbytes | Reveals                                         |
| ----------------------------------- | ------------- | -------------- | ----------------------------------------------- |
| Key path (the payment above)        | 66            | 16.5           | one signature                                   |
| Script path (the test vector above) | 135           | 33.75          | the script, the internal key, the tree position |

The witness counts a quarter, so the difference per input is small in fees. The bigger difference is privacy: a key-path spend looks like every other key-path spend on the chain, whether or not the output had scripts behind it. A script-path spend shows the world one of the conditions, and that a tree existed.

So the usual design is: put the common case (everyone agrees) on the key path, and keep scripts for the exceptions. The quantum-safe addresses Oyster could make until v1.5.5 followed it: the XMSS leaf was there for an emergency, and everyday spends used the key.

## What do Pearl wallets do with Taproot?

- **Default addresses are key-path only.** Oyster derives a BIP-86 key and tweaks it with an empty tree. There is no script to reveal; every spend is a single signature.
- **No address has a leaf.** Up to v1.5.3, `getnewaddress … pq=true` committed one leaf that checks an XMSS signature ([OP_CHECKXMSSSIG](https://pearlcodex.com/technical/script/op-checkxmsssig/)), and the wallet still spent those addresses by key path. v1.5.5 removed the option. Its wallet signs every key-path spend with the plain BIP-86 tweak, so it can’t spend from an old pq address.

## What rules apply?

- **The 32 bytes are not checked** to be a valid point when the output is created, as in Bitcoin. A wrong one just makes the coin unspendable.
- **Leaf version must be `0xc0`.** Bitcoin lets unknown leaf versions pass, for future upgrades; Pearl fails them (“unsupported tapscript leaf version”).
- **Control blocks** are 33 + 32m bytes, m at most 128, so at most 4,129 bytes.
- **An annex** may follow the control block (see [witness](https://pearlcodex.com/technical/transaction/witness/)).

> **Pearl vs Bitcoin**
>
> Taproot on Pearl is BIP-341 and BIP-342: the same tweak, tags, control block and signature message, and Pearl’s code reproduces BIP-86’s test vectors. Differences: the address prefix (`prl1p`), unknown leaf versions and key sizes fail instead of passing, OP_CAT and OP_CHECKXMSSSIG are available in leaves, and there are no OP_SUCCESS opcodes.

## In short

- A Taproot (P2TR) output is 34 bytes: OP_1, a 32-byte push, and the tweaked output key Q. Its address starts prl1p.
- Key path: the witness is one Schnorr signature that verifies against Q. That’s how Pearl wallets spend, and it reveals nothing about any scripts.
- Script path: the witness reveals one script, its inputs and a control block holding the internal key P and the Merkle path.
- The node rebuilds the Merkle root from the script and path, redoes the tweak from P, and checks it lands exactly on Q before running the script.
- Only leaf version 0xc0 (tapscript) exists on Pearl; any other version fails.

## Read the code

- [verifyTaprootSpend: key path or script path](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/txscript/engine.go#L485-L534) `node/txscript/engine.go:485-534`
- [Control block sizes: 33 + 32m, m ≤ 128](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/txscript/taproot.go#L35-L50) `node/txscript/taproot.go:35-50`
- [Checking the script commitment against Q](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/txscript/taproot.go#L367-L407) `node/txscript/taproot.go:367-407`
- [Only leaf version 0xc0 is accepted](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/txscript/engine.go#L589-L617) `node/txscript/engine.go:589-617`
- [TapLeaf and TapBranch hashes](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/txscript/taproot.go#L570-L633) `node/txscript/taproot.go:570-633`

## Sources

### Bitcoin standards

- [BIP-341: Taproot](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki)
- [BIP-342: Validation of Taproot scripts](https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki)
- [BIP-86: Key derivation for single-key P2TR outputs](https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki)

### Other

- [learnmeabitcoin: P2TR](https://learnmeabitcoin.com/technical/script/p2tr/)
