Problems with Signature Verification Using SigHash SINGLE on Multi-Input Tx

2 replies 491 views
degen2009Member
Posts: 5 · Reputation: 119
#1Mar 14, 2025, 08:11 PM
I just sent out a transaction via Sparrow Wallet, check it out here: https://mempool.space/es/testnet4/tx/4942f8db3e32bd1f114fbfb5c500e0f9cd06c3c235ffe77b07087750b86cc0ea This transaction has 3 inputs and 2 outputs, and I used the SINGLE flag (0x03) to sign all the inputs. But when I try to verify this transaction with a custom script I wrote, the verification fails for the first two inputs. My script handles all SigHash types, including variations like SINGLE | ANYONECANPAY, ALL, multiple inputs, etc., and it usually works like 99% of the time. But in this specific situation where the transaction is signed with SINGLE and has more than one input, it just doesn’t verify. I think the problem might be in how the preimage for each input is put together. For the inputs where the index is greater than the number of outputs, the verification actually works (the signed message in these cases is "1"). Here’s the preimage for each input and a little breakdown: First Input Hash-Preimage: Raw Preimage: 0100000003d38e64afa39dd966f96e07bf56ae44bc3d402630771480f461389edff8a0051e010000001976a914ac2129222b94c90222c18c1f1a52b4139643d2f088acffffffff11ac3e436400735e8edc830a37f60fcab2098c871d6687c08507afe5168d110e0000000000ffffffff11ac3e436400735e8edc830a37f60fcab2098c871d6687c08507afe5168d110e0100000000ffffffff0158980000000000001976a914487b2cf05b1dc2b50c3c3019e578be45c29d03ff88ac0000000003000000 Breakdown: - 01000000 Version - 03 Number of Inputs - First Input: d38e64afa39dd966f96e07bf56ae44bc3d402630771480f461389edff8a0051e Txi
6 Reply Quote Share
gr3g.0rbitHero Member
Posts: 1025 · Reputation: 2646
#2Mar 14, 2025, 08:23 PM
I think it's the nSequence values of the inputs. In the first Input's preimage, the nSequence of inputs 2nd and 3rd should be 0x00000000 instead of 0xffffffff. Reference: https://en.bitcoin.it/wiki/OP_CHECKSIG#Procedure_for_Hashtype_SIGHASH_SINGLE It's also worth checking number 1 and 2 in the article's 'procedure' or this image (image link)
0 Reply Quote Share
degen2009Member
Posts: 5 · Reputation: 119
#3Mar 14, 2025, 10:40 PM
Many thanks! The issue was there. Now works perfectly. For anyone interested, the correct preimages for each input are: First Input: 0100000003d38e64afa39dd966f96e07bf56ae44bc3d402630771480f461389edff8a0051e01000 0001976a914ac2129222b94c90222c18c1f1a52b4139643d2f088acffffffff11ac3e436400735e 8edc830a37f60fcab2098c871d6687c08507afe5168d110e00000000000000000011ac3e4364007 35e8edc830a37f60fcab2098c871d6687c08507afe5168d110e0100000000000000000158980000 000000001976a914487b2cf05b1dc2b50c3c3019e578be45c29d03ff88ac0000000003000000 Second Input: 0100000003d38e64afa39dd966f96e07bf56ae44bc3d402630771480f461389edff8a0051e01000 000000000000011ac3e436400735e8edc830a37f60fcab2098c871d6687c08507afe5168d110e00 0000001976a914c103e57c094061209b419e5ca559704a8a22f3f988acffffffff11ac3e4364007 35e8edc830a37f60fcab2098c871d6687c08507afe5168d110e01000000000000000002ffffffff ffffffff0058980000000000001976a914d80f48340dd7ee6c7fae287342d3eeb1d4d887e288ac0 000000003000000 Happy New Year!
4 Reply Quote Share

Related topics