<p>OP_CHECKSIG needs to have the whole transaction to hash and to verify the tx. Btcdeb has the feature of allowing the tx as an argument however the website you linked doesn't hence this opcode is doomed to fail every time on this website.</p>
<p>It is reasonable to expect supplying the signature to verify the script/tx because otherwise to steal his coins, I would be able to copy one of his signatures and put them in my transactions.</p>
<p>Therefore I do suggest downloading and using the complete btcdeb.</p>

CC BY-SA 4.0
2021-01-11T20:07:11.653Z
2021-01-11T20:23:21.260Z
2021-01-11T20:23:21.260Z
MCCCS
<p>I'm try to get to grips with verifying the signature of a P2PKH transaction.</p>
<p>I have an example <a href="https://blockchair.com/bitcoin/transaction/9ec4bc49e828d924af1d1029cacf709431abbde46d59554b62bc270e3b29c4b1" rel="nofollow noreferrer">transaction</a>:</p>
<pre><code>9ec4bc49e828d924af1d1029cacf709431abbde46d59554b62bc270e3b29c4b1
</code></pre>
<p>I am trying to verify the signature of the first input in this transaction using <code>OP_CHECKSIG</code>.  The JSON is:</p>
<pre><code>{
   &quot;txid&quot;:&quot;9ec4bc49e828d924af1d1029cacf709431abbde46d59554b62bc270e3b29c4b1&quot;,
   &quot;hash&quot;:&quot;9ec4bc49e828d924af1d1029cacf709431abbde46d59554b62bc270e3b29c4b1&quot;,
   &quot;version&quot;:1,
   &quot;size&quot;:402,
   &quot;vsize&quot;:402,
   &quot;weight&quot;:1608,
   &quot;locktime&quot;:0,
   &quot;vin&quot;:[
      {
         &quot;txid&quot;:&quot;01f7ba55e5baac3d9cbc38722b19c07cb0cd2d2b25f4c270af4d9f2f3e604cf6&quot;,
         &quot;vout&quot;:1,
         &quot;scriptSig&quot;:{
            &quot;asm&quot;:&quot;30440220d47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad1022044e1ff2dfd8102cf7a47c21d5c9fd5701610d04953c6836596b4fe9dd2f53e3e01 04dbd0c61532279cf72981c3584fc32216e0127699635c2789f549e0730c059b81ae133016a69c21e23f1859a95f06d52b7bf149a8f2fe4e8535c8a829b449c5ff&quot;,
            &quot;hex&quot;:&quot;4730440220d47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad1022044e1ff2dfd8102cf7a47c21d5c9fd5701610d04953c6836596b4fe9dd2f53e3e014104dbd0c61532279cf72981c3584fc32216e0127699635c2789f549e0730c059b81ae133016a69c21e23f1859a95f06d52b7bf149a8f2fe4e8535c8a829b449c5ff&quot;
         },
         &quot;sequence&quot;:4294967295
      },
      {
         &quot;txid&quot;:&quot;4a85d9c86ba415f489be1ec68f67e862e9c3d8d13c892a3afacaa02bdb41f829&quot;,
         &quot;vout&quot;:1,
         &quot;scriptSig&quot;:{
            &quot;asm&quot;:&quot;30440220d47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad102209a5f1c75e461d7ceb1cf3cab9013eb2dc85b6d0da8c3c6e27e3a5a5b3faa5bab01 04dbd0c61532279cf72981c3584fc32216e0127699635c2789f549e0730c059b81ae133016a69c21e23f1859a95f06d52b7bf149a8f2fe4e8535c8a829b449c5ff&quot;,
            &quot;hex&quot;:&quot;4730440220d47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad102209a5f1c75e461d7ceb1cf3cab9013eb2dc85b6d0da8c3c6e27e3a5a5b3faa5bab014104dbd0c61532279cf72981c3584fc32216e0127699635c2789f549e0730c059b81ae133016a69c21e23f1859a95f06d52b7bf149a8f2fe4e8535c8a829b449c5ff&quot;
         },
         &quot;sequence&quot;:4294967295
      }
   ],
   &quot;vout&quot;:[
      {
         &quot;value&quot;:0.001,
         &quot;n&quot;:0,
         &quot;scriptPubKey&quot;:{
            &quot;asm&quot;:&quot;OP_DUP OP_HASH160 70792fb74a5df745bac07df6fe020f871cbb293b OP_EQUALVERIFY OP_CHECKSIG&quot;,
            &quot;hex&quot;:&quot;76a91470792fb74a5df745bac07df6fe020f871cbb293b88ac&quot;,
            &quot;reqSigs&quot;:1,
            &quot;type&quot;:&quot;pubkeyhash&quot;,
            &quot;addresses&quot;:[
               &quot;1BFhrfTTZP3Nw4BNy4eX4KFLsn9ZeijcMm&quot;
            ]
         }
      }
   ]
}
</code></pre>
<p>From this I have defined the script to do the <code>OP_CHECKSIG</code> as:</p>
<pre><code>OP_PUSHDATA1 71 0x30440220d47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad1022044e1ff2dfd8102cf7a47c21d5c9fd5701610d04953c6836596b4fe9dd2f53e3e01

OP_PUSHDATA1 65 0x04dbd0c61532279cf72981c3584fc32216e0127699635c2789f549e0730c059b81ae133016a69c21e23f1859a95f06d52b7bf149a8f2fe4e8535c8a829b449c5ff

OP_DUP OP_HASH160 20 0x70792fb74a5df745bac07df6fe020f871cbb293b OP_EQUALVERIFY OP_CHECKSIG
</code></pre>
<p>Everything runs correctly up until the <code>OP_CHECKSIG</code>.  The HASH160 is correct (<code>70792fb74a5df745bac07df6fe020f871cbb293b</code> == <code>70792fb74a5df745bac07df6fe020f871cbb293b</code>) and <code>OP_EQUALVERIFY</code> completes as expected.</p>
<p>The <code>OP_CHECKSIG</code> fails, but I don't understand why.  Please can someone shed some light on what I've got wrong here?</p>

CC BY-SA 4.0
2021-01-11T19:07:30.750Z
Where do you run this? `OP_CHECKSIG` needs the whole tx
MCCCS
CC BY-SA 4.0
2021-01-11T19:07:43.180Z
Checkout https://github.com/bitcoin-core/btcdeb for debugging Script :)
Antoine Poinsot
CC BY-SA 4.0
2021-01-11T19:08:30.810Z
https://github.com/bitcoin-core/btcdeb/blob/991348d7ec208f3c95e83bf77a1e82f2c01394ab/doc/btcdeb.md#signature-checking ?
MCCCS
CC BY-SA 4.0
2021-01-11T19:50:05.457Z
@MCCCS I'm using an online tool to test it: https://bitcoin-script-debugger.visvirial.com/.  Based on the comments, I think I'm maybe supplying the incorrect information
Martin
<signature><transaction-verification><message-signing><checksig>
Can't Make Sense of Why OP_CHECKSIG Fails Here
Martin
# Can't Make Sense of Why OP_CHECKSIG Fails Here

(Asked by: username_0 on 2021-01-11)

I'm try to get to grips with verifying the signature of a P2PKH transaction.

