Skip to content

Commit 637fb24

Browse files
committed
Add warning about the merkle-tree algorithm duplicate txid flaw
Lots of people read the Bitcoin Core codebase to learn more about crypto; better to warn about flaws explicitly so they don't blindly copy the code for other uses and create broken systems.
1 parent 8e47689 commit 637fb24

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

bitcoin/core/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,20 @@ class CBlock(CBlockHeader):
424424

425425
@staticmethod
426426
def build_merkle_tree_from_txids(txids):
427-
"""Build a full merkle tree from txids
427+
"""Build a full CBlock merkle tree from txids
428428
429429
txids - iterable of txids
430430
431-
Returns a new merkle tree in deepest first order.
431+
Returns a new merkle tree in deepest first order. The last element is
432+
the merkle root.
433+
434+
WARNING! If you're reading this because you're learning about crypto
435+
and/or designing a new system that will use merkle trees, keep in mind
436+
that the following merkle tree algorithm has a serious flaw related to
437+
duplicate txids, resulting in a vulnerability. (CVE-2012-2459) Bitcoin
438+
has since worked around the flaw, but for new applications you should
439+
use something different; don't just copy-and-paste this code without
440+
understanding the problem first.
432441
"""
433442
merkle_tree = list(txids)
434443

0 commit comments

Comments
 (0)