Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: edmundedgar on June 21, 2014, 09:37:16 AM



Title: Handiest way to verify a signature in isolation
Post by: edmundedgar on June 21, 2014, 09:37:16 AM
So I've been hacking on bitcore.io (http://bitcore.io) trying to do some (hopefully not for much longer, Inshallah (https://github.com/bitcoin/bitcoin/pull/4365)) non-standard transactions with it, and I'm finding they're getting rejected by my testnet node for being invalid. I can generate the same transactions with a python script I made earlier and get them accepted and mined OK, and the hash that's getting passed to the sign code seems to be the same in both cases, so I reckon I'm somehow screwing up the actual signature creation rather than elsewhere in the script, but I'd like to test the signatures in isolation to be sure and confirm that the ones getting created by my JavaScript are definitely wonky where the ones created by my Python code are good.

Any suggestions for an easy, hard-to-screw-up-when-sleep-deprived way to verify a signature in isolation? I'm wondering if I can do something like (made-up options follow):
Code:
openssl --i-would-like-to-verify-a-signature-please --ecdsa-something-or-other <pubkey> <hash_that_gets_passed_in_for_signing> <signature>


Title: Re: Handiest way to verify a signature in isolation
Post by: dexX7 on June 21, 2014, 06:19:37 PM
Probably not exatly what you are looking for, but you may could give python-bitcoinlib a try:

https://github.com/petertodd/python-bitcoinlib/blob/master/examples/spend-pay-to-script-hash-txout.py


Title: Re: Handiest way to verify a signature in isolation
Post by: 12648430 on June 21, 2014, 06:49:07 PM
bitcoind has some unit tests that are exactly what you want; you could copy one, put in your own values, and run it as a bitcoind test. You could do it with openssl but you'd probably need to convert the pubkey into an openssl-compatible format somehow.


Title: Re: Handiest way to verify a signature in isolation
Post by: edmundedgar on June 26, 2014, 07:21:45 AM
Thanks for the suggestions. I ended up doing it the other way: Instead of verifying the signatures my JavaScript was emitting, I plugged in a couple of signatures for the same transaction from my Python code to prove that the rest of the JavaScript was OK and figured it out that way. (Seems like my signatures were OK but I had them in the wrong order, which results in OP_CHECKMULTISIG reporting an invalid signature???)


Title: Re: Handiest way to verify a signature in isolation
Post by: Aleksei Richards on June 26, 2014, 01:16:39 PM
Thanks for the suggestions. I ended up doing it the other way: Instead of verifying the signatures my JavaScript was emitting, I plugged in a couple of signatures for the same transaction from my Python code to prove that the rest of the JavaScript was OK and figured it out that way. (Seems like my signatures were OK but I had them in the wrong order, which results in OP_CHECKMULTISIG reporting an invalid signature???)

Yes you do need them in the correct order as I've just found out.