I have some funds locked in a testnet P2SH address which requires 2-of-3 signatures.
This is the address: 2NEKRqUqoDtsELzpBa5wuWEiJeVbio5cSa2
and the 3 keys:

#1 - cU1mPkyNgJ8ceLG5v2zN1VkZcvDCE7VK8KrnHwW82PZb6RCq7zRq
#2 - cPTFNJD7hgbZTqNJgW89HABGtRzYo5aLpCQKvmNdtRNGWo49NAky
#3 - cNUe2L9CNJZoedMU8YNrzRuxFc56dvMjFxzK4mTsSGhXwbidAyog

The multisig script is: OP_2 <Key #1 length> <Key #1 PubKey> <Key #2 length> <Key #2 PubKey> <Key #3 length> <Key #3 PubKey> OP_3 OP_CHECKMULTISIG

I have also created a transaction spending the funds in this address, however I cannot broadcast this transaction because it gives the error Mempool accept test failed: 16: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation).

Here is the transaction:

01000000  //Version
01        //Input Count
e29cf4dad1c36d5e316bac18edfc665f8323050d7260b94b72777b12a4eecba0  //TXID
00000000  //Out index
fb        //ScriptSig size
0046304302202848f7f4087da2e01adcaca2da30fe9004861ca284efffcae6b49d2cf9f239b2021f7794619a597f5847e92fef4bdebeba42b91544d267220bfe8e2824f3ef74190147304402201dd2ba26a81ac13da8ecd5d967f9394ec0c5356e6d303adeb71f84bd2ee62d0202203632bfc457d778a71ca72007cce9d0e6f92a1bf8226e010fc9e59e0572afe454014c695221034d0953ff49ed8e98cce462e9ecd3ead6cf641b299ec500329dc153443d4cced721024be733c116a4ca8bd7dd2aafa6fb6877d153962e0f6a21709fab771ce6572b4821038c6a2191a2e77ede17063d8633fb9e08dba8535fd1dd99377b7dc9b6bea89efe53ae     //ScriptSig (2 signatures followed by the redeem script)
ffffffff         //Sequence
01               //Output count
204e000000000000 //Output Value
16               //ScriptPubKey size
001491c6c31a62b37a16447ccf44224eb1ab78ca0299  //scriptPubKey (Segwit P2PKH)
00000000         //Locktime

Here are the steps I took to sign the input:

1. Hash the input with the scriptPubKey as the scriptSig and SigHash ALL appended
2. Sign the hashed signature with Key #1 and Key #2
3. Construct the scriptSig by concatenating the 2 signatures and redeem script
4. Place the scriptSig in the scriptSig field of the input

Im not sure if I am missing a step or have done a step incorrectly. I did pretty much the same steps as signing a P2PKH input which I can successfully create, just with different scriptSigs.

Any help would be appreciated.

  • The signature verification seems to have failed. The calculation of the sighash used for the signature may be wrong. BTW, e29cf4dad1c36d5e316bac18edfc665f8323050d7260b94b72777b12a4eecba0 is tx hash, not TXID. If the endianness is reversed, it becomes TXID. Oct 4, 2021 at 1:11
  • I found where I went wrong. When creating the hashpreimage for the input, I was substituting in the scriptPubKey of the input instead of the redeemScript. When I used the redeemScript instead of the scriptPubKey, the signature was correct.
    – Keijyu
    Oct 4, 2021 at 1:51
  • @Keijyu: You could add your last comment as an answer in the "Your Answer" section below - if you think it might help others in future, or delete the question if not. Oct 4, 2021 at 9:01

1 Answer 1


I found where I went wrong.

When creating the hashpreimage for the input, I was substituting in the scriptPubKey of the input instead of the redeemScript into the scriptSig.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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