mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-27 16:05:39 +01:00
Merge bitcoin/bitcoin#26383: test: Add feature_taproot case involving invalid internal pubkey
5d413c8e79Add feature_taproot case involved invalid internal pubkey (Pieter Wuille) Pull request description: Add a test case to feature_taproot which involves an output that is (incorrectly) constructed, using an invalid internal public key and valid script tree. It is designed to detect cases where the script path spending validation logic does not detect this case, and instead treats the internal public key as the point at infinity. Equivalent unit test case added in https://github.com/bitcoin-core/qa-assets/pull/98. ACKs for top commit: instagibbs: ACK5d413c8e79aureleoules: reACK5d413c8e79Tree-SHA512: dfa014e383cd2743f3c9a996e1f2a2fceb9e244edf4b05dc0c110c4ba32a87684482222907805a4ca998aebcb42a197bb3e7967bfb5f0554fe9f1e5aa5463603
This commit is contained in:
@@ -12,7 +12,7 @@ import struct
|
||||
import unittest
|
||||
from typing import List, Dict
|
||||
|
||||
from .key import TaggedHash, tweak_add_pubkey
|
||||
from .key import TaggedHash, tweak_add_pubkey, compute_xonly_pubkey
|
||||
|
||||
from .messages import (
|
||||
CTransaction,
|
||||
@@ -872,7 +872,7 @@ TaprootInfo = namedtuple("TaprootInfo", "scriptPubKey,internal_pubkey,negflag,tw
|
||||
# - merklebranch: the merkle branch to use for this leaf (32*N bytes)
|
||||
TaprootLeafInfo = namedtuple("TaprootLeafInfo", "script,version,merklebranch,leaf_hash")
|
||||
|
||||
def taproot_construct(pubkey, scripts=None):
|
||||
def taproot_construct(pubkey, scripts=None, treat_internal_as_infinity=False):
|
||||
"""Construct a tree of Taproot spending conditions
|
||||
|
||||
pubkey: a 32-byte xonly pubkey for the internal pubkey (bytes)
|
||||
@@ -891,7 +891,10 @@ def taproot_construct(pubkey, scripts=None):
|
||||
|
||||
ret, h = taproot_tree_helper(scripts)
|
||||
tweak = TaggedHash("TapTweak", pubkey + h)
|
||||
tweaked, negated = tweak_add_pubkey(pubkey, tweak)
|
||||
if treat_internal_as_infinity:
|
||||
tweaked, negated = compute_xonly_pubkey(tweak)
|
||||
else:
|
||||
tweaked, negated = tweak_add_pubkey(pubkey, tweak)
|
||||
leaves = dict((name, TaprootLeafInfo(script, version, merklebranch, leaf)) for name, version, script, merklebranch, leaf in ret)
|
||||
return TaprootInfo(CScript([OP_1, tweaked]), pubkey, negated + 0, tweak, leaves, h, tweaked)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user