<p>Your signature <code>3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b9</code> for pubkey <code>04624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a</code> is wrong.</p>
<p>EDIT after btcdeb output: Actually both are wrong.</p>
<p>Wild guess: maybe this signature is for the third key and you forgot to add an empty byte array in-between the signatures ?</p>
<p>You might want to use <a href="https://github.com/kallewoof/btcdeb" rel="nofollow noreferrer">btcdeb</a> to debug your signature:</p>
<pre><code>DEBUG_SIGNING=1 DEBUG_SIGHASH=1 ./btcdeb --tx=0100000001a9c174acdc3493ba18e19654c440a8b78a86fba56e728af7af8853acc5bc918200000000fd3d0100473044022052c7ee72b96cba77f5a9e165e73251f01638ebc931fd2750cf3b8f6e4b41778f02207a1321f9b4a39e4e62b5199253822163f24135577f6b8c0d1258ce485b1d865d01483045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b9014ca952410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753aeffffffff0248710000000000001976a914ded6cec3c85c32c29216258099343f55875f99c888ac90dc0100000000001976a914fe2951cabb6d9e43aece6d530ac5967a5f895d4188ac00000000 --txin 020000000001037cc2ca29b2f72cdc03823bfae73030af625275e2323c7286dd83811aa7a578c90100000000ffffffffa85a130e60eecb36ee6e83cb622f3ed691946735fc9b07ada9e8c55b8eae215b010000006b483045022100df357edebc8a2eb7ead2ecfd11d4a7f1801fad491c87b693c44e206f6d2eddf30220184bca044c07e2dae06c809aa47dd37cfc7cc0db7da09600d9adbdc1ea1d44ea0121029cdaffb32f9508cfba8ef3c241f31978d76ac48f3bec3009dcbd798f70e3b619ffffffff08b620e68ed09ed674663fdb94e31c7d370bcaf40d880fa131f348c1763725c6000000006b483045022100860460170083a49cda6d68dec001892032df39988db52e2b8f91d8947c1cb71f0220277849a9319d16b0fcc60870e0efba55dc56251bf555d8e447ce6422949be288012102c87f969e60e1d85fb2f53c1314359123780f9c94b71299b03ac32e0a9d011f19ffffffff0200ee02000000000017a9140ea69eba81a9bfecfe7aa5b5f2b9a2bca6cdb68a879c1c0400000000001600149a0c39fc518500521b942ee1227cadc0933ebdc80247304402205226fa48d146904296bb6f26c5598c71234dbc46464d10498379dc8893e6114d0220526a3cb559e53ba5597824272dc1f8c36461ef9cac21c3e39fbbad1d4024e870012103a5f2fff56c0e7c45e8f5760a7580fb54470201345167bd060863c6c7c8bd78c2000000000000
</code></pre>

CC BY-SA 4.0
2020-03-27T13:20:22.807Z
it is the signature from the second pubkey. why are you saying 2nd sig is bad.?
user3554230
CC BY-SA 4.0
2020-03-27T13:49:36.110Z
i added the btcdeb output... but im not sure which signature is failing. 03d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b57 is the pub key i am not using for signing if that helps
user3554230
CC BY-SA 4.0
2020-03-27T14:37:15.167Z
Because btcdeb said so (and bitcoind too) ! :D

