<p>How did you try to sign your transaction? There are no signatures in your transaction, so the <code>OP_CHECKMULTISIG</code> is failing.</p>

<p>Because you are using a custom script, signing software are unlikely to be able to sign your transaction because they can only sign for standard templates. You are not using a standard script template (because of the <code>OP_3 OP_EQUAL</code>) so no signatures are being created. To sign this transaction, you will need to produce the signatures manually (by computing the correct sighash and signing it) and insert them into the transaction manually.</p>

CC BY-SA 4.0
2020-02-12T08:59:24.827Z
Thanks for reply. I'm using Bitcoin core and I'm using this "flow" to understand how it works. I create an address P2SH with OP_3 OP_EQUAL and 3 compressed public keys.  After that I create a transaction with `createrawtransaction` like `bitcoin-cli createrawtransaction '[{"txid":"'$TXID'","vout":'$VOUT',"scriptPubKey":"'$SCRIPTPUBKEY'","redeemScript":"'$REDEEM'"}]' '[{"'$ADDR_MITT'":'$AMOUNT'}'`  and try to sign with `bitcoin-cli signrawtransactionwithkey $TX_DATA '["'$PK1'","'$PK2'"]' '[{"txid":"'$TXID'","vout":'$VOUT',"scriptPubKey":"'$SCRIPTPUBKEY'","redeemScript":"'$REDEEM'"}]'`
monkeyUser
CC BY-SA 4.0
2020-02-12T17:24:38.147Z
Bitcoin Core doesn't know your script so it can't produce signatures for it.
Ava Chow
CC BY-SA 4.0
2020-02-12T17:33:15.650Z
When you say, "you will need to produce the signatures manually" what does mean? With openssl for example? With another RPC? thanks again
monkeyUser
CC BY-SA 4.0
2020-02-12T21:30:22.850Z
You need to use some other software that can produce Bitcoin signatures and then insert those signatures into your transaction by hand.
Ava Chow
CC BY-SA 4.0
2020-02-11T17:57:27.103Z
2020-02-11T17:57:27.103Z
Ava Chow
<p>I'm studying P2SH, and I want to create a custom script.
I already created one tx but without OP_CHECKMULITISIG as you can check at this link <a href="https://tbtc.bitaps.com/c86e443bdb3ad4845b1670a63376daf785eae3932a1b6146a7138ea46d51d24a" rel="nofollow noreferrer">https://tbtc.bitaps.com/c86e443bdb3ad4845b1670a63376daf785eae3932a1b6146a7138ea46d51d24a</a>.
The script is very simple, in Scriptpubkey you can find </p>

<pre><code>OP_3 OP_EQUAL
</code></pre>

<p>And in ScriptSig I put</p>

<pre><code>OP_3
</code></pre>

<p>The whole script is:</p>

<pre><code>02000000014ad2516da48e13a746611b2a93e3ea85f7da7633a670165b84d43adb3b446ec8000000000453025387ffffffff029f0f0000000000001976a914261216d05727044e927c385aa9bd278754cdc8dc88ac0000000000000000136a11636f72736f626974636f696e2e636f6d0a00000000
</code></pre>

<p>Now, I want to add 2-3 into simple script.
My redeem script is:</p>

<pre><code>53875221"$PB1"21"$PB2"21"$PB3"53AE
</code></pre>

<p>where $PB1 $PB2 $PB3 are compressed public keys.</p>

<p>Then I try to sign the transaction and add OP_3 in ScriptSig (increase its length by 1 byte)</p>

<p>Original Transaction Data</p>

<blockquote>
  <p>02000000014218ce881112706b0736419eef81220255d8dcc1412233a47091b770534f9b4700000000<strong>6d4c6b538752210319ea83d5ab6d737133c6dad6a4f942a87d3f0e7b6ad4050d245c34103319a1c3210211ebc7feb791c8936c7a8d3661bbb54470ecf579fd008d279cda67fc3e7374c721023dfba960bd3b37e004e34cd7777b9b402fb95d145d2649c3adfd5a93411c2c3453ae</strong>ffffffff025044042a010000001976a91475704b43283de0bdca419b898250e1916acc9df088ac0000000000000000136a11636f72736f626974636f696e2e636f6d0a00000000</p>
</blockquote>

<p>Transaction data with OP_3 in scriptSig</p>

<blockquote>
  <p>02000000014218ce881112706b0736419eef81220255d8dcc1412233a47091b770534f9b4700000000<strong>6e534c6b538752210319ea83d5ab6d737133c6dad6a4f942a87d3f0e7b6ad4050d245c34103319a1c3210211ebc7feb791c8936c7a8d3661bbb54470ecf579fd008d279cda67fc3e7374c721023dfba960bd3b37e004e34cd7777b9b402fb95d145d2649c3adfd5a93411c2c3453ae</strong>ffffffff025044042a010000001976a91475704b43283de0bdca419b898250e1916acc9df088ac0000000000000000136a11636f72736f626974636f696e2e636f6d0a00000000</p>
</blockquote>

<p>When I send the transaction I get this error:</p>

<blockquote>
  <p>error code: -26 error message: mandatory-script-verify-flag-failed
  (Operation not valid with the current stack size) (code 16)</p>
</blockquote>

<transactions><script><p2sh>
Create Custom Script with 2-3
monkeyUser
# Create Custom Script with 2-3

(Asked by: username_0 on 2020-02-11)

I'm studying P2SH, and I want to create a custom script.
I already created one tx but without OP\_CHECKMULITISIG as you can check at this link <https://tbtc.bitaps.com/c86e443bdb3ad4845b1670a63376daf785eae3932a1b6146a7138ea46d51d24a>.
The script is very simple, in Scriptpubkey you can find

```
OP_3 OP_EQUAL

```

And in ScriptSig I put

```
OP_3

```

The whole script is:

```
02000000014ad2516da48e13a746611b2a93e3ea85f7da7633a670165b84d43adb3b446ec8000000000453025387ffffffff029f0f0000000000001976a914261216d05727044e927c385aa9bd278754cdc8dc88ac0000000000000000136a11636f72736f626974636f696e2e636f6d0a00000000

```

Now, I want to add 2-3 into simple script.
My redeem script is:

```
53875221"$PB1"21"$PB2"21"$PB3"53AE

```

where $PB1 $PB2 $PB3 are compressed public keys.

Then I try to sign the transaction and add OP\_3 in ScriptSig (increase its length by 1 byte)

Original Transaction Data

> 02000000014218ce881112706b0736419eef81220255d8dcc1412233a47091b770534f9b4700000000**6d4c6b538752210319ea83d5ab6d737133c6dad6a4f942a87d3f0e7b6ad4050d245c34103319a1c3210211ebc7feb791c8936c7a8d3661bbb54470ecf579fd008d279cda67fc3e7374c721023dfba960bd3b37e004e34cd7777b9b402fb95d145d2649c3adfd5a93411c2c3453ae**ffffffff025044042a010000001976a91475704b43283de0bdca419b898250e1916acc9df088ac0000000000000000136a11636f72736f626974636f696e2e636f6d0a00000000

Transaction data with OP\_3 in scriptSig

> 02000000014218ce881112706b0736419eef81220255d8dcc1412233a47091b770534f9b4700000000**6e534c6b538752210319ea83d5ab6d737133c6dad6a4f942a87d3f0e7b6ad4050d245c34103319a1c3210211ebc7feb791c8936c7a8d3661bbb54470ecf579fd008d279cda67fc3e7374c721023dfba960bd3b37e004e34cd7777b9b402fb95d145d2649c3adfd5a93411c2c3453ae**ffffffff025044042a010000001976a91475704b43283de0bdca419b898250e1916acc9df088ac0000000000000000136a11636f72736f626974636f696e2e636f6d0a00000000

When I send the transaction I get this error:

> error code: -26 error message: mandatory-script-verify-flag-failed
> (Operation not valid with the current stack size) (code 16)

**Tags:** transactions, script, p2sh


---

## 1 answers

### Answer by username_1 on 2020-02-11. Score: 0 | Accepted answer

How did you try to sign your transaction? There are no signatures in your transaction, so the `OP_CHECKMULTISIG` is failing.

Because you are using a custom script, signing software are unlikely to be able to sign your transaction because they can only sign for standard templates. You are not using a standard script template (because of the `OP_3 OP_EQUAL`) so no signatures are being created. To sign this transaction, you will need to produce the signatures manually (by computing the correct sighash and signing it) and insert them into the transaction manually.

> **Comments:**
> **username_0**: Thanks for reply. I'm using Bitcoin core and I'm using this "flow" to understand how it works. I create an address P2SH with OP_3 OP_EQUAL and 3 compressed public keys.  After that I create a transaction with `createrawtransaction` like `bitcoin-cli createrawtransaction '[{"txid":"'$TXID'","vout":'$VOUT',"scriptPubKey":"'$SCRIPTPUBKEY'","redeemScript":"'$REDEEM'"}]' '[{"'$ADDR_MITT'":'$AMOUNT'}'`  and try to sign with `bitcoin-cli signrawtransactionwithkey $TX_DATA '["'$PK1'","'$PK2'"]' '[{"txid":"'$TXID'","vout":'$VOUT',"scriptPubKey":"'$SCRIPTPUBKEY'","redeemScript":"'$REDEEM'"}]'`  
> **username_1**: Bitcoin Core doesn't know your script so it can't produce signatures for it.  
> **username_0**: When you say, "you will need to produce the signatures manually" what does mean? With openssl for example? With another RPC? thanks again  
> **username_1**: You need to use some other software that can produce Bitcoin signatures and then insert those signatures into your transaction by hand.  

---

