# Taproot tweak

> Pearl addresses hold a tweaked key Q = P + t·G, where t is a tagged hash of your key and any scripts. Worked through with real numbers for key 1.

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

Your Taproot address doesn’t contain your public key. It contains a slightly shifted version of it, and that small shift is what makes Taproot work.

The shift is called the [Taproot tweak](https://pearlcodex.com/glossary/#taproot-tweak). Your wallet hashes your public key (together with any backup scripts), turns the hash into a number t, and moves the key by t steps along the curve. The result Q is still a perfectly ordinary public key. But it now quietly commits to whatever went into the hash.

## Try it

A tagged hash is the first ingredient. Pick the TapTweak tag and hash a key.

_Interactive: Tagged hash. Try it on the page: <https://pearlcodex.com/technical/keys/taproot-tweak/>_

## Why tweak a key at all?

Because a Taproot output can be spent two ways, and the key has to commit to both.

- **The key path:** one signature from the key. That’s how Pearl wallets spend almost everything.
- **The script path:** reveal one of several scripts that were committed in advance, and satisfy it.

The tweak binds the scripts into the key. If there are scripts, the hash includes their [Merkle root](https://pearlcodex.com/glossary/#merkle-root), so nobody can invent a new script later. If there are none, the hash includes nothing extra, which proves there’s no hidden script. That second case is BIP-86, and it’s what every default Pearl address uses.

_The tweak moves the internal key P to the output key Q. Both are points on the same curve; only Q appears in the address._

## How is the tweak computed?

Here is the whole calculation for private key 1. Its public key is the generator point itself, which keeps the numbers recognizable. (Key 1 is public: never send coins to its address.)

1. **Start from the x-only key P**

   P = `79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798`. Its y is even, so no adjustment is needed.

2. **Hash the tag**

   SHA256(“TapTweak”) = `e80fe1639c9ca050e3af1b39c143c63e429cbceb15d940fbb5c5a1f4af57c5e9`.

3. **Tagged hash of P**

   t = SHA256(tag hash ‖ tag hash ‖ P) = `3cf5216d476a5e637bf0da674e50ddf55c403270dd36494dfcca438132fa30e7`, read as a 256-bit number.

4. **Add t·G to P**

   Q = P + t·G. Its x-coordinate is `da4710964f7852695de2da025290e24af6d8c281de5a0b902b7135fd9fd74d21`, and its y happens to be odd.

5. **Write Q as an address**

   Version 1, program Q, prefix prl: `prl1pmfr3p9j00pfxjh0zmgp99y8zftmd3s5pmedqhyptwy6lm87hf5sse9xfq3`.

The 96 bytes that go into the final SHA-256 of step 3:

**TapTweak preimage, key 1 · 96 bytes**

```
e80fe1639c9ca050e3af1b39c143c63e429cbceb15d940fbb5c5a1f4af57c5e9 e80fe1639c9ca050e3af1b39c143c63e429cbceb15d940fbb5c5a1f4af57c5e9 79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
```

| Field                    | Bytes         | Value                         |
| ------------------------ | ------------- | ----------------------------- |
| SHA256("TapTweak")       | 32, offset 0  | the tag hash                  |
| SHA256("TapTweak") again | 32, offset 32 | the tag hash, repeated        |
| P (x-only)               | 32, offset 64 | internal key; no root follows |

_Computed with this site's library from private key 1; it matches the research vectors made with Pearl's own code._

Prefixing the tag’s hash keeps a TapTweak hash from ever colliding with any other kind of hash; writing it twice fills exactly one 64-byte SHA-256 block, which software can precompute. The [tagged hashes page](https://pearlcodex.com/technical/cryptography/tagged-hashes/) explains the trick.

## Which private key signs for Q?

The tweaked one. If P = d·G and Q = P + t·G, then Q = (d + t)·G, so d + t is the private key for Q.

One wrinkle: x-only keys always mean the point with even y. If d·G has odd y, the wallet uses n − d instead (same x, even y), then adds t:

$$
d' = \begin{cases} d + t & \text{if } d \cdot G \text{ has even } y \\ n - d + t & \text{otherwise} \end{cases} \pmod n
$$

For key 1, P has even y, so d’ = 1 + t:

`3cf5216d476a5e637bf0da674e50ddf55c403270dd36494dfcca438132fa30e8`

That’s t with its last digit bumped from 7 to 8. It’s the key behind every signature that spends from key 1’s address.

> **Warning: dumpprivkey gives the internal key**
>
> Oyster’s `dumpprivkey` exports d, the untweaked key, as WIF. Wallet software recomputes d + t whenever it signs. If you ever sign by hand with the exported key directly, the signature won’t match the address.

## What if there are scripts?

Then root is the Merkle root of the script tree, built from [TapLeaf](https://pearlcodex.com/glossary/#tapleaf) hashes. Take the same internal key G and commit to one leaf, `<G> OP_CHECKSIG` (bytes `20 79be…1798 ac`):

| Step                                 | Value                                                              |
| ------------------------------------ | ------------------------------------------------------------------ |
| Leaf hash = root (one leaf)          | `763e9da064b9dc0471fb0f3c8fa2c84b4b84d2ca992497c12d2274386795aa8e` |
| t = TaggedHash(“TapTweak”, P ‖ root) | `f1028f19b59a9cf0e26b17002188b8c05a2217d12768af23c5539600a089fbff` |
| Q (x-only, odd y)                    | `2d2f7b2a700ab270dd515ef7a02f25c5a344066641fcac563e1b53eca4a456d3` |
| Address                              | `prl1p95hhk2nsp2e8ph23tmm6qte9ck35gpnxg872c437rdf7ef9y2mfsnx7flw`  |

From outside, this address looks exactly like a key-only one. Only a spender who reveals the leaf, P and the Merkle path (the [control block](https://pearlcodex.com/glossary/#control-block)) shows that a script was there. The node then redoes the tweak and checks it lands on Q. The [P2TR page](https://pearlcodex.com/technical/script/p2tr/) walks through that check.

### Pearl’s quantum-safe addresses were tweaks too

Up to v1.5.3, when you asked Oyster for `getnewaddress … pq=true`, it built one script leaf, `40 <64-byte XMSS public key> de` (push 64 bytes, then [OP_CHECKXMSSSIG](https://pearlcodex.com/technical/script/op-checkxmsssig/)), and tweaked the normal BIP-86 key with that leaf’s hash.

The result was an ordinary `prl1p…` Taproot address, not a P2MR one. The Schnorr key path still worked, and anyone who could break Schnorr could use it too, so the XMSS leaf was an emergency backup, not full protection. The desktop wallet never asked for it, and change addresses never included it.

v1.5.5 removed the option, and its wallet now signs every key-path spend with the plain BIP-86 tweak. That’s the wrong key for a pq address, so Oyster v1.5.5 can’t spend coins sent to one. Pearl’s release notes say to move them with the earlier release before upgrading.

> **Note: P2MR has no tweak**
>
> Pearl’s other address type, [P2MR](https://pearlcodex.com/technical/script/p2mr/) (`prl1z…`), skips this step entirely. Its program is the script tree’s Merkle root itself, with no internal key and no key path.

> **Pearl vs Bitcoin: Same as Bitcoin**
>
> The formula, the tag and the BIP-86 empty root are unchanged. Pearl’s code reproduces the official BIP-86 test vectors, and for any key the output key Q is the same on both chains: key 1’s Bitcoin address is `bc1pmfr3p9j00pfxjh0zmgp99y8zftmd3s5pmedqhyptwy6lm87hf5sspknck9`, with the same 52 characters in the middle.

**Code: the tweak in JavaScript**

With [@noble/curves](https://github.com/paulmillr/noble-curves) (version 2), the BIP-86 tweak is a few lines:

```js
import { secp256k1 } from '@noble/curves/secp256k1.js';
import { sha256 } from '@noble/hashes/sha2.js';

const hex = (b) => Array.from(b, (x) => x.toString(16).padStart(2, '0')).join('');
const tag = sha256(new TextEncoder().encode('TapTweak'));
const taggedHash = (msg) => sha256(new Uint8Array([...tag, ...tag, ...msg]));

function bip86OutputKey(xonly /* Uint8Array(32) */) {
  const P = secp256k1.Point.fromHex('02' + hex(xonly));      // x-only means the even-y point
  const t = BigInt('0x' + hex(taggedHash(xonly)));
  const Q = P.add(secp256k1.Point.BASE.multiply(t));
  return Q.toBytes(true).slice(1);                            // x-only Q: the witness program
}
// bip86OutputKey(G.x) → da4710964f7852695de2da025290e24af6d8c281de5a0b902b7135fd9fd74d21
```

The same function, given an extra 32-byte root appended to `xonly` inside the hash, gives the script-tree version.

## In short

- A Taproot address doesn’t hold your public key P. It holds Q = P + t·G, where t = TaggedHash(“TapTweak”, P ‖ root).
- With no scripts (BIP-86, what Pearl wallets do), root is empty and t is just the tagged hash of P. That proves the address hides no script.
- The matching private key is d + t (negating d first if P has odd y). For key 1 it ends in …30e8.
- With scripts, root is the Merkle root of the script tree, and the address looks exactly the same from outside.
- Oyster’s quantum-safe addresses, an option until v1.5.5, used this: the tweak committed to one script leaf that checks an XMSS signature.

## Read the code

- [ComputeTaprootOutputKey and the BIP-86 key-only variant](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/txscript/taproot.go#L276-L331) `node/txscript/taproot.go:276-331`
- [Tweaking the private key](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/txscript/taproot.go#L335-L367) `node/txscript/taproot.go:335-367`
- [The TapTweak tag (unchanged from Bitcoin)](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/chaincfg/chainhash/hash.go#L21-L58) `node/chaincfg/chainhash/hash.go:21-58`
- [The wallet's key-path signature: the plain BIP-86 tweak, since v1.5.5](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/wallet/wallet/txauthor/author.go#L261-L294) `wallet/wallet/txauthor/author.go:261-294`

## Sources

### Bitcoin standards

- [BIP-341: Taproot (the tweak and the script tree)](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki)
- [BIP-86: Key derivation for single-key P2TR outputs](https://github.com/bitcoin/bips/blob/master/bip-0086.mediawiki)
- [BIP-340: Tagged hashes](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki)

### Other

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