<s>
In	O
cryptography	O
and	O
computer	B-General_Concept
science	I-General_Concept
,	O
a	O
hash	B-Algorithm
tree	B-Application
or	O
Merkle	B-Algorithm
tree	I-Algorithm
is	O
a	O
tree	B-Application
in	O
which	O
every	O
"	O
leaf	O
"	O
(	O
node	O
)	O
is	O
labelled	O
with	O
the	O
cryptographic	B-Algorithm
hash	I-Algorithm
of	O
a	O
data	O
block	O
,	O
and	O
every	O
node	O
that	O
is	O
not	O
a	O
leaf	O
(	O
called	O
a	O
branch	O
,	O
inner	B-Application
node	I-Application
,	O
or	O
inode	O
)	O
is	O
labelled	O
with	O
the	O
cryptographic	B-Algorithm
hash	I-Algorithm
of	O
the	O
labels	O
of	O
its	O
child	O
nodes	O
.	O
</s>
<s>
A	O
hash	B-Algorithm
tree	B-Application
allows	O
efficient	O
and	O
secure	O
verification	O
of	O
the	O
contents	O
of	O
a	O
large	O
data	B-General_Concept
structure	I-General_Concept
.	O
</s>
<s>
A	O
hash	B-Algorithm
tree	B-Application
is	O
a	O
generalization	O
of	O
a	O
hash	B-Algorithm
list	I-Algorithm
and	O
a	O
hash	B-Algorithm
chain	I-Algorithm
.	O
</s>
<s>
Demonstrating	O
that	O
a	O
leaf	O
node	O
is	O
a	O
part	O
of	O
a	O
given	O
binary	O
hash	B-Algorithm
tree	B-Application
requires	O
computing	O
a	O
number	O
of	O
hashes	B-Algorithm
proportional	O
to	O
the	O
logarithm	O
of	O
the	O
number	O
of	O
leaf	B-Application
nodes	I-Application
in	O
the	O
tree	B-Application
.	O
</s>
<s>
Conversely	O
,	O
in	O
a	O
hash	B-Algorithm
list	I-Algorithm
,	O
the	O
number	O
is	O
proportional	O
to	O
the	O
number	O
of	O
leaf	B-Application
nodes	I-Application
itself	O
.	O
</s>
<s>
A	O
Merkle	B-Algorithm
tree	I-Algorithm
is	O
therefore	O
an	O
efficient	O
example	O
of	O
a	O
cryptographic	O
commitment	O
scheme	O
,	O
in	O
which	O
the	O
root	O
of	O
the	O
tree	B-Application
is	O
seen	O
as	O
a	O
commitment	O
and	O
leaf	B-Application
nodes	I-Application
may	O
be	O
revealed	O
and	O
proven	O
to	O
be	O
part	O
of	O
the	O
original	O
commitment	O
.	O
</s>
<s>
The	O
concept	O
of	O
a	O
hash	B-Algorithm
tree	B-Application
is	O
named	O
after	O
Ralph	O
Merkle	O
,	O
who	O
patented	O
it	O
in	O
1979	O
.	O
</s>
<s>
Hash	B-Algorithm
trees	O
can	O
be	O
used	O
to	O
verify	O
any	O
kind	O
of	O
data	O
stored	O
,	O
handled	O
and	O
transferred	O
in	O
and	O
between	O
computers	O
.	O
</s>
<s>
They	O
can	O
help	O
ensure	O
that	O
data	O
blocks	B-Application
received	O
from	O
other	O
peers	O
in	O
a	O
peer-to-peer	O
network	O
are	O
received	O
undamaged	O
and	O
unaltered	O
,	O
and	O
even	O
to	O
check	O
that	O
the	O
other	O
peers	O
do	O
not	O
lie	O
and	O
send	O
fake	O
blocks	B-Application
.	O
</s>
<s>
Hash	B-Algorithm
trees	O
are	O
used	O
in	O
hash-based	O
cryptography	O
.	O
</s>
<s>
Hash	B-Algorithm
trees	O
are	O
also	O
used	O
in	O
the	O
InterPlanetary	B-Protocol
File	I-Protocol
System	I-Protocol
(	O
IPFS	B-Protocol
)	O
,	O
Btrfs	B-Operating_System
and	O
ZFS	B-Application
file	O
systems	O
(	O
to	O
counter	O
data	O
degradation	O
)	O
;	O
Dat	O
protocol	O
;	O
Apache	B-Application
Wave	I-Application
protocol	O
;	O
Git	B-Application
and	O
Mercurial	B-Protocol
distributed	O
revision	O
control	O
systems	O
;	O
the	O
Tahoe-LAFS	B-General_Concept
backup	O
system	O
;	O
Zeronet	B-Protocol
;	O
the	O
Bitcoin	B-Protocol
and	O
Ethereum	B-Application
peer-to-peer	O
networks	O
;	O
the	O
Certificate	B-Protocol
Transparency	I-Protocol
framework	O
;	O
the	O
Nix	B-Application
package	I-Application
manager	I-Application
and	O
descendants	O
like	O
GNU	B-Application
Guix	I-Application
;	O
and	O
a	O
number	O
of	O
NoSQL	B-General_Concept
systems	O
such	O
as	O
Apache	B-Application
Cassandra	I-Application
,	O
Riak	B-General_Concept
,	O
and	O
Dynamo	B-Application
.	O
</s>
<s>
Suggestions	O
have	O
been	O
made	O
to	O
use	O
hash	B-Algorithm
trees	O
in	O
trusted	O
computing	O
systems	O
.	O
</s>
<s>
The	O
initial	O
Bitcoin	B-Protocol
implementation	O
of	O
Merkle	B-Algorithm
trees	I-Algorithm
by	O
Satoshi	O
Nakamoto	O
applies	O
the	O
compression	O
step	O
of	O
the	O
hash	B-Algorithm
function	I-Algorithm
to	O
an	O
excessive	O
degree	O
,	O
which	O
is	O
mitigated	O
by	O
using	O
Fast	O
Merkle	B-Algorithm
Trees	I-Algorithm
.	O
</s>
<s>
A	O
hash	B-Algorithm
tree	B-Application
is	O
a	O
tree	B-Application
of	O
hashes	B-Algorithm
in	O
which	O
the	O
leaves	O
(	O
i.e.	O
,	O
leaf	B-Application
nodes	I-Application
,	O
sometimes	O
also	O
called	O
"	O
leafs	O
"	O
)	O
are	O
hashes	B-Algorithm
of	O
data	O
blocks	B-Application
in	O
,	O
for	O
instance	O
,	O
a	O
file	O
or	O
set	O
of	O
files	O
.	O
</s>
<s>
Nodes	O
farther	O
up	O
in	O
the	O
tree	B-Application
are	O
the	O
hashes	B-Algorithm
of	O
their	O
respective	O
children	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
the	O
above	O
picture	O
hash	B-Algorithm
0	O
is	O
the	O
result	O
of	O
hashing	O
the	O
concatenation	O
of	O
hash	B-Algorithm
0-0	O
and	O
hash	B-Algorithm
0-1	O
.	O
</s>
<s>
That	O
is	O
,	O
hash	B-Algorithm
0	O
=	O
hash( 	O
hash	B-Algorithm
0-0	O
+	O
hash	B-Algorithm
0-1	O
)	O
where	O
"	O
+	O
"	O
denotes	O
concatenation	O
.	O
</s>
<s>
Most	O
hash	B-Algorithm
tree	B-Application
implementations	O
are	O
binary	O
(	O
two	O
child	O
nodes	O
under	O
each	O
node	O
)	O
but	O
they	O
can	O
just	O
as	O
well	O
use	O
many	O
more	O
child	O
nodes	O
under	O
each	O
node	O
.	O
</s>
<s>
Usually	O
,	O
a	O
cryptographic	B-Algorithm
hash	I-Algorithm
function	I-Algorithm
such	O
as	O
SHA-2	B-Algorithm
is	O
used	O
for	O
the	O
hashing	O
.	O
</s>
<s>
If	O
the	O
hash	B-Algorithm
tree	B-Application
only	O
needs	O
to	O
protect	O
against	O
unintentional	O
damage	O
,	O
unsecured	O
checksums	B-Algorithm
such	O
as	O
CRCs	O
can	O
be	O
used	O
.	O
</s>
<s>
In	O
the	O
top	O
of	O
a	O
hash	B-Algorithm
tree	B-Application
there	O
is	O
a	O
top	O
hash	B-Algorithm
(	O
or	O
root	O
hash	B-Algorithm
or	O
master	O
hash	B-Algorithm
)	O
.	O
</s>
<s>
Before	O
downloading	O
a	O
file	O
on	O
a	O
P2P	O
network	O
,	O
in	O
most	O
cases	O
the	O
top	O
hash	B-Algorithm
is	O
acquired	O
from	O
a	O
trusted	O
source	O
,	O
for	O
instance	O
a	O
friend	O
or	O
a	O
web	O
site	O
that	O
is	O
known	O
to	O
have	O
good	O
recommendations	O
of	O
files	O
to	O
download	O
.	O
</s>
<s>
When	O
the	O
top	O
hash	B-Algorithm
is	O
available	O
,	O
the	O
hash	B-Algorithm
tree	B-Application
can	O
be	O
received	O
from	O
any	O
non-trusted	O
source	O
,	O
like	O
any	O
peer	O
in	O
the	O
P2P	O
network	O
.	O
</s>
<s>
Then	O
,	O
the	O
received	O
hash	B-Algorithm
tree	B-Application
is	O
checked	O
against	O
the	O
trusted	O
top	O
hash	B-Algorithm
,	O
and	O
if	O
the	O
hash	B-Algorithm
tree	B-Application
is	O
damaged	O
or	O
fake	O
,	O
another	O
hash	B-Algorithm
tree	B-Application
from	O
another	O
source	O
will	O
be	O
tried	O
until	O
the	O
program	O
finds	O
one	O
that	O
matches	O
the	O
top	O
hash	B-Algorithm
.	O
</s>
<s>
The	O
main	O
difference	O
from	O
a	O
hash	B-Algorithm
list	I-Algorithm
is	O
that	O
one	O
branch	O
of	O
the	O
hash	B-Algorithm
tree	B-Application
can	O
be	O
downloaded	O
at	O
a	O
time	O
and	O
the	O
integrity	O
of	O
each	O
branch	O
can	O
be	O
checked	O
immediately	O
,	O
even	O
though	O
the	O
whole	O
tree	B-Application
is	O
not	O
available	O
yet	O
.	O
</s>
<s>
For	O
example	O
,	O
in	O
the	O
picture	O
,	O
the	O
integrity	O
of	O
data	O
block	O
L2	O
can	O
be	O
verified	O
immediately	O
if	O
the	O
tree	B-Application
already	O
contains	O
hash	B-Algorithm
0-0	O
and	O
hash	B-Algorithm
1	O
by	O
hashing	O
the	O
data	O
block	O
and	O
iteratively	O
combining	O
the	O
result	O
with	O
hash	B-Algorithm
0-0	O
and	O
then	O
hash	B-Algorithm
1	O
and	O
finally	O
comparing	O
the	O
result	O
with	O
the	O
top	O
hash	B-Algorithm
.	O
</s>
<s>
Similarly	O
,	O
the	O
integrity	O
of	O
data	O
block	O
L3	O
can	O
be	O
verified	O
if	O
the	O
tree	B-Application
already	O
has	O
hash	B-Algorithm
1-1	O
and	O
hash	B-Algorithm
0	O
.	O
</s>
<s>
This	O
can	O
be	O
an	O
advantage	O
since	O
it	O
is	O
efficient	O
to	O
split	O
files	O
up	O
in	O
very	O
small	O
data	O
blocks	B-Application
so	O
that	O
only	O
small	O
blocks	B-Application
have	O
to	O
be	O
re-downloaded	O
if	O
they	O
get	O
damaged	O
.	O
</s>
<s>
If	O
the	O
hashed	O
file	O
is	O
big	O
,	O
such	O
a	O
hash	B-Algorithm
list	I-Algorithm
or	O
hash	B-Algorithm
chain	I-Algorithm
becomes	O
fairly	O
big	O
.	O
</s>
<s>
But	O
if	O
it	O
is	O
a	O
tree	B-Application
,	O
one	O
small	O
branch	O
can	O
be	O
downloaded	O
quickly	O
,	O
the	O
integrity	O
of	O
the	O
branch	O
can	O
be	O
checked	O
,	O
and	O
then	O
the	O
downloading	O
of	O
data	O
blocks	B-Application
can	O
start	O
.	O
</s>
<s>
The	O
Merkle	O
hash	B-Algorithm
root	O
does	O
not	O
indicate	O
the	O
tree	B-Application
depth	O
,	O
enabling	O
a	O
second-preimage	O
attack	O
in	O
which	O
an	O
attacker	O
creates	O
a	O
document	O
other	O
than	O
the	O
original	O
that	O
has	O
the	O
same	O
Merkle	O
hash	B-Algorithm
root	O
.	O
</s>
<s>
For	O
the	O
example	O
above	O
,	O
an	O
attacker	O
can	O
create	O
a	O
new	O
document	O
containing	O
two	O
data	O
blocks	B-Application
,	O
where	O
the	O
first	O
is	O
hash	B-Algorithm
0-0	O
+	O
hash	B-Algorithm
0-1	O
,	O
and	O
the	O
second	O
is	O
hash	B-Algorithm
1-0	O
+	O
hash	B-Algorithm
1-1	O
.	O
</s>
<s>
One	O
simple	O
fix	O
is	O
defined	O
in	O
Certificate	B-Protocol
Transparency	I-Protocol
:	O
when	O
computing	O
leaf	O
node	O
hashes	B-Algorithm
,	O
a	O
0x00	O
byte	B-Application
is	O
prepended	O
to	O
the	O
hash	B-Algorithm
data	O
,	O
while	O
0x01	O
is	O
prepended	O
when	O
computing	O
internal	O
node	O
hashes	B-Algorithm
.	O
</s>
<s>
Limiting	O
the	O
hash	B-Algorithm
tree	B-Application
size	O
is	O
a	O
prerequisite	O
of	O
some	O
formal	O
security	O
proofs	O
,	O
and	O
helps	O
in	O
making	O
some	O
proofs	O
tighter	O
.	O
</s>
<s>
Some	O
implementations	O
limit	O
the	O
tree	B-Application
depth	O
using	O
hash	B-Algorithm
tree	B-Application
depth	O
prefixes	O
before	O
hashes	B-Algorithm
,	O
so	O
any	O
extracted	O
hash	B-Algorithm
chain	I-Algorithm
is	O
defined	O
to	O
be	O
valid	O
only	O
if	O
the	O
prefix	O
decreases	O
at	O
each	O
step	O
and	O
is	O
still	O
positive	O
when	O
the	O
leaf	O
is	O
reached	O
.	O
</s>
<s>
The	O
Tiger	B-Algorithm
tree	B-Application
hash	B-Algorithm
is	O
a	O
widely	O
used	O
form	O
of	O
hash	B-Algorithm
tree	B-Application
.	O
</s>
<s>
It	O
uses	O
a	O
binary	O
hash	B-Algorithm
tree	B-Application
(	O
two	O
child	O
nodes	O
under	O
each	O
node	O
)	O
,	O
usually	O
has	O
a	O
data	O
block	O
size	O
of	O
1024	O
bytes	B-Application
and	O
uses	O
the	O
Tiger	B-Algorithm
hash	I-Algorithm
.	O
</s>
<s>
Tiger	B-Algorithm
tree	B-Application
hashes	B-Algorithm
are	O
used	O
in	O
Gnutella	B-Protocol
,	O
Gnutella2	O
,	O
and	O
Direct	O
Connect	O
P2P	O
file	O
sharing	O
protocols	O
and	O
in	O
file	O
sharing	O
applications	O
such	O
as	O
Phex	B-Language
,	O
BearShare	B-Protocol
,	O
LimeWire	B-Application
,	O
Shareaza	B-Application
,	O
DC++	B-Language
and	O
gtk-gnutella	B-Language
.	O
</s>
