Author

Topic: "Operation not valid with the current stack size" when spending from 2of3 (Read 1244 times)

staff
Activity: 3458
Merit: 6793
Just writing some code
Just an update on this:

The transaction is actually partially signed, but it isn't very obvious that it is with the errors showing up in the output. There isn't actually any issue here except that it looks scarier than before.
staff
Activity: 3458
Merit: 6793
Just writing some code
Does this mean nobody used signrawtransaction to sign multisigs like this for 18 months?
I don't think people use Core for Multisig. There are much better software for multisig.
sr. member
Activity: 261
Merit: 523
Does this mean nobody used signrawtransaction to sign multisigs like this for 18 months?
staff
Activity: 3458
Merit: 6793
Just writing some code
Great! Thanks for checking that. I submitted an issue for it on github: https://github.com/bitcoin/bitcoin/issues/9988 so that we can figure out how to fix it. The easiest solution would be to remove the VerifyScript call, but that may not be desirable.
sr. member
Activity: 261
Merit: 523
I tried it on 0.10.3 and it works

Code:

signrawtransaction '0100000001705da5d1160b1799d0c7e938abc24011ad3ce61c9e3d89556de3cbc67a9165ff0000000000ffffffff01706f9800000000001976a9146e2fe8ef5dcb05fd258e2f51d3f15ba3781cd96b88ac00000000' '[{"txid":"ff65917ac6cbe36d55893d9e1ce63cad1140c2ab38e9c7d099170b16d1a55d70","vout":0,"scriptPubKey":"a914b579aabfd350ed75ee056ff4d6d56718c74f55df87","redeemScript":"5221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453ae"}]' '["cMpfNfuasJcrCv8RKMG35C8YtUVpaheFbNMwDuBXVvdcjaeYE7oh"]'

{
"hex" : "0100000001705da5d1160b1799d0c7e938abc24011ad3ce61c9e3d89556de3cbc67a9165ff00000000b5004830450221009d4f252bc47a8ab7078c3f93929bd091da175ed115bbe4953a3704d1e8027e12022005ab1434847d64bc6551ce6044b970becad36fc0cf6380847c33b241a30fc085014c695221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453aeffffffff01706f9800000000001976a9146e2fe8ef5dcb05fd258e2f51d3f15ba3781cd96b88ac00000000",
"complete" : false
}


signing with other key

Code:
signrawtransaction '0100000001705da5d1160b1799d0c7e938abc24011ad3ce61c9e3d89556de3cbc67a9165ff00000000b5004830450221009d4f252bc47a8ab7078c3f93929bd091da175ed115bbe4953a3704d1e8027e12022005ab1434847d64bc6551ce6044b970becad36fc0cf6380847c33b241a30fc085014c695221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453aeffffffff01706f9800000000001976a9146e2fe8ef5dcb05fd258e2f51d3f15ba3781cd96b88ac00000000' '[{"txid":"ff65917ac6cbe36d55893d9e1ce63cad1140c2ab38e9c7d099170b16d1a55d70","vout":0,"scriptPubKey":"a914b579aabfd350ed75ee056ff4d6d56718c74f55df87","redeemScript":"5221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453ae"}]' '["cVM5Kaoim2MKzT8MxVHHAu9BixJKTJgMhqape1eHgjHGhFPkf2mn"]'

{
"hex" : "0100000001705da5d1160b1799d0c7e938abc24011ad3ce61c9e3d89556de3cbc67a9165ff00000000fdfd00004830450221009d4f252bc47a8ab7078c3f93929bd091da175ed115bbe4953a3704d1e8027e12022005ab1434847d64bc6551ce6044b970becad36fc0cf6380847c33b241a30fc08501473044022059c39a0fb206b088d9138a6838d57d30ef8fd913ed07eef9f7290d429f4584fc022069bf7ba1a8ae2b960ff62b36e3847e1109401b3746164b56f32c6e6075b14118014c695221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453aeffffffff01706f9800000000001976a9146e2fe8ef5dcb05fd258e2f51d3f15ba3781cd96b88ac00000000",
"complete" : true
}

So looks something changed in the meantime. I can try with other versions a bit later (with ones that still have the binaries uploaded)


EDIT: Tried it on 0.11.1 and it does not work, looks like you were right(?)

Code:
signrawtransaction '0100000001705da5d1160b1799d0c7e938abc24011ad3ce61c9e3d89556de3cbc67a9165ff0000000000ffffffff01706f9800000000001976a9146e2fe8ef5dcb05fd258e2f51d3f15ba3781cd96b88ac00000000' '[{"txid":"ff65917ac6cbe36d55893d9e1ce63cad1140c2ab38e9c7d099170b16d1a55d70","vout":0,"scriptPubKey":"a914b579aabfd350ed75ee056ff4d6d56718c74f55df87","redeemScript":"5221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453ae"}]' '["cMpfNfuasJcrCv8RKMG35C8YtUVpaheFbNMwDuBXVvdcjaeYE7oh"]'


