Skip to content

Commit 3998dbb

Browse files
committed
BIP 340: fix function signature of lift_x in reference code
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.
1 parent 2119931 commit 3998dbb

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

bip-0340.mediawiki

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ Blind Schnorr signatures could for example be used in [https://github.com/Elemen
243243
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]].
244244
The reference implementation is for demonstration purposes only and not to be used in production environments.
245245

246+
== Changelog ==
247+
248+
To help implementors understand updates to this BIP, we keep a list of substantial changes.
249+
250+
* 2022-08: Fix function signature of lift_x in reference code
251+
246252
== Footnotes ==
247253

248254
<references />

bip-0340/reference.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ def bytes_from_point(P: Point) -> bytes:
6868
def xor_bytes(b0: bytes, b1: bytes) -> bytes:
6969
return bytes(x ^ y for (x, y) in zip(b0, b1))
7070

71-
def lift_x(b: bytes) -> Optional[Point]:
72-
x = int_from_bytes(b)
71+
def lift_x(x: int) -> Optional[Point]:
7372
if x >= p:
7473
return None
7574
y_sq = (pow(x, 3, p) + 7) % p
@@ -128,7 +127,7 @@ def schnorr_verify(msg: bytes, pubkey: bytes, sig: bytes) -> bool:
128127
raise ValueError('The public key must be a 32-byte array.')
129128
if len(sig) != 64:
130129
raise ValueError('The signature must be a 64-byte array.')
131-
P = lift_x(pubkey)
130+
P = lift_x(int_from_bytes(pubkey))
132131
r = int_from_bytes(sig[0:32])
133132
s = int_from_bytes(sig[32:64])
134133
if (P is None) or (r >= p) or (s >= n):

0 commit comments

Comments
 (0)