Post
Topic
Board Development & Technical Discussion
Merits 8 from 3 users
Re: help! about multisig address spending using bitcoind
by
HCP
on 11/06/2019, 21:28:34 UTC
⭐ Merited by joniboini (5) ,bones261 (2) ,ETFbitcoin (1)
I don't have a MultiSig setup to test with... so I'm not 100% sure on that... reading the docs further it seems that there is still a "complete: true/false" value in the output from signrawtransactionwithkey:
Result:
{
  "hex" : "value",                  (string) The hex-encoded raw transaction with signature(s)
  "complete" : true|false,          (boolean) If the transaction has a complete set of signatures
  "errors" : [                      (json array of objects) Script verification errors (if there are any)
...
which would seem to imply that you should still be able to partially sign the transaction... Huh

I'll go setup up a multisig test address in Bitcoin Core (and wait for it to all sync up Tongue) and see if I can replicate your issue using signrawtransactionwithkey.



EDIT: Ok, so I set it all up and am indeed getting the same error "Unable to sign input, invalid stack size (possibly missing key)" when trying to sign the hex from createrawtransaction. It seems that to use signrawtransactionwithkey, you MUST also provide the "prevtxs" JSON array:
Quote
3. prevtxs                          (json array, optional) A json array of previous dependent transaction outputs
[
       {                            (json object)
         "txid": "hex",             (string, required) The transaction id
         "vout": n,                 (numeric, required) The output number
         "scriptPubKey": "hex",     (string, required) script key
         "redeemScript": "hex",     (string) (required for P2SH) redeem script
         "witnessScript": "hex",    (string) (required for P2WSH or P2SH-P2WSH) witness script
         "amount": amount,          (numeric or string, required) The amount spent
       },
       ...
     ]

So in my case... I had to use the command:
Code:
signrawtransactionwithkey "0200000001b6be4571434809a4590ce1cc0bd41d1c9bd2d20414df9c7b246b73d8b1b651a90000000000fdffffff019e959800000000001976a9142bd2a8a129cc97f18bd9c9820910a5d178b6259688ac00000000" '["cPz_FIRST_PRIVKEY_HERE_4EK"]' '[{"txid":"a951b6b1d8736b247b9cdf1404d2d29b1c1dd40bcce10c59a40948437145beb6","vout":0,"scriptPubKey":"a914_MULTISIG_SCRIPT_PUBKEY_HERE_e387","redeemScript":"5221_MULTISIG_REDEEM_SCRIPT_HERE_853ae","amount":10000000}]'


This gave the following output... NOTE: the "error" is normal! It's basically a warning that the transaction is only partially signed.
Quote
{
  "hex": "0200000001b6be4571434809a4590ce1cc0bd41d1c9bd2d20414df9c7b246b73d8b1b651a900000 000b500473044022040553dd608c655c94c5b1b7699a018256ce9439f909f4cc8ecef78dd453b3d 0502204a58ce1bfdf694f1626d57b34bf2d16cab24d3678096c4624bc0b6cbed32c5f901004c695 22102ccbf87a4c99e092e1d2bcc838b7fe051bc19b2d83931ea163452fe795720e24821036ece86 305c5604739805ec23926d902ceab41b6eb1d497c1d8160297072a38ed210353be0e12b29e46f73 fd06a9be455dd221b1effdbee287a9ea3827baf16f556a853aefdffffff019e9598000000000019 76a9142bd2a8a129cc97f18bd9c9820910a5d178b6259688ac00000000",
  "complete": false,
  "errors": [
    {
      "txid": "a951b6b1d8736b247b9cdf1404d2d29b1c1dd40bcce10c59a40948437145beb6",
      "vout": 0,
      "witness": [
      ],
      "scriptSig": "00473044022040553dd608c655c94c5b1b7699a018256ce9439f909f4cc8ecef78dd453b3d05022 04a58ce1bfdf694f1626d57b34bf2d16cab24d3678096c4624bc0b6cbed32c5f901004c69522102 ccbf87a4c99e092e1d2bcc838b7fe051bc19b2d83931ea163452fe795720e24821036ece86305c5 604739805ec23926d902ceab41b6eb1d497c1d8160297072a38ed210353be0e12b29e46f73fd06a 9be455dd221b1effdbee287a9ea3827baf16f556a853ae",
      "sequence": 4294967293,
      "error": "Signature must be zero for failed CHECK(MULTI)SIG operation"
    }
  ]
}

Using the "new" hex... I was able to sign with the 2nd privkey using signrawtransactionwithkey:
Code:
signrawtransactionwithkey "0200000001b6be4571434809a4590ce1cc0bd41d1c9bd2d20414df9c7b246b73d8b1b651a900000000b500473044022040553dd608c655c94c5b1b7699a018256ce9439f909f4cc8ecef78dd453b3d0502204a58ce1bfdf694f1626d57b34bf2d16cab24d3678096c4624bc0b6cbed32c5f901004c69522102ccbf87a4c99e092e1d2bcc838b7fe051bc19b2d83931ea163452fe795720e24821036ece86305c5604739805ec23926d902ceab41b6eb1d497c1d8160297072a38ed210353be0e12b29e46f73fd06a9be455dd221b1effdbee287a9ea3827baf16f556a853aefdffffff019e959800000000001976a9142bd2a8a129cc97f18bd9c9820910a5d178b6259688ac00000000" '["cPtc_SECOND_PRIVKEY_HERE_ppC"]' '[{"txid":"a951b6b1d8736b247b9cdf1404d2d29b1c1dd40bcce10c59a40948437145beb6","vout":0,"scriptPubKey":"a914_MULTISIG_SCRIPT_PUBKEY_HERE_e387","redeemScript":"52210_MULTISIG_REDEEMSCRIPT_HERE_853ae","amount":10000000}]'


This gave the following output:
Quote
{
  "hex": "0200000001b6be4571434809a4590ce1cc0bd41d1c9bd2d20414df9c7b246b73d8b1b651a900000 000fc00473044022040553dd608c655c94c5b1b7699a018256ce9439f909f4cc8ecef78dd453b3d 0502204a58ce1bfdf694f1626d57b34bf2d16cab24d3678096c4624bc0b6cbed32c5f9014730440 22032d6775ce11878d3c155516b53026f360168fc40015f0d116726041b9e25583302200e3d6fe3 f73105c0d072736d15154b108c2249ae260931ab04f31e7b1e9799e4014c69522102ccbf87a4c99 e092e1d2bcc838b7fe051bc19b2d83931ea163452fe795720e24821036ece86305c5604739805ec 23926d902ceab41b6eb1d497c1d8160297072a38ed210353be0e12b29e46f73fd06a9be455dd221 b1effdbee287a9ea3827baf16f556a853aefdffffff019e959800000000001976a9142bd2a8a129 cc97f18bd9c9820910a5d178b6259688ac00000000",
  "complete": true
}


which then failed to send because my fee was too small!!?! Tongue Roll Eyes
Quote
min relay fee not met, 226 < 337 (code 66) (code -26)

After fixing the fee, it all worked fine Wink
TXID: fc6360591fb5047955c5a974f8b2e5003bcac43f335119b250ce7344c9d901bf