I've started learning Taproot and I'm having trouble understanding some of the general story behind how it works in the context of a public key in scriptPubKey.

The segWit v1 (Taproot) scriptPubKey looks like 1 <32-public-key>. However, what is the way to create this public key?

Can someone give me some general abstract story of how this public key is created? I don't need details, just some general story to create a bigger picture. Below I have just listed the questions that would be good to include in the answer.

I know that we need to create MAST, and then by tweaking MAST root and some random public key we get the public key for the taproot (something like that). However, what if we do not have MAST and we just want to use classic signature (I think its called keypath)? We are not doing any tweaking then? Also, is the underline public key (that was tweaked with MAST root) really random or does it result from the application of some algorithm (Schnorr?)?

  • Hi LeaBit, your post contains a lot of different questions, can you shorten it to just one and make the other questions each into their own post if needed? Nov 8, 2023 at 0:48
  • @VojtěchStrnad Hi Vojtech, my question is just how to create public key (and perhaps signature) for the taproot. This text below are not actual questions but notes what I expect in answer. I shortened it a bit to focus on one thing only. Hope its better now.
    – LeaBit
    Nov 8, 2023 at 1:00
  • 2
    For general emphasis or introducing lingo, it may be better to use italicized style rather than code style. Too much code styling can reduce readability. Around here, most users seem to use code styling mostly to present variable or function names, or when inlining formulas or logic expressions.
    – Murch
    Nov 8, 2023 at 14:45

1 Answer 1


Consider two keyapirs, pubkey A with privkey a and pubkey B with privkey b. If you add the pubkeys together to get pubkey C, (A + B = C), C's private key c is also the sum of the two private keys, i.e. a + b = c. Furthermore, Schnorr signatures over the same message can be added together to produce a valid signature for the sum of the pubkeys, i.e. sig(a, msg) + sig(b, msg) = sig(c, msg). This linearity property of pubkeys and Schnorr signatures is what Taproot makes use of.

The most basic construction in Taproot is the keypath spend. This is simply a valid Schnorr signature for the output public key. At the most basic, you could just generate a new random keypair, put the public key in your P2TR script, and then spending is just generating a Schnorr signature with the private key.

However BIP 341 recommends using an "internal key". This is just a normal keypair that has a "tweak" added to it. In its most basic form, the tweak is just the hash of the public key itself. As a hash produces a 256 bit value, it can be treated as a private key, so the public key is computed with the tweak as the private key, and that public key is added to the internal key's pubkey to get the output key. When spending, the tweak is added to the private key so to get the private key of the output pubkey so that a valid signature can be produced for the output pubkey.

The last form a taproot output key can take is one that has both an internal key and a script tree. The script tree is a set of scripts which are used as the leaves of a merkle tree. Then the hashes of that merkle tree are computed until the merkle root is computed. Computing the output pubkey is almost the same as the previous construction with just the internal key. The only difference is that the tweak is the internal public key concatenated with the merkle root. The rest of the procedure remains the same.

In all of these constructions, there's always a random keypair, whether that is the output key itself, or the internal key. Even when you add the tweak in, the randomness is still preserved. The additional steps of hashing the tweak also help to make the tweak more random.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.