How did you sign it ? If it's by hand then don't forget the empty byte array for the signature for the pubkey you don't use (`03d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b57`).
Antoine Poinsot
CC BY-SA 4.0
2020-03-27T14:58:01.933Z
it is the signature from a nano ledger s and the corresponding public key.
user3554230
CC BY-SA 4.0
2020-03-27T15:06:13.130Z
i didn't add the 03d25 pub key when i did my signing. The signature was returned directly from the ledger.
user3554230
CC BY-SA 4.0
2020-03-27T15:10:54.033Z
And that's the ledger which constructed the transaction ? It looks like the signatures are just badly ordered but I really don't know anything about Ledger sorry (let's wait for someone with Ledger knowledge)...
Antoine Poinsot
CC BY-SA 4.0
2020-03-27T15:16:20.703Z
transaction was constructed in bitcoind with createmultisig. I put in the public keys ```    "0428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f",
   "04624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a",
   "03d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b57" ```
user3554230
CC BY-SA 4.0
2020-03-27T15:17:57.733Z
the first 2 public keys are from the ledger... the last one is just a regular p2pkh addr.
user3554230
CC BY-SA 4.0
2020-03-27T19:49:50.713Z
How exactly did you construct the signatures? Using Bitcoin Core, or using a Ledger, and if so, how?
Pieter Wuille
CC BY-SA 4.0
2020-03-28T09:36:04.487Z
i constructed it with bitcoin core v0.16 with  the command `createmultisig 2 '["0428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f","04624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a","03d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b57"]'`
user3554230
CC BY-SA 4.0
2020-03-28T16:50:09.043Z
The question was about the signatures (unlocking script / scriptSig), createmultisig creates an address (locking script / scriptPubKey).

How exactily did you construct the unlocking script / the spending transaction ?
Antoine Poinsot
CC BY-SA 4.0
2020-03-29T09:53:27.797Z
`createrawtransaction '[{"txid":"8291bcc5ac5388aff78a726ea5fb868ab7a840c45496e118ba9334dcac74c1a9","vout":0}]' {"1MKGLgkDVPLu932nMe39Aa5W7dZGWVtBnv": 0.00029000,"1QAt8ewP3CQhZUSxDcgZaXNgYYeu2V5JQp": 0.00122000}`
user3554230
CC BY-SA 4.0
2020-03-29T11:46:45.827Z
And then, how did you sign it ?..
Antoine Poinsot
CC BY-SA 4.0
2020-03-29T12:04:45.697Z
i signed it with the nano ledger   `await btc.signP2SHTransaction([input],keyset,outputscript).then(sig => console.log("SIGHASH: ",sig)).catch(err => console.log(err));`
user3554230
CC BY-SA 4.0
2020-03-29T12:05:04.077Z
i have singed numerous transactions this way before... this is the first time i have had an issue.
user3554230
CC BY-SA 4.0
2020-03-31T06:59:13.980Z
still haven't figured this out... not exactly sure what is wrong with btcdeb
user3554230
CC BY-SA 4.0
2020-03-31T08:07:22.223Z
"" not exactly sure what is wrong with btcdeb ""

What btcdeb output means is that your signatures are not valid for the given public key.

It does not *necessarily* mean that they are wrong, but maybe badly ordered such as the script interpreter does not compare the matching public key and signature.

Hence why I suggest you are missing an empty byte array...
Antoine Poinsot
CC BY-SA 4.0
2020-03-31T10:23:11.347Z
`3044022052c7ee72b96cba77f5a9e165e73251f01638ebc931fd2750cf3b8f6e4b41778f02207a1321f9b4a39e4e62b5199253822163f24135577f6b8c0d1258ce485b1d865d01  + 00 + 3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b901` is this what you mean ?
user3554230
CC BY-SA 4.0
2020-03-31T18:08:10.210Z
Yep, didn't check the order but that's what I mean about the empty byte array.
Antoine Poinsot
CC BY-SA 4.0
2020-04-01T06:36:34.177Z
hwo do you check if the order is correct ?
user3554230
CC BY-SA 4.0
2020-04-03T02:18:16.403Z
it's not the order. what HEX is used in the signature. What part of the raw transaction is used in the signature ?
user3554230
CC BY-SA 4.0
2020-04-03T08:43:52.283Z
You mean what is signed ? It depends on the SIGHASH flag.
Antoine Poinsot
CC BY-SA 4.0
2020-04-03T12:54:46.160Z
sighahs flag looks like 01 (ALL). I have figurd that part out. I am now tying to figure out how to verify if the signature is correct with the public key or address. of the 3 keys, 2 keys are on the ledger, one is manual ( i have hte private key). That, according to btcdeb is working fine... which leads me to believe maybe something is wrong with my ledger. I want to verify the signature it generates against my public key, but i'm not sure how to do that. Hence, how can i verify a signature against a public key or address ?
user3554230
CC BY-SA 4.0
2020-04-03T15:17:37.487Z
Using btcdeb is the best way I can think of (as you need to reimplement VerifySignature, which btcdeb already support as it fokred bitcoin-core).
Using DEBUG_SIGNING=1 DEBUG_SIGHASH=1 it will show you which signature is checked against which pubkey, and whether it's valid.
Antoine Poinsot
CC BY-SA 4.0
2020-08-06T03:14:27.090Z
I have added experimental support to btcdeb where it will detect and inform the user of incorrectly placed signatures. Running that on the above example, however, did not indicate that this was the case, so the problem is most likely not placement. https://github.com/kallewoof/btcdeb/pull/52
Kalle
CC BY-SA 4.0
2020-03-27T11:05:42.540Z
2020-08-06T09:33:57.977Z
2020-08-06T09:33:57.977Z
Antoine Poinsot
<p><a href="https://pastebin.com/kdQPkELN" rel="nofollow noreferrer">https://pastebin.com/kdQPkELN</a></p>

<p>if anyone can see why i am getting a  16: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)failure.... It is a p2sh multisig transaction 2 of 3. 2 public keys are uncompressed and one key is compressed. I can't seem to figure it out. 
 created originally on bitcoin core v0.16 and i am trying to send it out on core v0.17... Not sure why this is causing a problem.</p>