I have an example [transaction](https://blockchair.com/bitcoin/transaction/9ec4bc49e828d924af1d1029cacf709431abbde46d59554b62bc270e3b29c4b1):

```
9ec4bc49e828d924af1d1029cacf709431abbde46d59554b62bc270e3b29c4b1

```

I am trying to verify the signature of the first input in this transaction using `OP_CHECKSIG`. The JSON is:

```
{
   "txid":"9ec4bc49e828d924af1d1029cacf709431abbde46d59554b62bc270e3b29c4b1",
   "hash":"9ec4bc49e828d924af1d1029cacf709431abbde46d59554b62bc270e3b29c4b1",
   "version":1,
   "size":402,
   "vsize":402,
   "weight":1608,
   "locktime":0,
   "vin":[
      {
         "txid":"01f7ba55e5baac3d9cbc38722b19c07cb0cd2d2b25f4c270af4d9f2f3e604cf6",
         "vout":1,
         "scriptSig":{
            "asm":"30440220d47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad1022044e1ff2dfd8102cf7a47c21d5c9fd5701610d04953c6836596b4fe9dd2f53e3e01 04dbd0c61532279cf72981c3584fc32216e0127699635c2789f549e0730c059b81ae133016a69c21e23f1859a95f06d52b7bf149a8f2fe4e8535c8a829b449c5ff",
            "hex":"4730440220d47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad1022044e1ff2dfd8102cf7a47c21d5c9fd5701610d04953c6836596b4fe9dd2f53e3e014104dbd0c61532279cf72981c3584fc32216e0127699635c2789f549e0730c059b81ae133016a69c21e23f1859a95f06d52b7bf149a8f2fe4e8535c8a829b449c5ff"
         },
         "sequence":4294967295
      },
      {
         "txid":"4a85d9c86ba415f489be1ec68f67e862e9c3d8d13c892a3afacaa02bdb41f829",
         "vout":1,
         "scriptSig":{
            "asm":"30440220d47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad102209a5f1c75e461d7ceb1cf3cab9013eb2dc85b6d0da8c3c6e27e3a5a5b3faa5bab01 04dbd0c61532279cf72981c3584fc32216e0127699635c2789f549e0730c059b81ae133016a69c21e23f1859a95f06d52b7bf149a8f2fe4e8535c8a829b449c5ff",
            "hex":"4730440220d47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad102209a5f1c75e461d7ceb1cf3cab9013eb2dc85b6d0da8c3c6e27e3a5a5b3faa5bab014104dbd0c61532279cf72981c3584fc32216e0127699635c2789f549e0730c059b81ae133016a69c21e23f1859a95f06d52b7bf149a8f2fe4e8535c8a829b449c5ff"
         },
         "sequence":4294967295
      }
   ],
   "vout":[
      {
         "value":0.001,
         "n":0,
         "scriptPubKey":{
            "asm":"OP_DUP OP_HASH160 70792fb74a5df745bac07df6fe020f871cbb293b OP_EQUALVERIFY OP_CHECKSIG",
            "hex":"76a91470792fb74a5df745bac07df6fe020f871cbb293b88ac",
            "reqSigs":1,
            "type":"pubkeyhash",
            "addresses":[
               "1BFhrfTTZP3Nw4BNy4eX4KFLsn9ZeijcMm"
            ]
         }
      }
   ]
}

```

From this I have defined the script to do the `OP_CHECKSIG` as:

```
OP_PUSHDATA1 71 0x30440220d47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad1022044e1ff2dfd8102cf7a47c21d5c9fd5701610d04953c6836596b4fe9dd2f53e3e01

OP_PUSHDATA1 65 0x04dbd0c61532279cf72981c3584fc32216e0127699635c2789f549e0730c059b81ae133016a69c21e23f1859a95f06d52b7bf149a8f2fe4e8535c8a829b449c5ff

OP_DUP OP_HASH160 20 0x70792fb74a5df745bac07df6fe020f871cbb293b OP_EQUALVERIFY OP_CHECKSIG

```

Everything runs correctly up until the `OP_CHECKSIG`. The HASH160 is correct (`70792fb74a5df745bac07df6fe020f871cbb293b` == `70792fb74a5df745bac07df6fe020f871cbb293b`) and `OP_EQUALVERIFY` completes as expected.

The `OP_CHECKSIG` fails, but I don't understand why. Please can someone shed some light on what I've got wrong here?

**Tags:** signature, transaction-verification, message-signing, checksig

> **Comments:**
> **username_1**: Where do you run this? `OP_CHECKSIG` needs the whole tx  
> **username_2**: Checkout https://github.com/bitcoin-core/btcdeb for debugging Script :)  
> **username_1**: https://github.com/bitcoin-core/btcdeb/blob/991348d7ec208f3c95e83bf77a1e82f2c01394ab/doc/btcdeb.md#signature-checking ?  
> **username_0**: @username_1 I'm using an online tool to test it: https://bitcoin-script-debugger.visvirial.com/.  Based on the comments, I think I'm maybe supplying the incorrect information  

---

## 1 answers

### Answer by username_1 on 2021-01-11. Score: 2

OP\_CHECKSIG needs to have the whole transaction to hash and to verify the tx. Btcdeb has the feature of allowing the tx as an argument however the website you linked doesn't hence this opcode is doomed to fail every time on this website.

It is reasonable to expect supplying the signature to verify the script/tx because otherwise to steal his coins, I would be able to copy one of his signatures and put them in my transactions.

Therefore I do suggest downloading and using the complete btcdeb.


---

