0

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

I have an example transaction:

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?

4

1 Answer 1

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.

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.