Skip to content

Commit be34027

Browse files
committed
BIP 341: Fix taproot_tweak_pubkey
`lift_x` returns `None` if the input integer is not an X coordinate on the curve to indicate failure. `point_add`, on the other hand, interprets `None` as the point at infinity. Therefore, without this commit, if the internal `pubkey` is not a valid X coordinate, the function will not fail, which contradicts the specification in the "Script validation rules section". Instead, it sets `Q` to `t*G`.
1 parent 6545b81 commit be34027

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

bip-0341.mediawiki

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ 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(int(pubkey)), point_mul(G, t))
185+
P = lift_x(int_from_bytes(pubkey))
186+
if P is None:
187+
raise ValueError
188+
Q = point_add(P, point_mul(G, t))
186189
return 0 if has_even_y(Q) else 1, bytes_from_int(x(Q))
187190

188191
def taproot_tweak_seckey(seckey0, h):

0 commit comments

Comments
 (0)