Bitcoin Forum
May 05, 2024, 09:26:03 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to verify ECDSA of a sample litecoin tx using pycoin?  (Read 5041 times)
StephenMorse (OP)
Member
**
Offline Offline

Activity: 88
Merit: 12


View Profile
October 29, 2014, 03:23:46 AM
 #1

The question is laid out here: http://bitcoin.stackexchange.com/questions/32194/how-to-verify-ecdsa-of-a-sample-litecoin-tx-using-pycoin

Looking for some help, might even give a BTC tip for a really good answer!
1714944363
Hero Member
*
Offline Offline

Posts: 1714944363

View Profile Personal Message (Offline)

Ignore
1714944363
Reply with quote  #2

1714944363
Report to moderator
1714944363
Hero Member
*
Offline Offline

Posts: 1714944363

View Profile Personal Message (Offline)

Ignore
1714944363
Reply with quote  #2

1714944363
Report to moderator
"If you don't want people to know you're a scumbag then don't be a scumbag." -- margaritahuyan
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714944363
Hero Member
*
Offline Offline

Posts: 1714944363

View Profile Personal Message (Offline)

Ignore
1714944363
Reply with quote  #2

1714944363
Report to moderator
hhanh00
Sr. Member
****
Offline Offline

Activity: 467
Merit: 266


View Profile
October 29, 2014, 08:49:09 AM
 #2

Did you try reversing the bytes of the hash? The ToString() seems to be flipping them.

StephenMorse (OP)
Member
**
Offline Offline

Activity: 88
Merit: 12


View Profile
October 29, 2014, 05:03:12 PM
 #3

I had not tried reversing the hash. I tried, still no luck.

Thank you, though.
hhanh00
Sr. Member
****
Offline Offline

Activity: 467
Merit: 266


View Profile
October 30, 2014, 02:18:37 AM
 #4

Should work with the hash reversed

Code:
    Security.addProvider(new BouncyCastleProvider())
    val bigR = BigInt(Hex.decode("258ad2725e66da0ae9825bb849a8e73f86e4767cf256c9fae44d18fbc1aacc2e"))
    val bigS = BigInt(Hex.decode("406638a5b3369bb83d8a4f38a17b2f048c1495ebfd6fdff1a8c7b268e07f69cd"))
    val pub = Hex.decode("03ec539eb3d882c07575f6143d891c18d580cd9d2726add0d71d262f2f6f2d4ccf")
    val hash = Hex.decode("eed300fc63a973b668af66af746fde378ec6556f4b330ec1eeccc6a77aa535b0")
    ArrayUtils.reverse(hash)

    val f = KeyFactory.getInstance("ECDSA", "BC");
    val ecSpec = ECNamedCurveTable.getParameterSpec("secp256k1")
    val ecDomain = new ECDomainParameters(ecSpec.getCurve, ecSpec.getG, ecSpec.getN)
    val signer = new ECDSASigner

    val pubKey = ecSpec.getCurve().decodePoint(pub)
    val params = new ECPublicKeyParameters(pubKey, ecDomain)
    signer.init(false, params)
    val check = signer.verifySignature(hash, bigR.bigInteger, bigS.bigInteger)
   
    println(bigR, bigS)
    println(pubKey)
    println(Hex.toHexString(hash))
    println(check)

Code:
(16980852742628685644910148209432903671752523748137798365042615749252787915822,29128631674996429161026020280872095602306489412358940898112602484852964420045)
(ec539eb3d882c07575f6143d891c18d580cd9d2726add0d71d262f2f6f2d4ccf,227874efbedb02b88568b55106634b9b4e3eca128ab46fa98abe7066aece0a51,1)
b035a57aa7c6cceec10e334b6f55c68e37de6f74af66af68b673a963fc00d3ee
true

StephenMorse (OP)
Member
**
Offline Offline

Activity: 88
Merit: 12


View Profile
October 30, 2014, 04:24:48 AM
 #5

Thank you very much! Seeing your ArrayUtils.reverse clarified what the issue was for me.

When I reversed the hash, I turned "1234" into "4321", where as it should have been "3412".
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!