From 50a6b91352d4db5a541c8e582c1652008011e170 Mon Sep 17 00:00:00 2001 From: notmike Date: Fri, 26 Jun 2026 20:00:28 -0600 Subject: [PATCH] bip360: simplify tapbranch_hash function Implements @conduitions improvement on tapbranch_hash() Co-authored-by: conduition --- bip-0360/ref-impl/python/p2mr.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bip-0360/ref-impl/python/p2mr.py b/bip-0360/ref-impl/python/p2mr.py index 3d3196e4..515ea0b6 100644 --- a/bip-0360/ref-impl/python/p2mr.py +++ b/bip-0360/ref-impl/python/p2mr.py @@ -87,9 +87,7 @@ def tapleaf_hash(script: str, tapleaf_ver: str = "c0") -> str: def tapbranch_hash(left: str, right: str) -> bytes: """Hash function for tree branches""" - if left < right: - return tagged_hash("TapBranch", h2b(left) + h2b(right)) - return tagged_hash("TapBranch", h2b(right) + h2b(left)) + return tagged_hash("TapBranch", b"".join(sorted((h2b(right) + h2b(left))))) def collect_leaf_hashes(tree: ScriptTree) -> List[str]: