Author

Topic: issue "operation not valid with the current stack size" (Read 275 times)

HCP
legendary
Activity: 2086
Merit: 4363
I created the wallet myself.
...
My wallet is Electrum 4.1.5 [standard]

The transaction is imported
So this transaction was not created by your Electrum wallet at all... you're just trying to broadcast the transaction using your Electrum wallet.

So, the important question here is, where exactly did you import this transaction from? Huh Did someone or some website/service send this to you claiming you could broadcast it to receive funds? If so, and you have given someone money/services/goods for it... you've probably been scammed. Undecided

Or did you create this transaction yourself in another wallet? If so, what wallet? Huh
legendary
Activity: 3472
Merit: 10611
Yes, maybe left it as it is because there was no efficient way to validate the transaction.
Not just efficiency but I think the biggest problem is implementing a complete verifier which could verify transactions just like a full node would. That implementation is very hard and time consuming and you may end up with a lot of bugs.
legendary
Activity: 2618
Merit: 6452
Self-proclaimed Genius
Now the issue: Electrum has a bug where you can immediately broadcast an imported RAW transaction (except PSBT) whether it's signed correctly or not.
It is not a bug, it is a feature of this SPV wallet. -snip-
That's a weird feature then. Yes, maybe left it as it is because there was no efficient way to validate the transaction.
There's now testmempoolaccept RPC which they can utilize to fix that, but not all servers use Bitcoin Core or supported Bitcoin Core versions.

Good thing they moved to psbt.
legendary
Activity: 3472
Merit: 10611
Now the issue: Electrum has a bug where you can immediately broadcast an imported RAW transaction (except PSBT) whether it's signed correctly or not.
It is not a bug, it is a feature of this SPV wallet. It doesn't verify the transaction before broadcasting because it could require downloading the UTXOs from the Electrum node first and also it has to have a complete implementation of bitcoin scripts and the evaluator to validate the transaction. So it is easier to just send the tx to the node and let the node itself fetch the UTXOs itself and verify it.
legendary
Activity: 2618
Merit: 6452
Self-proclaimed Genius
My wallet is electrum 4.1.5 standalone version.
The raw transaction:

-snip-

The transaction is imported
Since the transaction has a signature,
I assume that it was signed with one prvKey before the raw transaction (HEX) is imported to Electrum.

Now the issue: Electrum has a bug where you can immediately broadcast an imported RAW transaction (except PSBT) whether it's signed correctly or not.
If the transaction is in HEX, "broadcast" button will be available even if a transaction is unsigned/partially signed.
But since it's invalid, the server where you're connected to wont relay it.

With that, it should be signed once more by one of the other two cosigners.
legendary
Activity: 3472
Merit: 10611
Which script? I decoded it as shown above, but I don't see any OP codes. Is it that "asm" that I have to decode?
I've located those hexadecimal characters, but I don't know how to decode them.
That's because you should start from the output that is being spent so that you know how to interpret the signature script. When we know that the output type being spent is P2SH then we know that the top stack item is a redeem script. Then we know that redeem scripts are being pushed to the stack as you push any other arbitrary data (like pushing a hash). So when you just interpret the signature script (which is what the block explorers do) you only see the data pushes without the redeem script being interpreted separately for you to see those OP codes.
legendary
Activity: 2268
Merit: 18771
If you want to learn more about how scripts are written and the different opcodes used, then here are a few good resources.

I would start here - https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch06.asciidoc#transaction-scripts-and-script-language. This section of Mastering Bitcoin gives a good breakdown of simple scripts, and how things are pushed to the stack and executed.
The next chapter goes in to things in much more detail, including an example of a multi-sig script - https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch07.asciidoc.
You can see a list of all the opcodes currently used in the source code here: https://github.com/bitcoin/bitcoin/blob/fdd80b0a53b4af0b29cb6e03118e2456d053a757/src/script/script.h#L67
And this wiki page gives a nice summary of what all the different opcodes do: https://en.bitcoin.it/wiki/Script
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
From the script.

Which script? I decoded it as shown above, but I don't see any OP codes. Is it that "asm" that I have to decode?
I've located those hexadecimal characters, but I don't know how to decode them.
legendary
Activity: 2268
Merit: 18771
Excuse from asking, but how did you get that?
From the script.

The first part of the script is the signatures, and the second part gives you the multi-sig requirements. Specifically, as follows:

4C - OP_PUSHDATA1
69 - Push 105 bytes
52 - OP_2
21 - Push 33 bytes
33 bytes of public key 1
21 - Push 33 bytes
33 bytes of public key 2
21 - Push 33 bytes
33 bytes of public key 3
53 - OP_3
AE - OP_CHECKMULTISIG

So we can see 2 signatures are required from the 3 public keys.
legendary
Activity: 1512
Merit: 7340
Farewell, Leo
Details: Your transaction is spending a P2SH output with a 2 of 3 multi-sig redeem script.
Excuse from asking, but how did you get that? I decoded the transaction, but didn't see anything similar to a 2-of-3 multisig. I then thought that the M, N and pubkeys values are located in the redeem script, but I decoded that too and still no 2-of-3 multisig.

It also says that the reqSigs are 1, which made me wonder how you concluded that. Thanks.
legendary
Activity: 3472
Merit: 10611
Hi & thanks one more!
You wrote, i need one of the other 2 private keys. How can i get this? isn't that the case that everyone has a private key and that it is confidential?
Yes, private keys are "private" and must remain that way.

Each bitcoin address is a script, usually they require a single signature from a single key to move the coins but you can create certain scripts that require more complicated actions such as requiring more than one signature from more than one private key. This is known as multi-signature address. The address can be created from n keys but require m signatures where m <= n.
In your case, the address you have requires 2 signatures from 2 keys out of the total 3. You have signed the transactions once with one key and need to figure out how you created this wallet and where the other 2 keys are so that you can sign the transaction again with one of the other 2.
legendary
Activity: 3472
Merit: 3217
Playbet.io - Crypto Casino and Sportsbook
Hi & thanks one more!
You wrote, i need one of the other 2 private keys. How can i get this? isn't that the case that everyone has a private key and that it is confidential?

How did you create your wallet?

The raw transaction must be sent to another wallet that has control of that private key to sign the transaction. Do you remember if how did you create your multisig wallet?
If you created this wallet on the same PC then you should open another wallet on the same PC and import this raw transaction to sign the transaction.

What wallet do you currently use? if it's Electrum you can find the wallet file under C:\Users\Replacethiswithyourusername\AppData\Roaming\Electrum

newbie
Activity: 3
Merit: 0
Leo's guess was right, now that you have posted the transaction it lacks the other signature.

Details: Your transaction is spending a P2SH output with a 2 of 3 multi-sig redeem script. While spending it the signature script only provides a single signature so when the script is being evaluated the evaluator knows that for a OP_CheckMultiSig with with m=2 and n=3 it needs 3 pubkeys, 2 signatures and a dummy item (OP_0) and when checking the stack it sees 1 item is missing hence the invalid message based on stack size.