<pre><code> -&gt; #0000 0
    #0001 3044022052c7ee72b96cba77f5a9e165e73251f01638ebc931fd2750cf3b8f6e4b41778f02207a1321f9b4a39e4e62b5199253822163f24135577f6b8c0d1258ce485b1d865d01
    #0002 3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b901
    #0003 52410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753ae
    &lt;&lt;&lt; scriptPubKey &gt;&gt;&gt;
    #0005 OP_HASH160
    #0006 0ea69eba81a9bfecfe7aa5b5f2b9a2bca6cdb68a
    #0007 OP_EQUAL
    &lt;&lt;&lt; P2SH script &gt;&gt;&gt;
    #0009 2
    #0010 0428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f
    #0011 04624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a
    #0012 03d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b57
    #0013 3
    #0014 OP_CHECKMULTISIG
</code></pre>

<p>btcdeb output:</p>

<pre><code>stack has 8 entries [require 5]
stack has 8 entries [require 8]
scriptCode = 52410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753ae
looping for multisig
loop: sigs = 2, keys = 3
- got sig 3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b901
- got key 03d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b57
GenericTransactionSignatureChecker::CheckSig(72 len sig, 33 len pubkey, sigversion=0)
  sig         = 3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b901
  pub key     = 03d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b57
  script code = 52410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753ae
  hash type   = 01 (SIGHASH_ALL)
SignatureHash(nIn=0, nHashType=01, amount=192000)
- sigversion = SIGVERSION_BASE (non-segwit style)
Serializing transaction
 &lt;&lt; txTo.nVersion (00000001)
#004 01000000
 &lt;&lt; nInputs = 1 [compact]
#001 01
(serialize input 0)
 &lt;&lt; txTo.vin[nInput=0].prevout = COutPoint(8291bcc5ac, 0)
#032 a9c174acdc3493ba18e19654c440a8b78a86fba56e728af7af8853acc5bc9182
#004 00000000
(SerializeScriptCode)
 &lt;&lt; scriptCode.size()=169 - nCodeSeparators=0
#001 a9
 &lt;&lt; script:52410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753ae
#169 52410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753ae
 &lt;&lt; txTo.vin[nInput].nSequence = 4294967295 [0xffffffff]
#004 ffffffff
 &lt;&lt; nOutputs = 2 [compact]
#001 02
(serialize output 0)
#008 4871000000000000
#001 19
#025 76a914ded6cec3c85c32c29216258099343f55875f99c888ac
(serialize output 1)
#008 90dc010000000000
#001 19
#025 76a914fe2951cabb6d9e43aece6d530ac5967a5f895d4188ac
 &lt;&lt; txTo.nLockTime = 0 [0x0]
