Bitcoin Forum
April 24, 2024, 08:08:28 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: secp256k1 formula calculations  (Read 212 times)
krashfire (OP)
Jr. Member
*
Offline Offline

Activity: 96
Merit: 6

Life aint interesting without any cuts and bruises


View Profile
January 31, 2023, 05:44:57 AM
 #1

Hi, i need help to check my code.

Code:

import ecdsa

z = int(input("Enter value of z: "))
r = int(input("Enter value of r: "))
k = int(input("Enter value of k: "))
s = int(input("Enter value of s: "))

private_key = (z + (r * k)) / s

print("Private Key =", private_key)


and after giving my inputs, i got this output, Private Key = 2.378864885847563e+77
I just wanna make sur.  is my formula written correctly?

and how do i actually read that answer? i tried googling but i cant get an answer on how do I read it as integer.

KRASH
1713989308
Hero Member
*
Offline Offline

Posts: 1713989308

View Profile Personal Message (Offline)

Ignore
1713989308
Reply with quote  #2

1713989308
Report to moderator
1713989308
Hero Member
*
Offline Offline

Posts: 1713989308

View Profile Personal Message (Offline)

Ignore
1713989308
Reply with quote  #2

1713989308
Report to moderator
In order to achieve higher forum ranks, you need both activity points and merit points.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713989308
Hero Member
*
Offline Offline

Posts: 1713989308

View Profile Personal Message (Offline)

Ignore
1713989308
Reply with quote  #2

1713989308
Report to moderator
1713989308
Hero Member
*
Offline Offline

Posts: 1713989308

View Profile Personal Message (Offline)

Ignore
1713989308
Reply with quote  #2

1713989308
Report to moderator
garlonicon
Hero Member
*****
Offline Offline

Activity: 799
Merit: 1932


View Profile
January 31, 2023, 06:22:46 AM
Merited by hugeblack (4), Welsh (2), ABCbits (1)
 #2

It is invalid, because:

1. You have to calculate it modulo "n".
2. The correct formula is "s=(z+rd)/k", so your private key "d" is "(sk-z)/r".

Also, if 256-bit numbers are too big for you to start with, then compute everything on smaller numbers first: https://www.coindesk.com/markets/2014/10/19/the-math-behind-the-bitcoin-protocol/

Hold your horses before deploying blockchain-related things. You don't want to deploy SHA-1 collision without deploying hardened SHA-1. Once you reveal some code, and make it Open Source, there is no "undo" button. Once you share some idea, there is no way to erase it from reader's memory.
witcher_sense
Legendary
*
Offline Offline

Activity: 2310
Merit: 4313

🔐BitcoinMessage.Tools🔑


View Profile WWW
January 31, 2023, 06:31:23 AM
Merited by ABCbits (1)
 #3

I already have given you  a link to a correct formula in your previous thread:
What is the formula to calculate private keys if you already have all the R,S,Z(H) K Value? 
Where d= private_key.


d = (k * s - z) * r-1 mod n

Source: https://learnmeabitcoin.com/technical/ecdsa (Why do you need to generate a random point each time? (Mathematical Explanation)
Why not just use it instead of inventing your own?

Also, your resulting private key shouldn't be a floating point number, which is why it is better to use floor division (//) instead of real division ( / ) that always gives you floats (even when you divide intehers without remainder)

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
krashfire (OP)
Jr. Member
*
Offline Offline

Activity: 96
Merit: 6

Life aint interesting without any cuts and bruises


View Profile
January 31, 2023, 06:51:38 AM
 #4

It is invalid, because:

1. You have to calculate it modulo "n".
2. The correct formula is "s=(z+rd)/k", so your private key "d" is "(sk-z)/r".

Also, if 256-bit numbers are too big for you to start with, then compute everything on smaller numbers first: https://www.coindesk.com/markets/2014/10/19/the-math-behind-the-bitcoin-protocol/
thank you garlonicon. I got this answer from ChatGPT... Damn.

KRASH
krashfire (OP)
Jr. Member
*
Offline Offline

Activity: 96
Merit: 6

Life aint interesting without any cuts and bruises


View Profile
January 31, 2023, 06:52:21 AM
 #5

I already have given you  a link to a correct formula in your previous thread:
What is the formula to calculate private keys if you already have all the R,S,Z(H) K Value? 
Where d= private_key.


d = (k * s - z) * r-1 mod n

Source: https://learnmeabitcoin.com/technical/ecdsa (Why do you need to generate a random point each time? (Mathematical Explanation)
Why not just use it instead of inventing your own?

