1
I am trying to sign a raw transaction that spends output #2 (txindex 1) from this transaction: 267c6d75851efa18afb7edeb2da00c09afc575231db84b3277fc7ea3e174ecbd
The output is a 1-of-4 multisig P2SH and I think I may have a mistake in the transaction structure used to generate the signature. The signature I calculate is different (as in cryptographically different) to the one that bitcoin core gives me using signrawtransaction.
As I see it this is the transaction structure which must be signed:
Version: 01000000
TxIn: 01 bdec74e1a37efc77324bb81d2375c5af090ca02debedb7af18fa1e85756d7c26 01000000
subScript: 17 a9 14 37fe3f20433380be4c742c978d3a9712c509656e 87
Sequence: ffffffff
TxOut: OUTPUTDATA
Locktime: 00000000
Hashtype: 01000000
The double-sha256 value used to calculate the signature is 9d384de385512525b4faf08c97651e410e77f2906aa8baeefdee151cc0994655
But the Bitcoin network rejects my transaction calculated from this transaction structure.
I will happily provide more information such as redeemScript and pubKeys/privateKeys if the mistake should not be in the transaction structure.
Any help is appreciated! Thanks!
I still cannot make it work. The redeemScript that hashes to "37fe3f20433380be4c742c978d3a9712c509656e" is "512102930a11e92103daefde0d30b552f57d303e94a128e763ca9e69ff2006446934442103e74d2113dec75d75cde09a5b46297b1067e4b8b35e63c4c32b8cdbadfdffda1e2103067fcc39ee36d2417684511d1055fdc7d35e54911cb9de9ae30c988b666f675c2102dfb1c2a1c3456c8cb76714706dba77b3f4e7fe5afffc2503b121323a48ebbdcf54ae", with a length of "8b". – Bjarne – 2017-10-09T19:30:18.767
My new preimage is as above but changning subScript to: "4c8b512102930a11e92103daefde0d30b552f57d303e94a128e763ca9e69ff2006446934442103e74d2113dec75d75cde09a5b46297b1067e4b8b35e63c4c32b8cdbadfdffda1e2103067fcc39ee36d2417684511d1055fdc7d35e54911cb9de9ae30c988b666f675c2102dfb1c2a1c3456c8cb76714706dba77b3f4e7fe5afffc2503b121323a48ebbdcf54ae" – Bjarne – 2017-10-09T19:31:24.393
But I still get the same error messages and when using the valid signature from bitcoin core cannot validate it using this preimage. – Bjarne – 2017-10-09T19:31:58.157
What is the exact error that you get when you try to send the transaction? – Andrew Chow – 2017-10-09T19:39:11.150
@Inaki It will be useful if you can provide the whole serialized transaction. – sr-gi – 2017-10-10T03:07:51.873
Thanks for offering me help! I have created a txt-message here: https://pastebin.com/raw/21ucHYW7 I have also tried to take a P2SH from the blockchain that is being spent and try to recreate the preimage manually to verify the provided signatures. But I can also not get that to work. If someone could make a step-by-step showing how the signature is calculated for any P2SH output being spend that this would also help me a lot!
– Bjarne – 2017-10-10T14:33:02.1671After checking it for a hundred times I saw that in the pastebin I uploaded I forgot to add the OP_0 (0x00) in the front of the scriptSig. After adding this it works! Thanks a lot for pointing out that the redeemScript is used in the preimage! This was the final signed transaction: – Bjarne – 2017-10-10T15:00:36.720
10100000001bdec74e1a37efc77324bb81d2375c5af090ca02debedb7af18fa1e85756d7c2601000000d60047304402204887a352b503da6f212c09ed7e973384d7660f62d2319a15b968252012d134810220695130bc101f44348203c51a50e46f37ed4bc5622795f5dfbddef2affb27e2a8014c8b512102930a11e92103daefde0d30b552f57d303e94a128e763ca9e69ff2006446934442103e74d2113dec75d75cde09a5b46297b1067e4b8b35e63c4c32b8cdbadfdffda1e2103067fcc39ee36d2417684511d1055fdc7d35e54911cb9de9ae30c988b666f675c2102dfb1c2a1c3456c8cb76714706dba77b3f4e7fe5afffc2503b121323a48ebbdcf54aeffffffff01c05d00000000000017a914de5462e6e84cdab5064220343b9331a3af6dbbf18700000000 – Bjarne – 2017-10-10T15:05:06.520