Skip to content

Commit

Permalink
BIP 340: fix function signature of lift_x in reference code
Browse files Browse the repository at this point in the history
bip-0340.mediawiki defines lift_x as taking an integer argument. This commit
changes the argument of lift_x in the reference code to be identical to the
specification. Previously it took a byte array.
  • Loading branch information
jonasnick committed Aug 23, 2022
1 parent 2119931 commit 3998dbb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 6 additions & 0 deletions bip-0340.mediawiki
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ Blind Schnorr signatures could for example be used in [https://github.com/Elemen
For development and testing purposes, we provide a [[bip-0340/test-vectors.csv|collection of test vectors in CSV format]] and a naive, highly inefficient, and non-constant time [[bip-0340/reference.py|pure Python 3.7 reference implementation of the signing and verification algorithm]].
The reference implementation is for demonstration purposes only and not to be used in production environments.

== Changelog ==

To help implementors understand updates to this BIP, we keep a list of substantial changes.

* 2022-08: Fix function signature of lift_x in reference code
== Footnotes ==

<references />
Expand Down
5 changes: 2 additions & 3 deletions bip-0340/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def bytes_from_point(P: Point) -> bytes:
def xor_bytes(b0: bytes, b1: bytes) -> bytes:
return bytes(x ^ y for (x, y) in zip(b0, b1))

def lift_x(b: bytes) -> Optional[Point]:
x = int_from_bytes(b)
def lift_x(x: int) -> Optional[Point]:
if x >= p:
return None
y_sq = (pow(x, 3, p) + 7) % p
Expand Down Expand Up @@ -128,7 +127,7 @@ def schnorr_verify(msg: bytes, pubkey: bytes, sig: bytes) -> bool:
raise ValueError('The public key must be a 32-byte array.')
if len(sig) != 64:
raise ValueError('The signature must be a 64-byte array.')
P = lift_x(pubkey)
P = lift_x(int_from_bytes(pubkey))
r = int_from_bytes(sig[0:32])
s = int_from_bytes(sig[32:64])
if (P is None) or (r >= p) or (s >= n):
Expand Down

0 comments on commit 3998dbb

Please sign in to comment.