Skip to content

Commit addb9b5

Browse files
committed
Improve comments in taproot signing logic
1 parent 4fc15d1 commit addb9b5

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

src/key.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,15 @@ class CKey
133133
* optionally tweaked by *merkle_root. Additional nonce entropy can be provided through
134134
* aux.
135135
*
136-
* When merkle_root is not nullptr, this results in a signature with a modified key as
137-
* specified in BIP341:
138-
* - If merkle_root->IsNull(): key + H_TapTweak(pubkey)*G
139-
* - Otherwise: key + H_TapTweak(pubkey || *merkle_root)
136+
* merkle_root is used to optionally perform tweaking of the private key, as specified
137+
* in BIP341:
138+
* - If merkle_root == nullptr: no tweaking is done, sign with key directly (this is
139+
* used for signatures in BIP342 script).
140+
* - If merkle_root->IsNull(): sign with key + H_TapTweak(pubkey) (this is used for
141+
* key path spending when no scripts are present).
142+
* - Otherwise: sign with key + H_TapTweak(pubkey || *merkle_root)
143+
* (this is used for key path spending, with specific
144+
* Merkle root of the script tree).
140145
*/
141146
bool SignSchnorr(const uint256& hash, Span<unsigned char> sig, const uint256* merkle_root = nullptr, const uint256* aux = nullptr) const;
142147

src/script/interpreter.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ struct PrecomputedTransactionData
170170

171171
PrecomputedTransactionData() = default;
172172

173+
/** Initialize this PrecomputedTransactionData with transaction data.
174+
*
175+
* @param[in] tx The transaction for which data is being precomputed.
176+
* @param[in] spent_outputs The CTxOuts being spent, one for each tx.vin, in order.
177+
* @param[in] force Whether to precompute data for all optional features,
178+
* regardless of what is in the inputs (used at signing
179+
* time, when the inputs aren't filled in yet). */
173180
template <class T>
174181
void Init(const T& tx, std::vector<CTxOut>&& spent_outputs, bool force = false);
175182

src/script/sign.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ bool MutableTransactionSignatureCreator::CreateSchnorrSig(const SigningProvider&
6161

6262
CKey key;
6363
{
64-
// For now, use the old full pubkey-based key derivation logic. As it indexed by
64+
// For now, use the old full pubkey-based key derivation logic. As it is indexed by
6565
// Hash160(full pubkey), we need to try both a version prefixed with 0x02, and one
6666
// with 0x03.
6767
unsigned char b[33] = {0x02};

src/script/standard.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,11 @@ struct TaprootSpendData
227227
/** The Merkle root of the script tree (0 if no scripts). */
228228
uint256 merkle_root;
229229
/** Map from (script, leaf_version) to (sets of) control blocks.
230-
* The control blocks are sorted by size, so that the signing logic can
231-
* easily prefer the cheapest one. */
230+
* More than one control block for a given script is only possible if it
231+
* appears in multiple branches of the tree. We keep them all so that
232+
* inference can reconstruct the full tree. Within each set, the control
233+
* blocks are sorted by size, so that the signing logic can easily
234+
* prefer the cheapest one. */
232235
std::map<std::pair<CScript, int>, std::set<std::vector<unsigned char>, ShortestVectorFirstComparator>> scripts;
233236
/** Merge other TaprootSpendData (for the same scriptPubKey) into this. */
234237
void Merge(TaprootSpendData other);
@@ -252,7 +255,7 @@ class TaprootBuilder
252255
/** Merkle hash of this node. */
253256
uint256 hash;
254257
/** Tracked leaves underneath this node (either from the node itself, or its children).
255-
* The merkle_branch field for each is the partners to get to *this* node. */
258+
* The merkle_branch field of each is the partners to get to *this* node. */
256259
std::vector<LeafInfo> leaves;
257260
};
258261
/** Whether the builder is in a valid state so far. */

0 commit comments

Comments
 (0)