0

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?

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:

# <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, 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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.