{
"hex" : "0100000001705da5d1160b1799d0c7e938abc24011ad3ce61c9e3d89556de3cbc67a9165ff00000000b5004830450221009d4f252bc47a8ab7078c3f93929bd091da175ed115bbe4953a3704d1e8027e12022005ab1434847d64bc6551ce6044b970becad36fc0cf6380847c33b241a30fc085014c695221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453aeffffffff01706f9800000000001976a9146e2fe8ef5dcb05fd258e2f51d3f15ba3781cd96b88ac00000000",
"complete" : false,
"errors" : [
{
"txid" : "ff65917ac6cbe36d55893d9e1ce63cad1140c2ab38e9c7d099170b16d1a55d70",
"vout" : 0,
"scriptSig" : "004830450221009d4f252bc47a8ab7078c3f93929bd091da175ed115bbe4953a3704d1e8027e12022005ab1434847d64bc6551ce6044b970becad36fc0cf6380847c33b241a30fc085014c695221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453ae",
"sequence" : 4294967295,
"error" : "Operation not valid with the current stack size"
}
]
}
jr. member
Activity: 31
Merit: 1
It still returns the partially signed transaction, but doesn't put a 0x00 in place of the missing signature, so checkmultisig fails.
Adding the 0x00 will return a better error..
Code:
                                                                                                      V   V

signrawtransaction '0100000001705da5d1160b1799d0c7e938abc24011ad3ce61c9e3d89556de3cbc67a9165ff00000000b600004830450221009d4f252bc47a8ab7078c3f93929bd091da175ed115bbe4953a3704d1e8027e12022005ab1434847d64bc6551ce6044b970becad36fc0cf6380847c33b241a30fc085014c695221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453aeffffffff01706f9800000000001976a9146e2fe8ef5dcb05fd258e2f51d3f15ba3781cd96b88ac00000000' '[{"txid":"ff65917ac6cbe36d55893d9e1ce63cad1140c2ab38e9c7d099170b16d1a55d70","vout":0,"scriptPubKey":"a914b579aabfd350ed75ee056ff4d6d56718c74f55df87","redeemScript":"5221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453ae"}]'

*edit: forgot to add the better output Smiley

Code:
{
  "hex": "0100000001705da5d1160b1799d0c7e938abc24011ad3ce61c9e3d89556de3cbc67a9165ff00000000b600004830450221009d4f252bc47a8ab7078c3f93929bd091da175ed115bbe4953a3704d1e8027e12022005ab1434847d64bc6551ce6044b970becad36fc0cf6380847c33b241a30fc085014c695221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453aeffffffff01706f9800000000001976a9146e2fe8ef5dcb05fd258e2f51d3f15ba3781cd96b88ac00000000",
  "complete": false,
  "errors": [
    {
      "txid": "ff65917ac6cbe36d55893d9e1ce63cad1140c2ab38e9c7d099170b16d1a55d70",
      "vout": 0,
      "scriptSig": "00004830450221009d4f252bc47a8ab7078c3f93929bd091da175ed115bbe4953a3704d1e8027e12022005ab1434847d64bc6551ce6044b970becad36fc0cf6380847c33b241a30fc085014c695221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453ae",
      "sequence": 4294967295,
      "error": "Signature must be zero for failed CHECK(MULTI)SIG operation"
    }
  ]
}
staff
Activity: 3458
Merit: 6793
Just writing some code
Well that's interesting and probably a bug. It looks like this happens because the script is verified after signing, and a partially signed script is not valid.

Edit: Can you try this with older versions of Core, particularly 0.11.x and 0.10.x? The change to verify scripts was first introduced in 0.11.0, so I want to see if that is what's causing the issue.
sr. member
Activity: 261
Merit: 523
I've been trying to spend from a 2of3 multisig address, using the same procedure as from this gist: https://gist.github.com/gavinandresen/3966071

When trying to sign I get the "error": "Operation not valid with the current stack size"

What's really strange is I did this exact procedure some time in October 2015 and it worked. I must've been using a version of core around 0.10.2 or 0.11.0. If nobody has any idea I can try downgrading to one of those versions and seeing if it works.

Here's what I did:

Generated 3 keypairs (privkey, pubkey and address)

Code:
cMpfNfuasJcrCv8RKMG35C8YtUVpaheFbNMwDuBXVvdcjaeYE7oh
024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a
mgMZZtLSX1cU9jhAdQWMqMyoPv4JncZqcU

cVM5Kaoim2MKzT8MxVHHAu9BixJKTJgMhqape1eHgjHGhFPkf2mn
03c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771
mrdkuGp2wcXhcmtN7RwwUs7CYevJpYuLnV

cU4mHYwU2X1oTWBfYBGYFN69oYdrpWnBMrWd4nCoeRPUzmRY89vM
0256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b34
mospdWZdHtym59yMwUUi8w4HcWQxd7sQsv

Create 2of3 multisig address

Code:
createmultisig 2 '["024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a","03c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771","0256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b34"]'

{
  "address": "2N9nn3aMYzTjs2ccTRAvDUmdKykL9YjM2cj",
  "redeemScript": "5221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453ae"
}

Import address and fund it

