Skip to content

Instantly share code, notes, and snippets.

@delta1
Last active May 26, 2023 11:47
Show Gist options
  • Save delta1/88499753379c5269edb895ee42678ff3 to your computer and use it in GitHub Desktop.
Save delta1/88499753379c5269edb895ee42678ff3 to your computer and use it in GitHub Desktop.
tweaked pubkey for internal key from bitcoin/bitcoin#23371 has different negflag for TaggedHash("TapTweak/elements")
#!/usr/bin/env python3
from test_framework.key import TaggedHash, tweak_add_pubkey
from test_framework.script import OP_1, OP_TRUE, CScript, TaprootInfo, TaprootLeafInfo, taproot_tree_helper
pubkeys = [(1).to_bytes(32, 'big'), (2).to_bytes(32, 'big')]
pubkey = (1).to_bytes(32, 'big')
scripts = [(None, CScript([OP_TRUE]))]
for pubkey in pubkeys:
print(pubkey.hex())
ret, h = taproot_tree_helper(scripts)
tweak = TaggedHash("TapTweak", pubkey + h)
print(tweak.hex())
tweaked, negated = tweak_add_pubkey(pubkey, tweak)
leaves = dict((name, TaprootLeafInfo(script, version, merklebranch, leaf)) for name, version, script, merklebranch, leaf in ret)
info = TaprootInfo(CScript([OP_1, tweaked]), pubkey, negated + 0, tweak, leaves, h, tweaked)
print(info.negflag)
ret, h = taproot_tree_helper(scripts)
tweak = TaggedHash("TapTweak/elements", pubkey + h)
print(tweak.hex())
tweaked, negated = tweak_add_pubkey(pubkey, tweak)
leaves = dict((name, TaprootLeafInfo(script, version, merklebranch, leaf)) for name, version, script, merklebranch, leaf in ret)
info = TaprootInfo(CScript([OP_1, tweaked]), pubkey, negated + 0, tweak, leaves, h, tweaked)
print(info.negflag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment