test: cover invalid codesep positions for signature in taproot
This commit is contained in:
1 parent
9b1a7c3e8d
commit
81e5c8385b
2 files changed
+5
-3
No files matched your search
@@ -431,7 +431,7 @@ DEFAULT_CONTEXT = {
|
|||||||
# The annex (only when mode=="taproot").
|
# The annex (only when mode=="taproot").
|
||||||
"annex": None,
|
"annex": None,
|
||||||
# The codeseparator position (only when mode=="taproot").
|
# The codeseparator position (only when mode=="taproot").
|
||||||
"codeseppos": -1,
|
"codeseppos": 0xffffffff,
|
||||||
# Which OP_CODESEPARATOR is the last executed one in the script (in legacy/P2SH/P2WSH).
|
# Which OP_CODESEPARATOR is the last executed one in the script (in legacy/P2SH/P2WSH).
|
||||||
"codesepnum": -1,
|
"codesepnum": -1,
|
||||||
# The redeemscript to add to the scriptSig (if P2SH; None implies not P2SH).
|
# The redeemscript to add to the scriptSig (if P2SH; None implies not P2SH).
|
||||||
@@ -779,6 +779,8 @@ def spenders_taproot_active():
|
|||||||
add_spender(spenders, "sighash/codesep_pk", tap=tap, leaf="codesep_pk", key=secs[1], codeseppos=0, **common, **SINGLE_SIG, **SIGHASH_BITFLIP, **ERR_SCHNORR_SIG)
|
add_spender(spenders, "sighash/codesep_pk", tap=tap, leaf="codesep_pk", key=secs[1], codeseppos=0, **common, **SINGLE_SIG, **SIGHASH_BITFLIP, **ERR_SCHNORR_SIG)
|
||||||
add_spender(spenders, "sighash/branched_codesep/left", tap=tap, leaf="branched_codesep", key=secs[0], codeseppos=3, **common, inputs=[getter("sign"), b'\x01'], **SIGHASH_BITFLIP, **ERR_SCHNORR_SIG)
|
add_spender(spenders, "sighash/branched_codesep/left", tap=tap, leaf="branched_codesep", key=secs[0], codeseppos=3, **common, inputs=[getter("sign"), b'\x01'], **SIGHASH_BITFLIP, **ERR_SCHNORR_SIG)
|
||||||
add_spender(spenders, "sighash/branched_codesep/right", tap=tap, leaf="branched_codesep", key=secs[1], codeseppos=6, **common, inputs=[getter("sign"), b''], **SIGHASH_BITFLIP, **ERR_SCHNORR_SIG)
|
add_spender(spenders, "sighash/branched_codesep/right", tap=tap, leaf="branched_codesep", key=secs[1], codeseppos=6, **common, inputs=[getter("sign"), b''], **SIGHASH_BITFLIP, **ERR_SCHNORR_SIG)
|
||||||
|
add_spender(spenders, "sighash/codesep_pk_wrongpos1", tap=tap, leaf="codesep_pk", key=secs[1], codeseppos=0, **common, **SINGLE_SIG, failure={"codeseppos": 1}, **ERR_SCHNORR_SIG)
|
||||||
|
add_spender(spenders, "sighash/codesep_pk_wrongpos2", tap=tap, leaf="codesep_pk", key=secs[1], codeseppos=0, **common, **SINGLE_SIG, failure={"codeseppos": 0xfffffffe}, **ERR_SCHNORR_SIG)
|
||||||
|
|
||||||
# Reusing the scripts above, test that various features affect the sighash.
|
# Reusing the scripts above, test that various features affect the sighash.
|
||||||
add_spender(spenders, "sighash/annex", tap=tap, leaf="pk_codesep", key=secs[1], hashtype=hashtype, standard=False, **SINGLE_SIG, annex=bytes([ANNEX_TAG]), failure={"sighash": override(default_sighash, annex=None)}, **ERR_SCHNORR_SIG)
|
add_spender(spenders, "sighash/annex", tap=tap, leaf="pk_codesep", key=secs[1], hashtype=hashtype, standard=False, **SINGLE_SIG, annex=bytes([ANNEX_TAG]), failure={"sighash": override(default_sighash, annex=None)}, **ERR_SCHNORR_SIG)
|
||||||
@@ -1280,7 +1282,7 @@ def spenders_taproot_active():
|
|||||||
script = [pubs[1]]
|
script = [pubs[1]]
|
||||||
inputs = []
|
inputs = []
|
||||||
opcount = 1
|
opcount = 1
|
||||||
codeseppos = -1
|
codeseppos = 0xffffffff
|
||||||
for pos, op in enumerate(ops):
|
for pos, op in enumerate(ops):
|
||||||
if op == -1:
|
if op == -1:
|
||||||
codeseppos = opcount
|
codeseppos = opcount
|
||||||
|
|||||||
@@ -847,7 +847,7 @@ def TaprootSignatureMsg(txTo, spent_utxos, hash_type, input_index=0, *, scriptpa
|
|||||||
if scriptpath:
|
if scriptpath:
|
||||||
ss += TaggedHash("TapLeaf", bytes([leaf_ver]) + ser_string(leaf_script))
|
ss += TaggedHash("TapLeaf", bytes([leaf_ver]) + ser_string(leaf_script))
|
||||||
ss += bytes([0])
|
ss += bytes([0])
|
||||||
ss += codeseparator_pos.to_bytes(4, "little", signed=True)
|
ss += codeseparator_pos.to_bytes(4, "little", signed=False)
|
||||||
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
|
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
|
||||||
return ss
|
return ss
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user