Code:
importaddress 2N9nn3aMYzTjs2ccTRAvDUmdKykL9YjM2cj "" false

//sent 0.1btc to 2N9nn3aMYzTjs2ccTRAvDUmdKykL9YjM2cj

listunspent
[
  {
    "txid": "ff65917ac6cbe36d55893d9e1ce63cad1140c2ab38e9c7d099170b16d1a55d70",
    "vout": 0,
    "address": "2N9nn3aMYzTjs2ccTRAvDUmdKykL9YjM2cj",
    "account": "",
    "scriptPubKey": "a914b579aabfd350ed75ee056ff4d6d56718c74f55df87",
    "amount": 0.10000000,
    "confirmations": 1,
    "spendable": false,
    "solvable": false
  },

Create spending tx, sending to mqZa1zbDg5RHVYbX6ea1QxPuuxAyuGVSoK

Code:
createrawtransaction '[{"txid":"ff65917ac6cbe36d55893d9e1ce63cad1140c2ab38e9c7d099170b16d1a55d70","vout":0,"scriptPubKey":"a914b579aabfd350ed75ee056ff4d6d56718c74f55df87","redeemScript":"5221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453ae"}]' '{"mqZa1zbDg5RHVYbX6ea1QxPuuxAyuGVSoK":0.0999}'

0100000001705da5d1160b1799d0c7e938abc24011ad3ce61c9e3d89556de3cbc67a9165ff0000000000ffffffff01706f9800000000001976a9146e2fe8ef5dcb05fd258e2f51d3f15ba3781cd96b88ac00000000


decoderawtransaction 0100000001705da5d1160b1799d0c7e938abc24011ad3ce61c9e3d89556de3cbc67a9165ff0000000000ffffffff01706f9800000000001976a9146e2fe8ef5dcb05fd258e2f51d3f15ba3781cd96b88ac00000000
{
  "txid": "a8cfe9dd4fb8534caf4236b8fdf87d28aee5d74154eb88dab60c4de865bebfea",
  "hash": "a8cfe9dd4fb8534caf4236b8fdf87d28aee5d74154eb88dab60c4de865bebfea",
  "size": 85,
  "vsize": 85,
  "version": 1,
  "locktime": 0,
  "vin": [
    {
      "txid": "ff65917ac6cbe36d55893d9e1ce63cad1140c2ab38e9c7d099170b16d1a55d70",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "sequence": 4294967295
    }
  ],
  "vout": [
    {
      "value": 0.09990000,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 6e2fe8ef5dcb05fd258e2f51d3f15ba3781cd96b OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a9146e2fe8ef5dcb05fd258e2f51d3f15ba3781cd96b88ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "mqZa1zbDg5RHVYbX6ea1QxPuuxAyuGVSoK"
        ]
      }
    }
  ]
}

Sign with the first privkey

Code:
signrawtransaction '0100000001705da5d1160b1799d0c7e938abc24011ad3ce61c9e3d89556de3cbc67a9165ff0000000000ffffffff01706f9800000000001976a9146e2fe8ef5dcb05fd258e2f51d3f15ba3781cd96b88ac00000000' '[{"txid":"ff65917ac6cbe36d55893d9e1ce63cad1140c2ab38e9c7d099170b16d1a55d70","vout":0,"scriptPubKey":"a914b579aabfd350ed75ee056ff4d6d56718c74f55df87","redeemScript":"5221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453ae"}]' '["cMpfNfuasJcrCv8RKMG35C8YtUVpaheFbNMwDuBXVvdcjaeYE7oh"]'


{
  "hex": "0100000001705da5d1160b1799d0c7e938abc24011ad3ce61c9e3d89556de3cbc67a9165ff00000000b5004830450221009d4f252bc47a8ab7078c3f93929bd091da175ed115bbe4953a3704d1e8027e12022005ab1434847d64bc6551ce6044b970becad36fc0cf6380847c33b241a30fc085014c695221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453aeffffffff01706f9800000000001976a9146e2fe8ef5dcb05fd258e2f51d3f15ba3781cd96b88ac00000000",
  "complete": false,
  "errors": [
    {
      "txid": "ff65917ac6cbe36d55893d9e1ce63cad1140c2ab38e9c7d099170b16d1a55d70",
      "vout": 0,
      "scriptSig": "004830450221009d4f252bc47a8ab7078c3f93929bd091da175ed115bbe4953a3704d1e8027e12022005ab1434847d64bc6551ce6044b970becad36fc0cf6380847c33b241a30fc085014c695221024c5965fb18701569ec09e8d2979c45e3d6e0c60ddb3c9d6af0692124d3890e8a2103c9084cf82f74f764829a7d3c842462e03f4bbaf59981cb3b98cd3974438e5771210256d87a1997bad87ebdd409a3437ecec02885300a1bb0a1159e289ae66af78b3453ae",
      "sequence": 4294967295,
      "error": "Operation not valid with the current stack size"
    }
  ]
}


As far as I can tell, everything is done in exactly the same was as in Gavin's gist from 2012, and I did this procedure in October 2015 and it worked.
Jump to: