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


And in ScriptSig I put


The whole script is:


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


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


Transaction data with OP_3 in scriptSig


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)

1 Answer 1


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.

  • 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
    Feb 12, 2020 at 8:59
  • Bitcoin Core doesn't know your script so it can't produce signatures for it.
    – Ava Chow
    Feb 12, 2020 at 17:24
  • When you say, "you will need to produce the signatures manually" what does mean? With openssl for example? With another RPC? thanks again
    – monkeyUser
    Feb 12, 2020 at 17:33
  • 1
    You need to use some other software that can produce Bitcoin signatures and then insert those signatures into your transaction by hand.
    – Ava Chow
    Feb 12, 2020 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.