Also, your resulting private key shouldn't be a floating point number, which is why it is better to use floor division (//) instead of real division ( / ) that always gives you floats (even when you divide intehers without remainder)
I already have given you  a link to a correct formula in your previous thread:
What is the formula to calculate private keys if you already have all the R,S,Z(H) K Value? 
Where d= private_key.


d = (k * s - z) * r-1 mod n

Source: https://learnmeabitcoin.com/technical/ecdsa (Why do you need to generate a random point each time? (Mathematical Explanation)
Why not just use it instead of inventing your own?

Also, your resulting private key shouldn't be a floating point number, which is why it is better to use floor division (//) instead of real division ( / ) that always gives you floats (even when you divide intehers without remainder)
yeah yeah...I forgot about that ..thanks for reminding.

KRASH
krashfire (OP)
Jr. Member
*
Offline Offline

Activity: 96
Merit: 6

Life aint interesting without any cuts and bruises


View Profile
January 31, 2023, 07:15:42 AM
 #6

ChatGPT also gave me this formula to find K nonce Value

Code:
k= (z + r*s) % n

KRASH
garlonicon
Hero Member
*****
Offline Offline

Activity: 799
Merit: 1932


View Profile
January 31, 2023, 03:48:56 PM
Merited by hugeblack (1)
 #7

Quote
Code:
k= (z + r*s) % n
But there is no private key "d" here, so I am certain this formula is invalid. If it would be possible to calculate "k" from publicly known values r,s,z, then you could do that for every signature, and move any coins in this way.

Quote
ChatGPT also gave me this formula
ChatGPT is already banned in Stack Overflow, because of bad answers it gave for technical questions. Who knows, if there will be more such cases here, then maybe we will get "automatically generated post" as one of the reasons to report such posts. Because now, the quality of that bot is far from perfect, and even worse, typical answers seems to be correct, but are often misleading.

Hold your horses before deploying blockchain-related things. You don't want to deploy SHA-1 collision without deploying hardened SHA-1. Once you reveal some code, and make it Open Source, there is no "undo" button. Once you share some idea, there is no way to erase it from reader's memory.
witcher_sense
Legendary
*
Offline Offline

Activity: 2310
Merit: 4313

🔐BitcoinMessage.Tools🔑


View Profile WWW
January 31, 2023, 04:01:45 PM
 #8

Quote
Code:
k= (z + r*s) % n
But there is no private key "d" here, so I am certain this formula is invalid. If it would be possible to calculate "k" from publicly known values r,s,z, then you could do that for every signature, and move any coins in this way.

Just for reference, the correct formula is the following (we still need private key to obtain nonce value):

k = (z + d * r) * s-1 mod n


█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
krashfire (OP)
Jr. Member
*
Offline Offline

Activity: 96
Merit: 6

Life aint interesting without any cuts and bruises


View Profile
January 31, 2023, 07:31:58 PM
 #9

Quote
Code:
k= (z + r*s) % n
But there is no private key "d" here, so I am certain this formula is invalid. If it would be possible to calculate "k" from publicly known values r,s,z, then you could do that for every signature, and move any coins in this way.

Just for reference, the correct formula is the following (we still need private key to obtain nonce value):

k = (z + d * r) * s-1 mod n




Just to be sure, I again ask ChatGPT

Code:

The mathematical formula to calculate k nonce from r,s,z signatures is:

k = (z + r*s) / s mod n

where n is the order of the elliptic curve.

Yeah


This forum should ban CHATGPT as well.

KRASH
Critical_Thoughts
Newbie
*
Offline Offline

Activity: 6
Merit: 7


View Profile
February 01, 2023, 08:23:08 AM
 #10

OP you need to understand chatGPT is not a computational operated model, it just generates answers based on a limited database, we don't know the source of it's outputs, they could be wrong in many cases. chatGPT is an experimental project, don't expect much from it.
NotATether
Legendary
*
Offline Offline

Activity: 1582
Merit: 6679


bitcoincleanup.com / bitmixlist.org


View Profile WWW
February 02, 2023, 04:45:51 AM
 #11

Quote
Code:
k= (z + r*s) % n
But there is no private key "d" here, so I am certain this formula is invalid. If it would be possible to calculate "k" from publicly known values r,s,z, then you could do that for every signature, and move any coins in this way.

The divisor is also missing here, instead the s is being multiplied instead of divided.

Quote
ChatGPT is already banned in Stack Overflow, because of bad answers it gave for technical questions. Who knows, if there will be more such cases here, then maybe we will get "automatically generated post" as one of the reasons to report such posts. Because now, the quality of that bot is far from perfect, and even worse, typical answers seems to be correct, but are often misleading.

Alternatively you can feed the input of a post into ChatGPT and prompt it to explain why it's a bad bitcointalk post, and you will get an automated report message out of it.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
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!