Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: elpanxaaa on May 06, 2020, 02:13:54 PM



Title: Calculate z and z1 from ECDSA Signature
Post by: elpanxaaa on May 06, 2020, 02:13:54 PM
Can anyone explain me any clearly answer or code in python with examples how we can calculate z and z' value fromECDSA Signature order? I search in google and youtube and i not saw any correctly answer i just see scam posts or video in youtube.
I Saw this explain at 2Coin.org but this page is not active anymore, who can help me with python code and to calculate manualy how to get z and z' from ECDSA Signature.

Example:

https://blockchain.info/tx/9ec4bc49e828d924af1d1029cacf709431abbde46d59554b62bc270e3b29c4b1

from this transaction we have:

ScriptSig: PUSHDATA(71)[30440220d47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad1022044e1ff2dfd8102cf7a47c21d5c9fd5701610d04953c6836596b4fe9dd2f53e3e01] PUSHDATA(65)[04dbd0c61532279cf72981c3584fc32216e0127699635c2789f549e0730c059b81ae133016a69c21e23f1859a95f06d52b7bf149a8f2fe4e8535c8a829b449c5ff]

ScriptSig: PUSHDATA(71)[30440220d47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad102209a5f1c75e461d7ceb1cf3cab9013eb2dc85b6d0da8c3c6e27e3a5a5b3faa5bab01] PUSHDATA(65)[04dbd0c61532279cf72981c3584fc32216e0127699635c2789f549e0730c059b81ae133016a69c21e23f1859a95f06d52b7bf149a8f2fe4e8535c8a829b449c5ff]


r1: d47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad1
r2: d47ce4c025c35ec440bc81d99834a624875161a26bf56ef7fdc0f5d52f843ad1

s1: 44e1ff2dfd8102cf7a47c21d5c9fd5701610d04953c6836596b4fe9dd2f53e3e
s2: 9a5f1c75e461d7ceb1cf3cab9013eb2dc85b6d0da8c3c6e27e3a5a5b3faa5bab

how we can calculate z and z1 with this info ? is anyone have any code in python ?
 

thank you in advance


Title: Re: Calculate z and z1 from ECDSA Signature
Post by: MixMAx123 on May 07, 2020, 04:51:48 PM
Can you please describe what the variable "z" represents?


Title: Re: Calculate z and z1 from ECDSA Signature
Post by: coinlatte on May 08, 2020, 08:32:19 AM
I guess that z and z' has the same meaning as in this Wikipedia article (https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm#Signature_generation_algorithm). If so, then z is simplified transaction hash. All you need to do is just calculate SHA-256(simplified_transaction) and that will be your z. The same for z', it will be just another simplified transaction signed using the same k value. Here you have two inputs, so for each of them you should create two different simplified transactions. Here is some example (https://bitcoin.stackexchange.com/questions/41209/how-to-sign-a-transaction-with-multiple-inputs).


Title: Re: Calculate z and z1 from ECDSA Signature
Post by: pooya87 on May 08, 2020, 02:26:00 PM
I guess that z and z' has the same meaning as in this Wikipedia article (https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm#Signature_generation_algorithm). If so, then z is simplified transaction hash. All you need to do is just calculate SHA-256(simplified_transaction) and that will be your z. The same for z', it will be just another simplified transaction signed using the same k value. Here you have two inputs, so for each of them you should create two different simplified transactions. Here is some example (https://bitcoin.stackexchange.com/questions/41209/how-to-sign-a-transaction-with-multiple-inputs).

it is not "simplified", the transaction is instead "modified" and it is a complicated process. and the example you shared like many others on SE are only covering a small portion of the entire difference cases so they only work for that special case which is usually spending a legacy P2PKH output with SIGHASH_ALL.
FWIW starter doesn't seem to communicate back at all. he already has another duplicate of this topic in another board and also asking the same 2 questions on SE.