Bitcoin Forum
May 08, 2024, 05:30:48 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How can I verify ECDsa signature that I made?  (Read 164 times)
Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
September 21, 2018, 12:37:02 PM
 #1

I have been working on EC calculations, ECDsa signatures and DER-encoding, considering the randomness of the results and the fact that I am not using any kind of external libraries for any of the steps, I don't know how correct my resulting signatures are!

Lets take the transaction in this example with the following private key:
Code:
18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725

How can I verify whether the following transaction has a valid signature (ignore the fact that the transaction it is spending does not exist):
Code:
0100000001eccf7e3034189b851985d871f91384b8ee357cd47c3024736e5676eb2debb3f2010000006b473045022100c3835cd9615ad7bf13ce68498ca4262794f8e1b481020107234e99a675710b40022070cd0c818f53b937e308ce4a824e75657875b3dabeea2eb9e377f18efdeb86e901210250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352ffffffff01605af405000000001976a914097072524438d003d23a2f23edb65aae1bb3e46988ac00000000

I will try with TestNet coins later, but for now I would like to know which part I messed up (if any) for today.

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
1715189448
Hero Member
*
Offline Offline

Posts: 1715189448

View Profile Personal Message (Offline)

Ignore
1715189448
Reply with quote  #2

1715189448
Report to moderator
1715189448
Hero Member
*
Offline Offline

Posts: 1715189448

View Profile Personal Message (Offline)

Ignore
1715189448
Reply with quote  #2

1715189448
Report to moderator
Activity + Trust + Earned Merit == The Most Recognized Users on Bitcointalk
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715189448
Hero Member
*
Offline Offline

Posts: 1715189448

View Profile Personal Message (Offline)

Ignore
1715189448
Reply with quote  #2

1715189448
Report to moderator
1715189448
Hero Member
*
Offline Offline

Posts: 1715189448

View Profile Personal Message (Offline)

Ignore
1715189448
Reply with quote  #2

1715189448
Report to moderator
piotr_n
Legendary
*
Offline Offline

Activity: 2053
Merit: 1354


aka tonikt


View Profile WWW
September 21, 2018, 12:58:05 PM
 #2

This doesn't seem to be a valid transaction.

I think you rather meant:
Code:
0100000001eccf7e3034189b851985d871f91384b8ee357cd47c3024736e5676eb2debb3f2010000006a473045022100c3835cd9615ad7bf13ce68498ca4262794f8e1b481020107234e99a675710b40022070cd0c818f53b937e308ce4a824e75657875b3dabeea2eb9e377f18efdeb86e9210250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352ffffffff01605af405000000001976a914097072524438d003d23a2f23edb65aae1bb3e46988ac00000000

(there is an extra 01 in yours)

Then to verify the signature you also need the output script from the transaction that you are spending:
Code:
TxID: f2b3eb2deb76566e7324307cd47c35eeb88413f971d88519859b1834307ecfec
VOut: 1

Check out gocoin - my original project of full bitcoin node & cold wallet written in Go.
PGP fingerprint: AB9E A551 E262 A87A 13BB  9059 1BE7 B545 CDF3 FD0E
piotr_n
Legendary
*
Offline Offline

Activity: 2053
Merit: 1354


aka tonikt


View Profile WWW
September 21, 2018, 01:03:36 PM
 #3

In your case the output script you need will probably be:
Code:
76a914f54a5851e9372b87810a8e60cdd2e7cfd80b6e3188ac


Check out gocoin - my original project of full bitcoin node & cold wallet written in Go.
PGP fingerprint: AB9E A551 E262 A87A 13BB  9059 1BE7 B545 CDF3 FD0E
Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
September 21, 2018, 01:07:12 PM
 #4

(there is an extra 01 in yours)

That is not "extra", that is sigHashType (01 for signall).
An example tx from last block:
https://blockexplorer.com/api/rawtx/85478be31ee805af627562a4b30b44a3321acdf593fb72c99660065a0c7bf301
Quote
48
  30
  45
    02
    21
      008115527f88cf17c6a81ae98e5024ce9839faacba2c78d0005e7413be933397b4
    02
    20
      33792c5f9f76dae8346cab3e69a891101f65ec160bfaba823740a17784c38504
  01
21
  03f63338b081b576f9308066dd1b869eed6f999cff1f24620b416ea7b65fc4e8db

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
piotr_n
Legendary
*
Offline Offline

Activity: 2053
Merit: 1354


aka tonikt


View Profile WWW
September 21, 2018, 01:10:52 PM
Merited by Coding Enthusiast (5)
 #5

(there is an extra 01 in yours)

That is not "extra", that is sigHashType (01 for signall).

then your length fields are screwed up.

Code:
0100000001eccf7e3034189b851985d871f91384b8ee357cd47c3024736e5676eb2debb3f2010000006b483045022100c3835cd9615ad7bf13ce68498ca4262794f8e1b481020107234e99a675710b40022070cd0c818f53b937e308ce4a824e75657875b3dabeea2eb9e377f18efdeb86e901210250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352ffffffff01605af405000000001976a914097072524438d003d23a2f23edb65aae1bb3e46988ac00000000

Check out gocoin - my original project of full bitcoin node & cold wallet written in Go.
PGP fingerprint: AB9E A551 E262 A87A 13BB  9059 1BE7 B545 CDF3 FD0E
Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
September 21, 2018, 01:21:51 PM
 #6

then your length fields are screwed up.

YUP. That was it. Thanks.
I missed the fact that 47 (or the right one 48) is the size of the first stack Tongue I mistook it for a DER-length.

If I am not mistaken 48 should be a Compact size integer?

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!