BIP 340 defines tagged_hash(tag, x) as
SHA-256(SHA-256(tag) ‖ SHA-256(tag) ‖ x).
The double-prepended tag hash gives domain separation —
a hash computed with tag "TapTweak" can never collide with
one computed with tag "BIP0340/challenge" or
"TapLeaf", even if the underlying x is identical.
Pre-hashing the tag (instead of prepending it raw) also aligns the
preimage to a 64-byte SHA-256 block boundary, so the first block is
cached across repeated calls with the same tag.
3a. tag_hash = SHA-256("TapTweak")
tag_hash = —
32 bytes. Constant for this tag — every TapTweak computation reuses it.
3b. preimage = tag_hash ‖ tag_hash ‖ data
preimage = —
—
3c. raw hash = SHA-256(preimage)
traw = —
256-bit output interpreted as a big-endian integer.
3d. reduce mod n (secp256k1 group order)
t = traw mod n = —
—