Skip to content

Commit fadf621

Browse files
author
MarcoFalke
committed
test: Make leaf_script mandatory when scriptpath is set in TaprootSignatureMsg
This removes the default value, because there should not be a use-case to fall back to a an empty leaf_script by default. (If there was, it could trivially be added back)
1 parent 4c62f4b commit fadf621

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

test/functional/feature_taproot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def default_sigmsg(ctx):
231231
codeseppos = get(ctx, "codeseppos")
232232
leaf_ver = get(ctx, "leafversion")
233233
script = get(ctx, "script_taproot")
234-
return TaprootSignatureMsg(tx, utxos, hashtype, idx, scriptpath=True, script=script, leaf_ver=leaf_ver, codeseparator_pos=codeseppos, annex=annex)
234+
return TaprootSignatureMsg(tx, utxos, hashtype, idx, scriptpath=True, leaf_script=script, leaf_ver=leaf_ver, codeseparator_pos=codeseppos, annex=annex)
235235
else:
236236
return TaprootSignatureMsg(tx, utxos, hashtype, idx, scriptpath=False, annex=annex)
237237
elif mode == "witv0":

test/functional/test_framework/script.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ def BIP341_sha_sequences(txTo):
810810
def BIP341_sha_outputs(txTo):
811811
return sha256(b"".join(o.serialize() for o in txTo.vout))
812812

813-
def TaprootSignatureMsg(txTo, spent_utxos, hash_type, input_index = 0, scriptpath = False, script = CScript(), codeseparator_pos = -1, annex = None, leaf_ver = LEAF_VERSION_TAPSCRIPT):
813+
def TaprootSignatureMsg(txTo, spent_utxos, hash_type, input_index=0, *, scriptpath=False, leaf_script=None, codeseparator_pos=-1, annex=None, leaf_ver=LEAF_VERSION_TAPSCRIPT):
814814
assert (len(txTo.vin) == len(spent_utxos))
815815
assert (input_index < len(txTo.vin))
816816
out_type = SIGHASH_ALL if hash_type == 0 else hash_type & 3
@@ -829,7 +829,7 @@ def TaprootSignatureMsg(txTo, spent_utxos, hash_type, input_index = 0, scriptpat
829829
spend_type = 0
830830
if annex is not None:
831831
spend_type |= 1
832-
if (scriptpath):
832+
if scriptpath:
833833
spend_type |= 2
834834
ss += bytes([spend_type])
835835
if in_type == SIGHASH_ANYONECANPAY:
@@ -846,11 +846,11 @@ def TaprootSignatureMsg(txTo, spent_utxos, hash_type, input_index = 0, scriptpat
846846
ss += sha256(txTo.vout[input_index].serialize())
847847
else:
848848
ss += bytes(0 for _ in range(32))
849-
if (scriptpath):
850-
ss += TaggedHash("TapLeaf", bytes([leaf_ver]) + ser_string(script))
849+
if scriptpath:
850+
ss += TaggedHash("TapLeaf", bytes([leaf_ver]) + ser_string(leaf_script))
851851
ss += bytes([0])
852852
ss += codeseparator_pos.to_bytes(4, "little", signed=True)
853-
assert len(ss) == 175 - (in_type == SIGHASH_ANYONECANPAY) * 49 - (out_type != SIGHASH_ALL and out_type != SIGHASH_SINGLE) * 32 + (annex is not None) * 32 + scriptpath * 37
853+
assert len(ss) == 175 - (in_type == SIGHASH_ANYONECANPAY) * 49 - (out_type != SIGHASH_ALL and out_type != SIGHASH_SINGLE) * 32 + (annex is not None) * 32 + scriptpath * 37
854854
return ss
855855

856856
def TaprootSignatureHash(*args, **kwargs):

0 commit comments

Comments
 (0)