#004 00000000
#004 01000000
  sighash     = 0c6027c0017de012eaa0c7c6ee1074f06a1fbc5c15e2b84291ea80bfaea68da7
  pubkey.Verify(sig=3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b9, sighash=0c6027c0017de012eaa0c7c6ee1074f06a1fbc5c15e2b84291ea80bfaea68da7):
  result: FAILURE
- failed: VerifySignature() failed
- sig check failed
loop: sigs = 2, keys = 2
- got sig 3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b901
- got key 04624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a
GenericTransactionSignatureChecker::CheckSig(72 len sig, 65 len pubkey, sigversion=0)
  sig         = 3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b901
  pub key     = 04624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a
  script code = 52410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753ae
  hash type   = 01 (SIGHASH_ALL)
SignatureHash(nIn=0, nHashType=01, amount=192000)
- sigversion = SIGVERSION_BASE (non-segwit style)
Serializing transaction
 &lt;&lt; txTo.nVersion (00000001)
#004 01000000
 &lt;&lt; nInputs = 1 [compact]
#001 01
(serialize input 0)
 &lt;&lt; txTo.vin[nInput=0].prevout = COutPoint(8291bcc5ac, 0)
#032 a9c174acdc3493ba18e19654c440a8b78a86fba56e728af7af8853acc5bc9182
#004 00000000
(SerializeScriptCode)
 &lt;&lt; scriptCode.size()=169 - nCodeSeparators=0
#001 a9
 &lt;&lt; script:52410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753ae
#169 52410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753ae
 &lt;&lt; txTo.vin[nInput].nSequence = 4294967295 [0xffffffff]
#004 ffffffff
 &lt;&lt; nOutputs = 2 [compact]
#001 02
(serialize output 0)
#008 4871000000000000
#001 19
#025 76a914ded6cec3c85c32c29216258099343f55875f99c888ac
(serialize output 1)
#008 90dc010000000000
#001 19
#025 76a914fe2951cabb6d9e43aece6d530ac5967a5f895d4188ac
 &lt;&lt; txTo.nLockTime = 0 [0x0]
#004 00000000
#004 01000000
  sighash     = 0c6027c0017de012eaa0c7c6ee1074f06a1fbc5c15e2b84291ea80bfaea68da7
  pubkey.Verify(sig=3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b9, sighash=0c6027c0017de012eaa0c7c6ee1074f06a1fbc5c15e2b84291ea80bfaea68da7):
  result: FAILURE
- failed: VerifySignature() failed
- sig check failed
loop ended in failure state
        &lt;&gt; POP  stack
        &lt;&gt; POP  stack
        &lt;&gt; POP  stack
        &lt;&gt; POP  stack
        &lt;&gt; POP  stack
error: Signature must be zero for failed CHECK(MULTI)SIG operation
btcdeb&gt; 
</code></pre>

<p>Still a little confused with the output</p>

<bitcoin-core><multi-signature><p2sh>
Old p2sh address not signing correctly on core v0.17
user3554230
# Old p2sh address not signing correctly on core v0.17

(Asked by: username_0 on 2020-03-27)

<https://pastebin.com/kdQPkELN>

if anyone can see why i am getting a 16: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation)failure.... It is a p2sh multisig transaction 2 of 3. 2 public keys are uncompressed and one key is compressed. I can't seem to figure it out.
created originally on bitcoin core v0.16 and i am trying to send it out on core v0.17... Not sure why this is causing a problem.

```
 -> #0000 0
    #0001 3044022052c7ee72b96cba77f5a9e165e73251f01638ebc931fd2750cf3b8f6e4b41778f02207a1321f9b4a39e4e62b5199253822163f24135577f6b8c0d1258ce485b1d865d01
    #0002 3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b901
    #0003 52410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753ae
    <<< scriptPubKey >>>
    #0005 OP_HASH160
    #0006 0ea69eba81a9bfecfe7aa5b5f2b9a2bca6cdb68a
    #0007 OP_EQUAL
    <<< P2SH script >>>
    #0009 2
    #0010 0428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f
    #0011 04624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a
    #0012 03d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b57
    #0013 3
    #0014 OP_CHECKMULTISIG

```

btcdeb output:

```
stack has 8 entries [require 5]
stack has 8 entries [require 8]
scriptCode = 52410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753ae
looping for multisig
loop: sigs = 2, keys = 3
- got sig 3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b901
- got key 03d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b57
GenericTransactionSignatureChecker::CheckSig(72 len sig, 33 len pubkey, sigversion=0)
  sig         = 3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b901
  pub key     = 03d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b57
  script code = 52410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753ae
  hash type   = 01 (SIGHASH_ALL)
SignatureHash(nIn=0, nHashType=01, amount=192000)
- sigversion = SIGVERSION_BASE (non-segwit style)
Serializing transaction
 << txTo.nVersion (00000001)
#004 01000000
 << nInputs = 1 [compact]
#001 01
(serialize input 0)
 << txTo.vin[nInput=0].prevout = COutPoint(8291bcc5ac, 0)
#032 a9c174acdc3493ba18e19654c440a8b78a86fba56e728af7af8853acc5bc9182
#004 00000000
(SerializeScriptCode)
 << scriptCode.size()=169 - nCodeSeparators=0
#001 a9
 << script:52410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753ae
#169 52410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753ae
 << txTo.vin[nInput].nSequence = 4294967295 [0xffffffff]
#004 ffffffff
 << nOutputs = 2 [compact]
#001 02
(serialize output 0)
#008 4871000000000000
#001 19
#025 76a914ded6cec3c85c32c29216258099343f55875f99c888ac
(serialize output 1)
#008 90dc010000000000
#001 19
#025 76a914fe2951cabb6d9e43aece6d530ac5967a5f895d4188ac
 << txTo.nLockTime = 0 [0x0]
#004 00000000
#004 01000000
  sighash     = 0c6027c0017de012eaa0c7c6ee1074f06a1fbc5c15e2b84291ea80bfaea68da7
  pubkey.Verify(sig=3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b9, sighash=0c6027c0017de012eaa0c7c6ee1074f06a1fbc5c15e2b84291ea80bfaea68da7):
  result: FAILURE
- failed: VerifySignature() failed
- sig check failed
loop: sigs = 2, keys = 2
- got sig 3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b901
- got key 04624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a
GenericTransactionSignatureChecker::CheckSig(72 len sig, 65 len pubkey, sigversion=0)
  sig         = 3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b901
  pub key     = 04624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a
  script code = 52410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753ae
  hash type   = 01 (SIGHASH_ALL)
SignatureHash(nIn=0, nHashType=01, amount=192000)
- sigversion = SIGVERSION_BASE (non-segwit style)
Serializing transaction
 << txTo.nVersion (00000001)
#004 01000000
 << nInputs = 1 [compact]
#001 01
(serialize input 0)
 << txTo.vin[nInput=0].prevout = COutPoint(8291bcc5ac, 0)
#032 a9c174acdc3493ba18e19654c440a8b78a86fba56e728af7af8853acc5bc9182
#004 00000000
(SerializeScriptCode)
 << scriptCode.size()=169 - nCodeSeparators=0
#001 a9
 << script:52410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753ae
#169 52410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753ae
 << txTo.vin[nInput].nSequence = 4294967295 [0xffffffff]
#004 ffffffff
 << nOutputs = 2 [compact]
#001 02
(serialize output 0)
#008 4871000000000000
#001 19
#025 76a914ded6cec3c85c32c29216258099343f55875f99c888ac
(serialize output 1)
#008 90dc010000000000
#001 19
#025 76a914fe2951cabb6d9e43aece6d530ac5967a5f895d4188ac
 << txTo.nLockTime = 0 [0x0]
#004 00000000
#004 01000000
  sighash     = 0c6027c0017de012eaa0c7c6ee1074f06a1fbc5c15e2b84291ea80bfaea68da7
  pubkey.Verify(sig=3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b9, sighash=0c6027c0017de012eaa0c7c6ee1074f06a1fbc5c15e2b84291ea80bfaea68da7):
  result: FAILURE
- failed: VerifySignature() failed
- sig check failed
loop ended in failure state
        <> POP  stack
        <> POP  stack
        <> POP  stack
        <> POP  stack
        <> POP  stack
error: Signature must be zero for failed CHECK(MULTI)SIG operation
btcdeb> 

```

