# XMSS

> How Pearl's optional post-quantum XMSS signatures work: hash chains, Winternitz digits, a 32-leaf Merkle tree, 2,340-byte signatures and OP_CHECKXMSSSIG.

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

[XMSS](https://pearlcodex.com/glossary/#xmss) is a way to sign messages using nothing but a hash function. No curves, no hard number puzzles: if the hash function is safe, the signatures are safe.

That matters because of quantum computers. A large enough one could break the [elliptic-curve](https://pearlcodex.com/technical/cryptography/elliptic-curves/) math behind Schnorr signatures, but it would barely dent a good hash function. Pearl adds XMSS as an optional, [post-quantum](https://pearlcodex.com/glossary/#post-quantum) way to lock coins.

> **Pearl vs Bitcoin: Pearl-only**
>
> Bitcoin has no XMSS and no opcode for it. Pearl adds `OP_CHECKXMSSSIG` as opcode `0xde`, valid only inside tapscript. In Bitcoin’s tapscript that byte is an unused “OP_SUCCESS” placeholder.

## Why would hashes survive a quantum computer?

Shor’s algorithm lets a quantum computer solve the discrete-logarithm problem, which is what keeps a private key hidden behind its public key. That would break every elliptic-curve signature.

Hash functions have no such weakness. The best known quantum attack on them, Grover’s algorithm, only takes a square root off the work: a 256-bit hash still needs about 2¹²⁸ quantum steps to invert. So a signature that relies only on hashes stays secure.

XMSS is standardised in RFC 8391. It’s built in three layers.

## Layer 1: how can a hash make a signature?

Start with a secret random value and hash it over and over, 15 times. You get a chain of 16 values. Publish only the last one.

To “sign” a number d between 0 and 15, reveal the value d steps along the chain. Anyone can check it: hash it 15 − d more times and see if it lands on the published end.

_A Winternitz chain with w = 16. Signing the digit 5 reveals the value after 5 hashes. The verifier hashes it 10 more times and must reach the public end._

Hashing forward is easy. Hashing backward is impossible, because hashes are [one-way](https://pearlcodex.com/technical/cryptography/hash-functions/). That asymmetry is the whole signature. This kind of scheme is a [one-time signature](https://pearlcodex.com/glossary/#one-time-signature): once part of a chain is revealed, the key mustn’t sign again.

## Layer 2: how do you sign a whole message?

Use many chains, one per digit. This is the [Winternitz](https://pearlcodex.com/glossary/#winternitz) scheme (WOTS+). With chains of 16 values, each chain signs one hexadecimal digit.

A 32-byte digest has 64 hex digits, so it needs 64 chains. But there’s a catch: anyone holding a signature can hash further along any chain, raising that digit, and sign a different message. Three **checksum** digits stop that.

> **Scenario · made-up numbers: Winternitz digits, worked out**
>
> Take a 32-byte digest. (In real XMSS the digest is a randomized hash of the message; here we just use SHA-256 of “Pearl” to show the arithmetic.)
>
> `72bc556112e9538a2433f0a9b87b032eae43c69e367e9dca1b176929dcf20ed5`
>
> - Its 64 hex digits are the positions to reveal on chains 1 to 64: 7, 2, b (11), c (12), 5, …
> - The digits add up to 469. The checksum counts how far every chain is from its end: 64 × 15 − 469 = 491.
> - 491 is `0x1eb`, so chains 65, 66 and 67 sign the digits 1, e (14) and b (11).
>
> A forger who raises any message digit makes the checksum smaller, so some checksum digit would have to go _down_: back along its chain. That’s impossible.

That gives 64 + 3 = 67 chains, and a one-time signature of 67 × 32 = 2,144 bytes.

## Layer 3: how does one key sign 32 times?

One-time keys are awkward: you’d need a new public key for every signature. XMSS fixes this with a [Merkle tree](https://pearlcodex.com/technical/cryptography/merkle-trees/).

Make 32 one-time keys. Hash each one’s public part into a leaf, and build a tree of height 5 over the 32 leaves. The root becomes the long-term public key.

To sign, use the next unused one-time key, and attach its [authentication path](https://pearlcodex.com/glossary/#merkle-proof): the 5 sibling hashes from its leaf to the root. The verifier rebuilds the one-time public key from the signature, climbs the path, and checks the root.

_Simplified: a tree of height 3 (8 one-time keys). Pearl’s tree has height 5, 32 leaves. Signing with leaf 2 needs its authentication path: the highlighted siblings._

So a full XMSS signature is: the leaf’s index, a random value r used to hash the message, the 67-chain one-time signature, and the authentication path.

$$
4 + 32 + 67 \times 32 + 5 \times 32 = 2{,}340 \text{ bytes}
$$

Signature

_index + randomness r + one-time signature + authentication path._

## What are Pearl’s exact parameters?

Pearl uses a configuration its code calls XMSS-SHAKE256_5_256, which is not one of RFC 8391’s named sets:

- **Hash:** SHAKE256 32-byte outputs (n = 32)
- **Winternitz w:** 16 67 chains (64 + 3)
- **Tree height:** 5 one layer (d = 1)
- **Signatures per key:** 32 2⁵ leaves
- **Public key:** 64 bytes root + public seed
- **Signature:** 2,340 bytes 5 × 468 in a witness

The hash is [SHAKE256](https://pearlcodex.com/glossary/#shake256), from the SHA-3 family. The secret key is 128 bytes plus a 4-byte index that counts the signatures used.

> **Warning: XMSS keys have state**
>
> Every signature uses up one leaf, and **a leaf must never sign twice**. Reusing an index leaks enough chain values to forge signatures. So whoever holds an XMSS key must remember, reliably, how many signatures it has made, even across backups and restores. After 32 signatures the key is spent.

## How does Pearl use XMSS?

Through tapscript, Pearl’s script language for Taproot and P2MR outputs:

- **The opcode.** `OP_CHECKXMSSSIG` takes five 468-byte signature pieces and a 64-byte public key from the stack. Stack items are capped at 520 bytes, which is why the 2,340-byte signature is split in five.
- **What is signed.** The same tapscript signature digest that Schnorr signatures sign (BIP-342), always with the default sighash type.
- **Failure is final.** An invalid XMSS signature makes the whole script fail; it never just pushes “false”. Each check also costs 1,000 units of the input’s script budget.
- **The script leaf.** The simplest XMSS leaf is `40 <64-byte public key> de`: push 64 bytes, then `OP_CHECKXMSSSIG`. 66 bytes in all.

Until v1.5.5, the reference wallet (Oyster) could add such a leaf to a Taproot address when asked: `getnewaddress` with a `pq` flag set to true. It took the XMSS key from a separate branch of the wallet’s seed (purpose 222, which is `0xde`, the opcode’s byte), stretched with HKDF-SHA256 into a 64-byte private seed and a 32-byte public seed.

v1.5.5 removed all of it: the flag, the branch and the key helpers. Pearl Research Labs call it a clean-up before a full post-quantum wallet built on [P2MR](https://pearlcodex.com/technical/script/p2mr/), which will derive XMSS keys its own way.

The result was a normal-looking Taproot address whose script tree had one XMSS leaf. Here is one, made by Oyster v1.5.2 from the public BIP-39 test words:

| Part                       | Value                                                                                                                              |
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| XMSS public key (64 bytes) | `5e70da755554f576d008eb89bfa9ffa8965e08cfdcfa48aaf85d59499792497a4b9e933bfc2f4695395f43339d799434741e36742ce2f0df31994e54b25ee8f8` |
| Address                    | `prl1ph89v46drqp3rd3cfaylqqwnynuu2cgykdgqd60094qxp4jl4sd7ssg6v5j`                                                                  |

## What are the honest limits today?

XMSS in Pearl is real but early. As of v1.5.5:

- **No wallet uses it.** Every address Pearl’s wallet makes, change included, has no XMSS leaf, and since v1.5.5 there is no option to add one. They are protected by Schnorr alone.
- **A Taproot leaf leaves the key path open.** A Taproot address with an XMSS leaf can still be spent with an ordinary Schnorr signature. Someone who could break secp256k1 could use that path too. A [P2MR](https://pearlcodex.com/technical/script/p2mr/) output has no key path, but no Pearl wallet creates P2MR addresses.
- **Nothing signs with it yet.** The research found no production code that makes XMSS signatures; only a test calls the signer.
- **Old pq addresses need an old wallet.** Oyster v1.5.5 can’t spend coins sent to an address made with the removed `pq` option: it now signs for the plain key, which no longer matches that address. Pearl’s release notes say to spend them with an earlier release before upgrading.
- **It’s big.** An XMSS script-path spend’s witness is roughly 2,457 bytes, about 615 vbytes, against about 16.5 vbytes for a Schnorr key-path witness (an estimate from the research, not a measured transaction).

**Why the opcode number is 0xde**

`0xde` is 222. Oyster up to v1.5.3 derived its XMSS keys under BIP-32 purpose 222′, matching the opcode byte, in the same way that Pearl’s normal keys live under purpose 86′ (BIP-86). The opcode is defined in [`opcode.go`](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/txscript/opcode.go#L2020-L2105), and the parameters in [`xmss.cpp`](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/xmss/src/xmss.cpp#L11-L31):

`xmss/src/xmss.cpp`

```cpp
// config: XMSS-SHAKE256_5_256 (not in RFC 8391)
static constexpr xmss_params default_params = {
    .func = XMSS_SHAKE256,
    .n = 32,                   // hash input & output length
    .wots_w = 16,              // Winternitz parameter
    .wots_len = 67,            // len1 + len2,
    .full_height = 5,          // allows 32 signatures
    .d = 1,                    // no MT recursion
    .sig_bytes = 2340, // wots_sig_bytes + index_bytes + (height + 1) * n,
    .pk_bytes = 64,    // 2 * n
    // ...
};
```

## In short

- XMSS is a signature scheme built only from a hash function, so it does not rely on the elliptic-curve math a large quantum computer could break.
- Its core is a one-time signature: secrets are hashed along chains, and signing a digit means revealing a point partway along a chain.
- Pearl’s version (SHAKE256, w = 16, tree height 5) signs a 32-byte digest with 67 chains and allows 32 signatures per key.
- A public key is 64 bytes; a signature is 2,340 bytes, passed to OP_CHECKXMSSSIG in five 468-byte pieces.
- XMSS is optional and stateful. Pearl’s rules accept it, but no Pearl wallet uses it (v1.5.5 removed Oyster’s early option), and a key must never sign twice with the same index.

## Read the code

- [Pearl's XMSS parameters](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/xmss/src/xmss.cpp#L11-L31) `xmss/src/xmss.cpp:11-31`
- [OP_CHECKXMSSSIG](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/txscript/opcode.go#L2020-L2105) `node/txscript/opcode.go:2020-2105`
- [The one valid XMSS spend in the code: a test](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/txscript/opcode_test.go#L260-L323) `node/txscript/opcode_test.go:260-323`
- [getnewaddress since v1.5.5: no pq option](https://github.com/pearl-research-labs/pearl/blob/v1.5.5/node/btcjson/walletsvrcmds.go#L243-L247) `node/btcjson/walletsvrcmds.go:243-247`

## Sources

### Pearl source

- [Pearl source code at v1.5.5](https://github.com/pearl-research-labs/pearl/tree/v1.5.5)
- [Pearl PR #463: removing the wallet's partial post-quantum support (v1.5.5)](https://github.com/pearl-research-labs/pearl/pull/463)

### Bitcoin standards

- [BIP-342: tapscript (the signature message XMSS signs)](https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki)
- [BIP-360: Pay to Merkle Root (P2MR), draft](https://github.com/bitcoin/bips/blob/master/bip-0360.mediawiki)

### Papers

- [RFC 8391: XMSS, eXtended Merkle Signature Scheme](https://www.rfc-editor.org/rfc/rfc8391)
