Post
Topic
Board Development & Technical Discussion
Re: Verifying K Value in Sagemath
by
krashfire
on 08/02/2024, 04:24:59 UTC
Hello there

"R = E.lift_x(r)"
there are 2 possibilities in this line for point R
"R" or "-R"

If "public_key" is not a string but a "point" object(like G) with "E" element (Ellipric Curve)

"R= u2*public_key + u1*G"

it's the right thing to do.

Thank you.

So you are saying i should instead write it like this?

Code:


def verify(r, s, z, public_key, k):
    # Compute modular inverse of s
    w = modinv(s, n)
   
    # Compute u1 and u2
    u1 = z * w % n
    u2 = r * w % n
   
    # Compute R using the provided x-coordinate r
    R = E.lift_x(r)
   
    # Compute the candidate public key using the provided k value
    candidate_public_key = u1 * public_key + u2 * G
   
    # Check if the x-coordinate of the computed R matches that of the candidate public key
    if R[0] == candidate_public_key[0]:
        print("Signature matches")
        return True
    else:
        print("Invalid signature")
        return False