To solve this you simply have to sign the transaction with one of the other 2 private keys (assuming your existing signature is valid, I didn't check).

Leo's guess was right, now that you have posted the transaction it lacks the other signature.

Details: Your transaction is spending a P2SH output with a 2 of 3 multi-sig redeem script. While spending it the signature script only provides a single signature so when the script is being evaluated the evaluator knows that for a OP_CheckMultiSig with with m=2 and n=3 it needs 3 pubkeys, 2 signatures and a dummy item (OP_0) and when checking the stack it sees 1 item is missing hence the invalid message based on stack size.

To solve this you simply have to sign the transaction with one of the other 2 private keys (assuming your existing signature is valid, I didn't check).

Hi & thanks one more!
You wrote, i need one of the other 2 private keys. How can i get this? isn't that the case that everyone has a private key and that it is confidential?
newbie
Activity: 3
Merit: 0
Do you remember how you created this wallet? Where else or who else did you set it up with?

I created the wallet myself.

Additionally, is it 2FA wallet (since 2FA wallet also use 2-of-3 multi-sig scheme)? You could find out by checking title of Electrum window application when you open the wallet. For example for standard wallet it's

Code:
Electrum 4.1.2 - default_wallet [standard]

My wallet is Electrum 4.1.5 [standard]

On a side note, i accidentally send 20 instead of 2 merit.
legendary
Activity: 2268
Merit: 18771
So as pooya has explained, the address 3EdE6sjQtr1p8DeroVCCPUqSRFBbN8vqWz is a 2-of-3 multi-sig. This means it was created using three different private keys, and any transactions spending coins from it must be signed with at least 2 of those private keys. Your wallet only contains one of those private keys. You will need to export your partially signed transaction and import it in to a wallet containing one of the other private keys to sign the transaction again and then broadcast it.

Do you remember how you created this wallet? Where else or who else did you set it up with?
legendary
Activity: 3472
Merit: 10611
Leo's guess was right, now that you have posted the transaction it lacks the other signature.

Details: Your transaction is spending a P2SH output with a 2 of 3 multi-sig redeem script. While spending it the signature script only provides a single signature so when the script is being evaluated the evaluator knows that for a OP_CheckMultiSig with with m=2 and n=3 it needs 3 pubkeys, 2 signatures and a dummy item (OP_0) and when checking the stack it sees 1 item is missing hence the invalid message based on stack size.

To solve this you simply have to sign the transaction with one of the other 2 private keys (assuming your existing signature is valid, I didn't check).
legendary
Activity: 2520
Merit: 1233
I tend to agree with the post above mine, it's better to share your signrawtransaction if you don't mind so that members will try to figure out your problem and make sure you're decoding the right TX.  If this staff member @achow101 will respond in your thread, I know he/she explained very well, I saw before it seems he is very expert on this.

Just like on this thread, it seems familiar to your issue and it might help.
https://bitcointalksearch.org/topic/operation-not-valid-with-the-current-stack-size-when-spending-from-2of3-1823847


legendary
Activity: 2268
Merit: 18771
This error appears when the transaction has not been signed properly or completely. This most commonly occurs when you have a multi-sig transaction which has not been signed with the threshold number of keys. Another possibility is that you are using a wallet made up of imported private keys and have failed to import one of the private keys required for an input in the transaction you are trying to sign.

Are you willing to share your raw transaction hex here so we can take a look? Is your wallet standard, multi-sig, or imported keys? Did you generate this transaction from scratch in your own wallet, or did you import it from somewhere else?
legendary
Activity: 3472
Merit: 3217
Playbet.io - Crypto Casino and Sportsbook
I suggest you add more info about your wallet and where did you broadcast the signed transaction?

Does it seem this issue mostly appears on multisig wallets where did you generate the unsign raw transaction?
newbie
Activity: 3
Merit: 0
Hi everybody, i see the error "operation not valid with the current stack size" if i try to broadcast after sign the transaction. Can anybody help please?


Hi guys, thanks for your feedback!

My wallet is electrum 4.1.5 standalone version.
The raw transaction:

010000000133cfe4fee57a49c87aaebe6680f5df65d2e8415c0c40ee7182945b807e5ad3b501000 000b500483045022100d1c66bdd1e03de6da9fa93c3c51c7b33ebe8504a13ca2895cf5f9cae8c4f d9a402207cc95a120677e50c7f5ebd8077c12ee98962e881aac5877fac802770f9ec22b6014c695 2210218f5bd07a035c06f9dc996fccf6c506afeca47a254524c1ac5efd09bcd719e1f21021b27b5 61146058dab6da3a4dd9eb9d8741652eb000f4a543978a5c639da6e46e2103ca405f45cbc7e7bd4 ace4ee75a72cdaf439ff7607cc4a6a54894e2e65f6b196353aeffffffff01901805000000000019 76a9145a5f756f562f8aaf82e4569761f85c2a06f031c488ac00000000

The transaction is imported
Jump to: