Definition
TapBranch is the internal-node hash function used to assemble a Taproot script tree from its leaves up to a single merkle root. Where each script becomes a leaf hashed with hashTapLeaf, every parent node is computed as hashTapBranch(a || b), combining two child hashes into one. The result, after repeated application, is the 32-byte merkle root that the Taproot tweak commits to.
Lexicographic ordering
A defining detail of BIP341 is that TapBranch sorts its two inputs before hashing: given children a and b, it hashes a || b if a < b lexicographically, otherwise b || a. This canonical ordering means a verifier reconstructing the root from a revealed leaf and its merkle path does not need to know whether each sibling sat on the left or the right. It removes a position bit per level and simplifies the control-block format.
Tagged hashing
Like all Taproot hashes, TapBranch is a tagged hash: SHA256(SHA256(tag) || SHA256(tag) || data) with the tag string "TapBranch". Domain separation by tag ensures a branch hash can never be confused with a leaf hash, a tweak hash, or a signature hash, closing off a class of cross-structure attacks.
TapBranch is the building block that turns a flat set of scripts into the tree summarised by the merkle root. See how a single branch chain is proven during spending in Taproot Merkle Path, and how the resulting root feeds the Taproot Tweak.
In Simple Terms
TapBranch is the internal-node hash function used to assemble a Taproot script tree from its leaves up to a single merkle root. Where each script…
