Skip to content

Commit e538fa8

Browse files
committed
Update Simple Signer Algorithm for SegWitv0 inputs
It is no longer expected that SegWitV0 inputs have no witness-utxo field. Reverting the order of checks avoids this assumption (while still relying on the mandatory lack of witness-utxo for legacy inputs).
1 parent aa5b0a1 commit e538fa8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

bip-0174.mediawiki

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -718,15 +718,8 @@ sign_non_witness(script_code, i):
718718
if IsMine(key) and IsAcceptable(sighash_type):
719719
sign(non_witness_sighash(script_code, i, input))
720720

721-
for input,i in enumerate(psbt.inputs):
722-
if non_witness_utxo.exists:
723-
assert(sha256d(non_witness_utxo) == psbt.tx.input[i].prevout.hash)
724-
if redeemScript.exists:
725-
assert(non_witness_utxo.vout[psbt.tx.input[i].prevout.n].scriptPubKey == P2SH(redeemScript))
726-
sign_non_witness(redeemScript, i)
727-
else:
728-
sign_non_witness(non_witness_utxo.vout[psbt.tx.input[i].prevout.n].scriptPubKey, i)
729-
else if witness_utxo.exists:
721+
for input, i in enumerate(psbt.inputs):
722+
if witness_utxo.exists:
730723
if redeemScript.exists:
731724
assert(witness_utxo.scriptPubKey == P2SH(redeemScript))
732725
script = redeemScript
@@ -737,6 +730,13 @@ for input,i in enumerate(psbt.inputs):
737730
else if IsP2WSH(script):
738731
assert(script == P2WSH(witnessScript))
739732
sign_witness(witnessScript, i)
733+
else if non_witness_utxo.exists:
734+
assert(sha256d(non_witness_utxo) == psbt.tx.input[i].prevout.hash)
735+
if redeemScript.exists:
736+
assert(non_witness_utxo.vout[psbt.tx.input[i].prevout.n].scriptPubKey == P2SH(redeemScript))
737+
sign_non_witness(redeemScript, i)
738+
else:
739+
sign_non_witness(non_witness_utxo.vout[psbt.tx.input[i].prevout.n].scriptPubKey, i)
740740
else:
741741
assert False
742742
</pre>

0 commit comments

Comments
 (0)