Blockstream half-a-puzzle - having trouble verifying signature

Blockstream half-a-puzzle - having trouble verifying signature

The https://blockstream.com/puzzles/half-of-a-puzzle/ link gives as the first example:

Address: 13yaSqGNDzt1mNW4vrKM9CvD46cTavNabF
Message: "There is nothing too shocking about this signature"
PublicKey: 02000000000005689111130e588a12ecda87b2dc5585c6c6ba
 66a412fa0cce65bc
Signature: ffffffff077b7209dc866fbfa0d2bf67a0c696afffe57a822e
 2ba90059a2cc7abb998becb4e427650e282522bf9576524665
 301b807c0e3194cf1e6c795a0cf7

So:

from fastecdsa.ecdsa import Point
from fastecdsa.curve import secp256k1
G = secp256k1.G
N = secp256k1.q

def verify(z, sig, pk):
    temp = pow(s, N-2, N)
    u = z * temp % N
    v = r * temp % N
    return (u*G + v*pk).x == r

from bitcoin.signmessage import BitcoinMessage
message = BitcoinMessage("There is nothing too shocking about this signature")
m = z = message.GetHash().hex() # 0xf5c93ce41555a349f6114e99fd60060bf01e0ac952ff6bbb564713ea326e47ed

r = 0xffffffff077b7209dc866fbfa0d2bf67a0c696afffe57a822e2ba90059a2cc7a
s = 0xbb998becb4e427650e282522bf9576524665301b807c0e3194cf1e6c795a0cf7
sig = (r,s)

px = 0x000000000005689111130e588a12ecda87b2dc5585c6c6ba66a412fa0cce65bc 
py = 0x9153b93a0c3b37a18b483b45f36c8a9c1c7deb468202eff9423318bfb9660f12
point = Point(px, py, curve=secp256k1)

print(verify(z, sig, point)) # evaluates to False

Meaning I have the signature (r,s) incorrect or I am creating z incorrectly. Pointers, please.

What else have I tried?

def VerifyMessage(address, message, sig):
    """ https://github.com/petertodd/python-bitcoinlib/blob/master/bitcoin/signmessage.py """
    # sig =  base64.b64decode(sig) # <- what format is the signature in? 
    hash = message.GetHash()
    pubkey = CPubKey.recover_compact(hash, sig)
    return str(P2PKHBitcoinAddress.from_pubkey(pubkey)) == str(address)

Trying to fit sig into various encoding patterns, but just can't find the right pattern that will fit with this code. It is looking for 65, not 64 bytes. After adding every possible character (16 0-f) in two different places = C(130,2), I still had no luck.

https://ift.tt/2ztV53h

Comments

Popular posts from this blog

Bitcoin Core errors with database block

Bitfinex & Market Synergy To Offer Institutional Calibre Cryptocurrency Connectivity