Skip to content

Commit b305d56

Browse files
committed
[BIP-119] Explain Hash Function Choices
1 parent afc605f commit b305d56

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

bip-0119.mediawiki

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,34 @@ Furthermore, if OP_SHA256STREAM is added in the future, it may be possible to wr
394394
allows adding a single output to a list of outputs without incurring O(n) overhead by committing to
395395
a hash midstate in the script.
396396

397+
=====Using SHA256=====
398+
399+
SHA256 is a 32 byte hash which meets Bitcoin's security standards and is
400+
available already inside of Bitcoin Script for programmatic creation of template
401+
programs.
402+
403+
RIPEMD160, a 20 byte hash, might also be a viable hash in some contexts and has some benefits. For fee efficiency,
404+
RIPEMD160 saves 12 bytes. However, RIPEMD160 was not chosen for BIP-119 because it introduces
405+
risks around the verification of programs created by third parties to be subject to a
406+
[birthday-attack https://bitcoin.stackexchange.com/questions/54841/birthday-attack-on-p2sh] on
407+
transaction preimages.
408+
409+
=====Using Non-Tagged Hashes=====
410+
411+
The Taproot/Schnorr BIPs use Tagged Hashes
412+
(`SHA256(SHA256(tag)||SHA256(tag)||msg)`) to prevent taproot leafs, branches,
413+
tweaks, and signatures from overlapping in a way that might introduce a security
414+
[vulnerability https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2018-June/016091.html].
415+
416+
OP_CHECKTEMPLATEVERIFY is not subject to this sort of vulnerability as the
417+
hashes are effectively tagged externally, that is, by OP_CHECKTEMPLATEVERIFY
418+
itself and therefore cannot be confused for another hash.
419+
420+
It would be a conservative design decisison to make it a tagged hash even if
421+
there was no obvious benefit and no cost. However, in the future, if OP_CAT were
422+
to be introduced to Bitcoin, it would make programs which dynamically build
423+
OP_CHECKTEMPLATEVERIFY hashes less space-efficient. Therefore, bare untagged hashes
424+
are used in BIP-119.
397425

398426
=====The Ordering of Fields=====
399427

0 commit comments

Comments
 (0)