<p>AFAICT, the script is not invalid. Rather the website is failing to validate the script properly.</p>

<p>OP_CHECKSIG checks the digital signature (interpreted as the first stack item) against the public key (the second stack item). However a digital signature requires a third component: the message that is signed. In Bitcoin, that message is the transaction itself (with some modification).</p>

<p>The problem here is that the script interpreter on the website does not have anywhere where you can enter the transaction or message being signed. Thus, without a message, OP_CHECKSIG will always verify to false for any valid Bitcoin script with OP_CHECKSIG.</p>

CC BY-SA 3.0
2018-04-23T02:44:06.323Z
2018-04-23T02:44:06.323Z
Ava Chow
<p>I have played with the tool for some hours, but couldn't get a single signature to work. Here is what I entered for the famous <a href="https://blockchain.info/tx/cca7507897abc89628f450e8b1e0c6fca4ec3f7b34cccf55f3f531c659ff4d79" rel="nofollow noreferrer">PIZZA transaction</a>:</p>

<pre><code># &lt;sig&gt;
OP_PUSHDATA1 71 0x30450221009908144CA6539E09512B9295C8A27050D478FBB96F8ADDBC3D075544DC41328702201AA528BE2B907D316D2DA068DD9EB1E23243D97E444D59290D2FDDF25269EE0E
# &lt;pubKey&gt;
OP_PUSHDATA1 65 0x042E930F39BA62C6534EE98ED20CA98959D34AA9E057CDA01CFD422C6BAB3667B76426529382C23F42B9B08D7832D4FEE1D6B437A8526E59667CE9C4E9DCEBCABB

OP_DUP OP_HASH160
# &lt;pubkeyHash&gt;
20 0x46af3fb481837fadbb421727f9959c2d32a36829
OP_EQUALVERIFY OP_CHECKSIG
</code></pre>

<p>The script's content would execute correctly the OP_DUP and OP_HASH160, so the results on the stack match the OP_EQUALVERIFY. Then OP_CHECKSIG returns false... Checking with openssl returns true. </p>

<blockquote>
  <p>Is there a way to manually verify that the example digital
  signature/public key pair matches, or to generate matching pairs that
  don't contain or link to my actual Bitcoin addresses, in order to
  experiment with the Script debugger?</p>
</blockquote>

<p>yes, I usually have OPENSSL to give me a helping hand. But any ECDSA library should do. A normal P2PKH tx is converted into unsigned format, and the input script is replaced with previous tx' output script (and lengths adapted). This raw tx is then double sha256'd, and the result signed. This hash value can easily be checked with openssl, the signature and the pubkey. I posted <a href="https://bitcoin.stackexchange.com/questions/46455/verifying-a-bitcoin-trx-on-the-unix-cmd-line-with-openssl">this ~2 years ago</a>, and got help from Dave. </p>

<p>How to come to the unsigned transaction is explained by @amaclin's answer in the first link (--> How does the ECDSA verification...). Openssl requires a PEM key to verify, so some conversion takes place from pubkey to PEM format. And then bitcoin works with raw (hex) data, not strings. Hence the efforts to convert with xxd on Linux systems, or with sed and [:xdigit:] on BSD type systems. If you are on unixoide systems, I can provide a script. </p>

<blockquote>
  <p>how can I generate valid public key/digital signature pairs?</p>
</blockquote>

<p>Maybe "generate" is not the correct word here, but one can take any tx from the blockchain, and extract the elements (raw tx, sig, pubkey, prev tx pubkey hash), and push it through the process described above. </p>

CC BY-SA 3.0
2018-04-22T20:23:14.843Z
2018-04-22T20:23:14.843Z
pebwindkraft
<p>Why does the default P2PKH transaction at <a href="http://bitcoin-script-debugger.visvirial.com/" rel="nofollow noreferrer">http://bitcoin-script-debugger.visvirial.com/</a> return NULL rather than true?  I haven't tried to swallow the gory details of OP_CHECKSIG yet, but everything else looks solid.</p>

