Extract internal keys from Bitcoin transactions
Bitcoin’s private keys are designed in such a way that they are very safe and resistant to reverse engineering. One of the challenges in understanding how these keys are generated and used is to extract the internal key from an optimized pubkey and BIP341 tweak day.
In this article we will examine what happens when a user optimizes his public with the “TweakpubKey” command with BIP341 and try to extract the internal key. We will also discuss why this process seems impossible without more context.
Optimize a public key
If a user wants to optimize his private key, he use the following commands:
`Bash
$ Bitcoin-Taproot
This will change the private key and create a new tweaked pubkey.
The command BIP341 is used to specify the tweak day for the new public key. The tweak day determines how the user’s private key should be changed in order to create the optimized public key.
Extracting the internal key
In order to extract the internal key from an optimized pubkey and BIP341 tweak day, we have to understand how Bitcoin creates these keys.
A Bitcoin transaction consists of a series of input outputs (IOVS), which are summarized in a single edition. Each IOV contains the public’s public key, the recipient’s public key and other relevant information. The internal key is generated by changing the user’s private key using the Optimed Pubkey.
If a user wants to change his private key with the “Tweakpubkey” command, Bitcoin generates a new private key that is compatible with the TWEAK day specified in the issue of BIP341. This new private key is then used to sign and check transactions.
The problem: extract the internal key
Let’s assume that we have an optimized BIP341 tweak day with which we can extract the internal key:
`Bash
$ Bitcoin-Taproot
The “-tweakpubkey” option indicates the tweak day. The 0x00a9d6d5e8c3f4b1abcdef000000001 is an example -tweak day.
To extract the internal key, we can use the “BIP341” command to generate a new private key that is compatible with this optimized pubkey:
`Bash
$ Bitcoin-Taproot
This creates a new private key that is compatible with the optimized pubkey.
Now we can use this extracted private key to sign and check transactions. The internal key is now accessible via the “extracted key”.
Why extracting the internal key is impossible without more context
In summary, extracting the internal key from a tweaked pubkey and BIP341 tweak day requires more context than just optimizing the public key with tweakpubkey. To extract the internal key, we have to:
- Create a new private key that is compatible with the optimized pubkey.
- Use the “BIP341” command to generate a new private key that corresponds to the tweak day of the optimized pubkey.
Without knowing the exact tweak day or the private key that is used in the original transaction, it is impossible to extract the internal key only with the tweaked pubkey and BIP341 tweak day.
Diploma

If you use a public key with “tweakpubkey” with BIP341, you can change the user’s private key. However, extracting the internal key from the resulting tweaked pubkey is not easy. Without more context, such as the original transaction or the private key that is used in the optimized pubkey, it seems impossible to extract the internal key.
However, if you have access to the original transaction and the tweaked pubkey with BIP341 tweak day, you may be able to restore the internal key through reverse engineering.