Still a little confused with the output

**Tags:** bitcoin-core, multi-signature, p2sh


---

## 1 answers

### Answer by username_1 on 2020-03-27. Score: 1

Your signature `3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b9` for pubkey `04624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a` is wrong.

EDIT after btcdeb output: Actually both are wrong.

Wild guess: maybe this signature is for the third key and you forgot to add an empty byte array in-between the signatures ?

You might want to use [btcdeb](https://github.com/kallewoof/btcdeb) to debug your signature:

```
DEBUG_SIGNING=1 DEBUG_SIGHASH=1 ./btcdeb --tx=0100000001a9c174acdc3493ba18e19654c440a8b78a86fba56e728af7af8853acc5bc918200000000fd3d0100473044022052c7ee72b96cba77f5a9e165e73251f01638ebc931fd2750cf3b8f6e4b41778f02207a1321f9b4a39e4e62b5199253822163f24135577f6b8c0d1258ce485b1d865d01483045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b9014ca952410428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f4104624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a2103d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b5753aeffffffff0248710000000000001976a914ded6cec3c85c32c29216258099343f55875f99c888ac90dc0100000000001976a914fe2951cabb6d9e43aece6d530ac5967a5f895d4188ac00000000 --txin 020000000001037cc2ca29b2f72cdc03823bfae73030af625275e2323c7286dd83811aa7a578c90100000000ffffffffa85a130e60eecb36ee6e83cb622f3ed691946735fc9b07ada9e8c55b8eae215b010000006b483045022100df357edebc8a2eb7ead2ecfd11d4a7f1801fad491c87b693c44e206f6d2eddf30220184bca044c07e2dae06c809aa47dd37cfc7cc0db7da09600d9adbdc1ea1d44ea0121029cdaffb32f9508cfba8ef3c241f31978d76ac48f3bec3009dcbd798f70e3b619ffffffff08b620e68ed09ed674663fdb94e31c7d370bcaf40d880fa131f348c1763725c6000000006b483045022100860460170083a49cda6d68dec001892032df39988db52e2b8f91d8947c1cb71f0220277849a9319d16b0fcc60870e0efba55dc56251bf555d8e447ce6422949be288012102c87f969e60e1d85fb2f53c1314359123780f9c94b71299b03ac32e0a9d011f19ffffffff0200ee02000000000017a9140ea69eba81a9bfecfe7aa5b5f2b9a2bca6cdb68a879c1c0400000000001600149a0c39fc518500521b942ee1227cadc0933ebdc80247304402205226fa48d146904296bb6f26c5598c71234dbc46464d10498379dc8893e6114d0220526a3cb559e53ba5597824272dc1f8c36461ef9cac21c3e39fbbad1d4024e870012103a5f2fff56c0e7c45e8f5760a7580fb54470201345167bd060863c6c7c8bd78c2000000000000

```

> **Comments:**
> **username_0**: it is the signature from the second pubkey. why are you saying 2nd sig is bad.?  
> **username_0**: i added the btcdeb output... but im not sure which signature is failing. 03d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b57 is the pub key i am not using for signing if that helps  
> **username_1**: Because btcdeb said so (and bitcoind too) ! :D  How did you sign it ? If it's by hand then don't forget the empty byte array for the signature for the pubkey you don't use (`03d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b57`).  
> **username_0**: it is the signature from a nano ledger s and the corresponding public key.  
> **username_0**: i didn't add the 03d25 pub key when i did my signing. The signature was returned directly from the ledger.  
> **username_1**: And that's the ledger which constructed the transaction ? It looks like the signatures are just badly ordered but I really don't know anything about Ledger sorry (let's wait for someone with Ledger knowledge)...  
> **username_0**: transaction was constructed in bitcoind with createmultisig. I put in the public keys ```    "0428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f",    "04624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a",    "03d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b57" ```  
> **username_0**: the first 2 public keys are from the ledger... the last one is just a regular p2pkh addr.  
> **username_2**: How exactly did you construct the signatures? Using Bitcoin Core, or using a Ledger, and if so, how?  
> **username_0**: i constructed it with bitcoin core v0.16 with  the command `createmultisig 2 '["0428e87e0c4670b46541f17f8ad42c2b731b196fb8f1185b47939fa97d826944303921a8993eebe288d6b8bdf1e804dd16e122d32f720455b4eeedf7a4cc98770f","04624ee12cb0b3e63ceac25ed5bf16fb5d9791a9f17bd09963bbb44fa23e15a9d703b5ef7250dc304d606ecc39f976539b5a833462f7258cfd1dde0ca63b74935a","03d25273b1b2ab9e96b666764d2bc448019440f095aa989f5289145f293be98b57"]'`  
> **username_1**: The question was about the signatures (unlocking script / scriptSig), createmultisig creates an address (locking script / scriptPubKey).  How exactily did you construct the unlocking script / the spending transaction ?  
> **username_0**: `createrawtransaction '[{"txid":"8291bcc5ac5388aff78a726ea5fb868ab7a840c45496e118ba9334dcac74c1a9","vout":0}]' {"1MKGLgkDVPLu932nMe39Aa5W7dZGWVtBnv": 0.00029000,"1QAt8ewP3CQhZUSxDcgZaXNgYYeu2V5JQp": 0.00122000}`  
> **username_1**: And then, how did you sign it ?..  
> **username_0**: i signed it with the nano ledger   `await btc.signP2SHTransaction([input],keyset,outputscript).then(sig => console.log("SIGHASH: ",sig)).catch(err => console.log(err));`  
> **username_0**: i have singed numerous transactions this way before... this is the first time i have had an issue.  
> **username_0**: still haven't figured this out... not exactly sure what is wrong with btcdeb  
> **username_1**: "" not exactly sure what is wrong with btcdeb ""  What btcdeb output means is that your signatures are not valid for the given public key.  It does not *necessarily* mean that they are wrong, but maybe badly ordered such as the script interpreter does not compare the matching public key and signature.  Hence why I suggest you are missing an empty byte array...  
> **username_0**: `3044022052c7ee72b96cba77f5a9e165e73251f01638ebc931fd2750cf3b8f6e4b41778f02207a1321f9b4a39e4e62b5199253822163f24135577f6b8c0d1258ce485b1d865d01  + 00 + 3045022100a8174334724185341d5c47fa70a5b6228bc357a6fd98427cc2c31a898136dc44022000886624847174494956e919bb83b2d3b195bca4b7f37aba0e7c391b2c5510b901` is this what you mean ?  
> **username_1**: Yep, didn't check the order but that's what I mean about the empty byte array.  
> **username_0**: hwo do you check if the order is correct ?  
> **username_0**: it's not the order. what HEX is used in the signature. What part of the raw transaction is used in the signature ?  
> **username_1**: You mean what is signed ? It depends on the SIGHASH flag.  
> **username_0**: sighahs flag looks like 01 (ALL). I have figurd that part out. I am now tying to figure out how to verify if the signature is correct with the public key or address. of the 3 keys, 2 keys are on the ledger, one is manual ( i have hte private key). That, according to btcdeb is working fine... which leads me to believe maybe something is wrong with my ledger. I want to verify the signature it generates against my public key, but i'm not sure how to do that. Hence, how can i verify a signature against a public key or address ?  
> **username_1**: Using btcdeb is the best way I can think of (as you need to reimplement VerifySignature, which btcdeb already support as it fokred bitcoin-core). Using DEBUG_SIGNING=1 DEBUG_SIGHASH=1 it will show you which signature is checked against which pubkey, and whether it's valid.  
> **username_3**: I have added experimental support to btcdeb where it will detect and inform the user of incorrectly placed signatures. Running that on the above example, however, did not indicate that this was the case, so the problem is most likely not placement. https://github.com/kallewoof/btcdeb/pull/52  

---

