Skip to content

Commit fb75bae

Browse files
instagibbsjgriffiths
authored andcommitted
tx: Fix BIP118 ANYPREVOUTANYSCRIPT sighash
In the current code anytime sh_anyprevout_anyscript is true, sh_anyonecanpay will also be true. Therefore it will fall through and hash the prevout erroneously. Fix this by checking for APOAS first.
1 parent 944f266 commit fb75bae

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/tx_io.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,10 @@ static int bip341_signature_hash(
910910
}
911911
/* Input data */
912912
hash_u8(&io.ctx, (tapleaf_script ? 1 : 0) * 2 + (annex ? 1 : 0)); /* spend_type */
913-
if (sh_anyonecanpay || sh_anyprevout) {
913+
if (sh_anyprevout_anyscript) {
914+
// Note that this means sh_anyonecanpay is set so we check this first
915+
hash_le32(&io.ctx, tx->inputs[index].sequence); /* nSequence */
916+
} else if (sh_anyonecanpay || sh_anyprevout) {
914917
if (sh_anyonecanpay) {
915918
#ifdef BUILD_ELEMENTS
916919
if (is_elements)
@@ -925,8 +928,6 @@ static int bip341_signature_hash(
925928
else
926929
#endif
927930
txio_hash_input(&io, tx, index, scripts, values, NULL, 0, WALLY_SIGTYPE_SW_V1);
928-
} else if (sh_anyprevout_anyscript) {
929-
hash_le32(&io.ctx, tx->inputs[index].sequence); /* nSequence */
930931
} else {
931932
hash_le32(&io.ctx, index); /* input_index */
932933
}

0 commit comments

Comments
 (0)