Skip to content

Commit 6a0a6e7

Browse files
Correction for VerifyTaprootCommitment comments
According to BIP-341, 'p' is called the taproot *internal* key, not inner key.
1 parent 828bb77 commit 6a0a6e7

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/script/interpreter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,7 @@ static bool ExecuteWitnessScript(const Span<const valtype>& stack_span, const CS
18341834
static bool VerifyTaprootCommitment(const std::vector<unsigned char>& control, const std::vector<unsigned char>& program, const CScript& script, uint256& tapleaf_hash)
18351835
{
18361836
const int path_len = (control.size() - TAPROOT_CONTROL_BASE_SIZE) / TAPROOT_CONTROL_NODE_SIZE;
1837-
//! The inner pubkey (x-only, so no Y coordinate parity).
1837+
//! The internal pubkey (x-only, so no Y coordinate parity).
18381838
const XOnlyPubKey p{uint256(std::vector<unsigned char>(control.begin() + 1, control.begin() + TAPROOT_CONTROL_BASE_SIZE))};
18391839
//! The output pubkey (taken from the scriptPubKey).
18401840
const XOnlyPubKey q{uint256(program)};
@@ -1852,9 +1852,9 @@ static bool VerifyTaprootCommitment(const std::vector<unsigned char>& control, c
18521852
}
18531853
k = ss_branch.GetSHA256();
18541854
}
1855-
// Compute the tweak from the Merkle root and the inner pubkey.
1855+
// Compute the tweak from the Merkle root and the internal pubkey.
18561856
k = (CHashWriter(HASHER_TAPTWEAK) << MakeSpan(p) << k).GetSHA256();
1857-
// Verify that the output pubkey matches the tweaked inner pubkey, after correcting for parity.
1857+
// Verify that the output pubkey matches the tweaked internal pubkey, after correcting for parity.
18581858
return q.CheckPayToContract(p, k, control[0] & 1);
18591859
}
18601860

test/functional/feature_taproot.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,17 @@ def default_negflag(ctx):
177177
"""Default expression for "negflag": tap.negflag."""
178178
return get(ctx, "tap").negflag
179179

180-
def default_pubkey_inner(ctx):
181-
"""Default expression for "pubkey_inner": tap.inner_pubkey."""
182-
return get(ctx, "tap").inner_pubkey
180+
def default_pubkey_internal(ctx):
181+
"""Default expression for "pubkey_internal": tap.internal_pubkey."""
182+
return get(ctx, "tap").internal_pubkey
183183

184184
def default_merklebranch(ctx):
185185
"""Default expression for "merklebranch": tapleaf.merklebranch."""
186186
return get(ctx, "tapleaf").merklebranch
187187

188188
def default_controlblock(ctx):
189-
"""Default expression for "controlblock": combine leafversion, negflag, pubkey_inner, merklebranch."""
190-
return bytes([get(ctx, "leafversion") + get(ctx, "negflag")]) + get(ctx, "pubkey_inner") + get(ctx, "merklebranch")
189+
"""Default expression for "controlblock": combine leafversion, negflag, pubkey_internal, merklebranch."""
190+
return bytes([get(ctx, "leafversion") + get(ctx, "negflag")]) + get(ctx, "pubkey_internal") + get(ctx, "merklebranch")
191191

192192
def default_sighash(ctx):
193193
"""Default expression for "sighash": depending on mode, compute BIP341, BIP143, or legacy sighash."""
@@ -341,9 +341,9 @@ def default_scriptsig(ctx):
341341
"tapleaf": default_tapleaf,
342342
# The script to push, and include in the sighash, for a taproot script path spend.
343343
"script_taproot": default_script_taproot,
344-
# The inner pubkey for a taproot script path spend (32 bytes).
345-
"pubkey_inner": default_pubkey_inner,
346-
# The negation flag of the inner pubkey for a taproot script path spend.
344+
# The internal pubkey for a taproot script path spend (32 bytes).
345+
"pubkey_internal": default_pubkey_internal,
346+
# The negation flag of the internal pubkey for a taproot script path spend.
347347
"negflag": default_negflag,
348348
# The leaf version to include in the sighash (this does not affect the one in the control block).
349349
"leafversion": default_leafversion,
@@ -780,8 +780,8 @@ def mutate(spk):
780780
add_spender(spenders, "spendpath/negflag", tap=tap, leaf="128deep", **SINGLE_SIG, key=secs[0], failure={"negflag": lambda ctx: 1 - default_negflag(ctx)}, **ERR_WITNESS_PROGRAM_MISMATCH)
781781
# Test that bitflips in the Merkle branch invalidate it.
782782
add_spender(spenders, "spendpath/bitflipmerkle", tap=tap, leaf="128deep", **SINGLE_SIG, key=secs[0], failure={"merklebranch": bitflipper(default_merklebranch)}, **ERR_WITNESS_PROGRAM_MISMATCH)
783-
# Test that bitflips in the inner pubkey invalidate it.
784-
add_spender(spenders, "spendpath/bitflippubkey", tap=tap, leaf="128deep", **SINGLE_SIG, key=secs[0], failure={"pubkey_inner": bitflipper(default_pubkey_inner)}, **ERR_WITNESS_PROGRAM_MISMATCH)
783+
# Test that bitflips in the internal pubkey invalidate it.
784+
add_spender(spenders, "spendpath/bitflippubkey", tap=tap, leaf="128deep", **SINGLE_SIG, key=secs[0], failure={"pubkey_internal": bitflipper(default_pubkey_internal)}, **ERR_WITNESS_PROGRAM_MISMATCH)
785785
# Test that empty witnesses are invalid.
786786
add_spender(spenders, "spendpath/emptywit", tap=tap, leaf="128deep", **SINGLE_SIG, key=secs[0], failure={"witness": []}, **ERR_EMPTY_WITNESS)
787787
# Test that adding garbage to the control block invalidates it.

test/functional/test_framework/script.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -826,11 +826,11 @@ def taproot_tree_helper(scripts):
826826

827827
# A TaprootInfo object has the following fields:
828828
# - scriptPubKey: the scriptPubKey (witness v1 CScript)
829-
# - inner_pubkey: the inner pubkey (32 bytes)
830-
# - negflag: whether the pubkey in the scriptPubKey was negated from inner_pubkey+tweak*G (bool).
829+
# - internal_pubkey: the internal pubkey (32 bytes)
830+
# - negflag: whether the pubkey in the scriptPubKey was negated from internal_pubkey+tweak*G (bool).
831831
# - tweak: the tweak (32 bytes)
832832
# - leaves: a dict of name -> TaprootLeafInfo objects for all known leaves
833-
TaprootInfo = namedtuple("TaprootInfo", "scriptPubKey,inner_pubkey,negflag,tweak,leaves")
833+
TaprootInfo = namedtuple("TaprootInfo", "scriptPubKey,internal_pubkey,negflag,tweak,leaves")
834834

835835
# A TaprootLeafInfo object has the following fields:
836836
# - script: the leaf script (CScript or bytes)

0 commit comments

Comments
 (0)