3

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

02000000014218ce881112706b0736419eef81220255d8dcc1412233a47091b770534f9b47000000006d4c6b538752210319ea83d5ab6d737133c6dad6a4f942a87d3f0e7b6ad4050d245c34103319a1c3210211ebc7feb791c8936c7a8d3661bbb54470ecf579fd008d279cda67fc3e7374c721023dfba960bd3b37e004e34cd7777b9b402fb95d145d2649c3adfd5a93411c2c3453aeffffffff025044042a010000001976a91475704b43283de0bdca419b898250e1916acc9df088ac0000000000000000136a11636f72736f626974636f696e2e636f6d0a00000000

Transaction data with OP_3 in scriptSig

02000000014218ce881112706b0736419eef81220255d8dcc1412233a47091b770534f9b47000000006e534c6b538752210319ea83d5ab6d737133c6dad6a4f942a87d3f0e7b6ad4050d245c34103319a1c3210211ebc7feb791c8936c7a8d3661bbb54470ecf579fd008d279cda67fc3e7374c721023dfba960bd3b37e004e34cd7777b9b402fb95d145d2649c3adfd5a93411c2c3453aeffffffff025044042a010000001976a91475704b43283de0bdca419b898250e1916acc9df088ac0000000000000000136a11636f72736f626974636f696e2e636f6d0a00000000

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

0

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.

4
  • 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.
    – Andrew 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.
    – Andrew Chow
    Feb 12, 2020 at 21:30

Your Answer

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

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