Skip to content

Commit

Permalink
BIP 341: Fix taproot_tweak_pubkey
Browse files Browse the repository at this point in the history
`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`.
  • Loading branch information
jonasnick committed Oct 24, 2022
1 parent 6545b81 commit be34027
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion bip-0341.mediawiki
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ def taproot_tweak_pubkey(pubkey, h):
t = int_from_bytes(tagged_hash("TapTweak", pubkey + h))
if t >= SECP256K1_ORDER:
raise ValueError
Q = point_add(lift_x(int(pubkey)), point_mul(G, t))
P = lift_x(int_from_bytes(pubkey))
if P is None:
raise ValueError
Q = point_add(P, point_mul(G, t))
return 0 if has_even_y(Q) else 1, bytes_from_int(x(Q))

def taproot_tweak_seckey(seckey0, h):
Expand Down

0 comments on commit be34027

Please sign in to comment.