What does "operation not valid with the current stack size" mean? I'm asking this question to help others who run into the same problem I ran into.  The error is, at least sometimes, misleading and might not be accurate.

The context in which this error is relevant is signing a raw transaction that you created with bitcoin software.  This is a common practice for those who are paranoid, like me.  Here's the basic procedure:


Identify the TxOuts (txid and vout pairs) that you want to spend.
Use https://chainquery.com/bitcoin-api/createrawtransaction or something similar to create a hex string.
Use https://chainquery.com/bitcoin-api/signrawtransaction along with the private keys required to spend those unspent TxOuts.


In that third step, you might get this "operation not valid with the current stack size" error.
The signrawtransaction RPC will verify the input scripts of the transaction after it signs it. If the transaction has not been fully signed (i.e. it isn't complete), then the script verification will fail and produce this error.

This also happens with multisig transactions. When you don't have enough signatures, the script will fail to verify with the error that you see.

See also: https://github.com/bitcoin/bitcoin/issues/9988