Skip to content

Commit 52f68fe

Browse files
authored
Merge pull request bitcoin#1355 from jonasnick/fix-missing-int
BIP 340 & 341: use consistent definition of lift_x
2 parents 64aba76 + 3998dbb commit 52f68fe

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
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):

bip-0341.mediawiki

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def taproot_tweak_pubkey(pubkey, h):
182182
t = int_from_bytes(tagged_hash("TapTweak", pubkey + h))
183183
if t >= SECP256K1_ORDER:
184184
raise ValueError
185-
Q = point_add(lift_x(pubkey), point_mul(G, t))
185+
Q = point_add(lift_x(int(pubkey)), point_mul(G, t))
186186
return 0 if has_even_y(Q) else 1, bytes_from_int(x(Q))
187187

188188
def taproot_tweak_seckey(seckey0, h):

0 commit comments

Comments
 (0)