<p>There are a lot of things to keep track of when verifying.</p>
<ol>
<li>Did you encode your data according to the proper sighash byte?</li>
<li>Are you using the correct key to verify?</li>
<li>Did you hash the data you are verifying?</li>
<li>Did you add the four bytes representing the sighash byte to your data?</li>
</ol>
<p>So, for the transaction you mentioned, there is only one input that contains a signature that ends with sighash byte 01. Sighash byte 01 means we basically use the raw transaction as our data. If there had been multiple inputs, we would use zero-length scripts for the inputs we are not verifying, but in this case we only have one. But we do have to put a 4-byte little endian value at the end of the data to represent the sighash byte.</p>
<p>So this is the data that I believe needs to be verified.</p>
<pre><code>01000000

01

c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd3704
00000000
43410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac
ffffffff

02

00ca9a3b00000000
434104ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84cac

00286bee00000000
43410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac

00000000
01000000
</code></pre>
<p>Notice the <code>01000000</code> at the end. That represents the sighash byte which has to be signed along with the rest of the data.</p>
<p>I'm not familiar with the library you mentioned, but many of them will work. Typically, you need to pass the data and its length, the signature and the public key being verified. Since the signatures in bitcoin transactions usually have a sighash byte stuck on the end of them, you'll need to remove that byte before passing it to the function you use to verify.</p>
<p>If you serialize all of the bytes above into one message, convert it to binary and apply a double sha256 to it, I bet you can verify it with the public key included in the previous output's script.</p>

CC BY-SA 4.0
2022-11-29T18:59:30.407Z
Got the same, except for the script sig at line 5, which I tought had to be replaced by 0...
RooSoft
CC BY-SA 4.0
2022-11-29T19:04:02.247Z
reference, point 7 here: https://en.bitcoin.it/wiki/OP_CHECKSIG#How_it_works
RooSoft
CC BY-SA 4.0
2022-11-29T21:39:07.227Z
Usually, you would set them all to length zero as explained in step 7, and then in step 8 it says to include just the script for the input you are verifying. However, with the transaction we're looking at there is only one input, so we can just use it as is.
Zephyrus
CC BY-SA 4.0
2022-11-29T17:06:43.727Z
2022-11-29T17:06:43.727Z
Zephyrus
<p>In the process of validating transactions by hand with a new library in elixir. I am starting with <code>f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16</code>, which is one of the first <code>P2PK</code> transactions ever made.</p>
<p>I am struggling to manually validate that transaction with the <code>secp256k1</code> library included with the language.</p>
<p>It probably has something to do with my code. Most probably is when I strip the signature, creating the message to be signed with the public key, in the process of verifying the signature, or how I encode things, I don't know.</p>
<p>In the process of solving that mystery, I've spent countless hours in vain trying to find a super detailed step-by-step validation of an early transaction.</p>
<p>Might be enough to just know a txid and the exact bytes being sent to a secp256k1 verifying function, so I make sure my code does the same.</p>
<p>In the event that such a document exists somewhere I'd be grateful to be pointed towards it.</p>

CC BY-SA 4.0
2022-11-29T16:49:31.857Z
Hey, the “message” input, i.e. the digest of the transaction that is being committed to by the signature in Bitcoin transactions is called “signature hash” or [tag:sighash]. I think this might be useful: https://bitcoin.stackexchange.com/a/95750/5406
Murch
CC BY-SA 4.0
2022-11-29T16:59:44.830Z
I got to know exactly what "delete all the script signatures in the raw transaction" means... I am replacing it with `0100` which means one byte that equals to zero. Not 100% it's what's needed.
RooSoft
CC BY-SA 4.0
2022-11-29T19:13:11.870Z
I was mistaken, it's `00`.
RooSoft
<transaction-verification><validation><secp256k1><p2pk>
Need a detailed step-by-step P2PK signature validation example
RooSoft
# Need a detailed step-by-step P2PK signature validation example

(Asked by: username_0 on 2022-11-29)

In the process of validating transactions by hand with a new library in elixir. I am starting with `f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16`, which is one of the first `P2PK` transactions ever made.

I am struggling to manually validate that transaction with the `secp256k1` library included with the language.

It probably has something to do with my code. Most probably is when I strip the signature, creating the message to be signed with the public key, in the process of verifying the signature, or how I encode things, I don't know.

In the process of solving that mystery, I've spent countless hours in vain trying to find a super detailed step-by-step validation of an early transaction.

Might be enough to just know a txid and the exact bytes being sent to a secp256k1 verifying function, so I make sure my code does the same.

In the event that such a document exists somewhere I'd be grateful to be pointed towards it.

**Tags:** transaction-verification, validation, secp256k1, p2pk

> **Comments:**
> **username_1**: Hey, the “message” input, i.e. the digest of the transaction that is being committed to by the signature in Bitcoin transactions is called “signature hash” or [tag:sighash]. I think this might be useful: https://bitcoin.stackexchange.com/a/95750/5406  
> **username_0**: I got to know exactly what "delete all the script signatures in the raw transaction" means... I am replacing it with `0100` which means one byte that equals to zero. Not 100% it's what's needed.  
> **username_0**: I was mistaken, it's `00`.  

---

## 1 answers

### Answer by username_2 on 2022-11-29. Score: 1

There are a lot of things to keep track of when verifying.

1. Did you encode your data according to the proper sighash byte?
2. Are you using the correct key to verify?
3. Did you hash the data you are verifying?
4. Did you add the four bytes representing the sighash byte to your data?

So, for the transaction you mentioned, there is only one input that contains a signature that ends with sighash byte 01. Sighash byte 01 means we basically use the raw transaction as our data. If there had been multiple inputs, we would use zero-length scripts for the inputs we are not verifying, but in this case we only have one. But we do have to put a 4-byte little endian value at the end of the data to represent the sighash byte.

So this is the data that I believe needs to be verified.

```
01000000

01

c997a5e56e104102fa209c6a852dd90660a20b2d9c352423edce25857fcd3704
00000000
43410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac
ffffffff

02

00ca9a3b00000000
434104ae1a62fe09c5f51b13905f07f06b99a2f7159b2225f374cd378d71302fa28414e7aab37397f554a7df5f142c21c1b7303b8a0626f1baded5c72a704f7e6cd84cac

00286bee00000000
43410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac

00000000
01000000

```

Notice the `01000000` at the end. That represents the sighash byte which has to be signed along with the rest of the data.

I'm not familiar with the library you mentioned, but many of them will work. Typically, you need to pass the data and its length, the signature and the public key being verified. Since the signatures in bitcoin transactions usually have a sighash byte stuck on the end of them, you'll need to remove that byte before passing it to the function you use to verify.

If you serialize all of the bytes above into one message, convert it to binary and apply a double sha256 to it, I bet you can verify it with the public key included in the previous output's script.

> **Comments:**
> **username_0**: Got the same, except for the script sig at line 5, which I tought had to be replaced by 0...  
> **username_0**: reference, point 7 here: https://en.bitcoin.it/wiki/OP_CHECKSIG#How_it_works  
> **username_2**: Usually, you would set them all to length zero as explained in step 7, and then in step 8 it says to include just the script for the input you are verifying. However, with the transaction we're looking at there is only one input, so we can just use it as is.  

---