<p>Is there a way to manually verify that the example digital signature/public key pair matches, or to generate matching pairs that don't contain or link to my actual Bitcoin addresses, in order to experiment with the Script debugger?</p>

<hash><script><public-key><signature><p2pkh>
Why is this script invalid, and how can I generate valid public key/digital signature pairs?
user78281
# Why is this script invalid, and how can I generate valid public key/digital signature pairs?

(Asked by: username_0 on 2018-03-06)

Why does the default P2PKH transaction at <http://bitcoin-script-debugger.visvirial.com/> return NULL rather than true? I haven't tried to swallow the gory details of OP\_CHECKSIG yet, but everything else looks solid.

Is there a way to manually verify that the example digital signature/public key pair matches, or to generate matching pairs that don't contain or link to my actual Bitcoin addresses, in order to experiment with the Script debugger?

**Tags:** hash, script, public-key, signature, p2pkh


---

## 2 answers

### Answer by username_1 on 2018-04-23. Score: 1

AFAICT, the script is not invalid. Rather the website is failing to validate the script properly.

OP\_CHECKSIG checks the digital signature (interpreted as the first stack item) against the public key (the second stack item). However a digital signature requires a third component: the message that is signed. In Bitcoin, that message is the transaction itself (with some modification).

The problem here is that the script interpreter on the website does not have anywhere where you can enter the transaction or message being signed. Thus, without a message, OP\_CHECKSIG will always verify to false for any valid Bitcoin script with OP\_CHECKSIG.


---

### Answer by username_2 on 2018-04-22. Score: 1

I have played with the tool for some hours, but couldn't get a single signature to work. Here is what I entered for the famous [PIZZA transaction](https://blockchain.info/tx/cca7507897abc89628f450e8b1e0c6fca4ec3f7b34cccf55f3f531c659ff4d79):

```
# <sig>
OP_PUSHDATA1 71 0x30450221009908144CA6539E09512B9295C8A27050D478FBB96F8ADDBC3D075544DC41328702201AA528BE2B907D316D2DA068DD9EB1E23243D97E444D59290D2FDDF25269EE0E
# <pubKey>
OP_PUSHDATA1 65 0x042E930F39BA62C6534EE98ED20CA98959D34AA9E057CDA01CFD422C6BAB3667B76426529382C23F42B9B08D7832D4FEE1D6B437A8526E59667CE9C4E9DCEBCABB

OP_DUP OP_HASH160
# <pubkeyHash>
20 0x46af3fb481837fadbb421727f9959c2d32a36829
OP_EQUALVERIFY OP_CHECKSIG

```

The script's content would execute correctly the OP\_DUP and OP\_HASH160, so the results on the stack match the OP\_EQUALVERIFY. Then OP\_CHECKSIG returns false... Checking with openssl returns true.

> Is there a way to manually verify that the example digital
> signature/public key pair matches, or to generate matching pairs that
> don't contain or link to my actual Bitcoin addresses, in order to
> experiment with the Script debugger?

yes, I usually have OPENSSL to give me a helping hand. But any ECDSA library should do. A normal P2PKH tx is converted into unsigned format, and the input script is replaced with previous tx' output script (and lengths adapted). This raw tx is then double sha256'd, and the result signed. This hash value can easily be checked with openssl, the signature and the pubkey. I posted [this ~2 years ago](https://bitcoin.stackexchange.com/questions/46455/verifying-a-bitcoin-trx-on-the-unix-cmd-line-with-openssl), and got help from Dave.

How to come to the unsigned transaction is explained by @amaclin's answer in the first link (--> How does the ECDSA verification...). Openssl requires a PEM key to verify, so some conversion takes place from pubkey to PEM format. And then bitcoin works with raw (hex) data, not strings. Hence the efforts to convert with xxd on Linux systems, or with sed and [:xdigit:] on BSD type systems. If you are on unixoide systems, I can provide a script.

> how can I generate valid public key/digital signature pairs?

Maybe "generate" is not the correct word here, but one can take any tx from the blockchain, and extract the elements (raw tx, sig, pubkey, prev tx pubkey hash), and push it through the process described above.


---

