Merkle Tree
Merkle Tree
• Hash functions are used to create fixed-length digests of arbitrarily long input strings. Hash functions
are keyless, and they provide a data integrity service. They are usually built using iterated and
dedicated hash function construction techniques.
• Various families of hash functions are available, such as MD, SHA1, SHA-2, SHA-3, RIPEMD, and
Whirlpool. Hash functions are commonly used for digital signatures and message authentication codes,
such as HMACs.
• Hash functions are also typically used to provide data integrity services. These can be used both as one-
way functions and to construct other cryptographic primitives, such as MACs and digital signatures.
Some applications use hash functions as a means for generating PRNGs. There are
• two practical and three security properties of hash functions that must be met depending on the level of
integrity required.
Hash functions 2
• A hash function H accepts a variable-length block of data M as input and produces a fixed-size
hash value
• h = H(M)
(b) two data objects that map to the same hash result (the collision-free property)
Hash Function Uses
• The generation of addresses in blockchains. For example, in Ethereum, blockchain accounts are
represented as addresses. These addresses are obtained by hashing the public key with the Keccak-256
hash algorithm and then using the last 20 bytes of this hashed value.
• The creation of Merkle trees to guarantee the integrity of transaction structure in the blockchain.
Specifically, this structure is used to quickly verify whether a transaction is included in a block or not.
Merkle trees
8
9
• A Merkle tree is a binary tree in which the inputs are first placed at the leaves (nodes with no
children), and then the values of pairs of child nodes are hashed together to produce a value for the
parent node (internal node), until a single hash value known as a Merkle root is achieved.
• This structure helps to quickly verify the integrity of the entire tree (entire dataset), but just by
verifying the Merkle root on top of the Merkle tree, because if any change occurs in any of the
hashes in the tree, the Merkle root will also change.
• This is the reason why the integrity of the system can be verified quickly by just looking at the
Merkle root.
10
• Another advantage of Merkle trees is that there is no requirement of storing large amounts of data,
only the hashes of the data, which are fixed-length digests of the large dataset.
• Due to this property, the storage and management of Merkle trees is easy and efficient as it takes a
very small amount of space for storage.
• Also, due to the fact that the tree is storage efficient, the relevant proofs for integrity are also
smaller in size and quick to transmit over the network, thus making them bandwidth efficient over
the network.
11
Patricia trees
• A trie, or a digital tree, is an ordered tree data structure used to store a dataset.
• The Practical Algorithm to Retrieve Information Coded in Alphanumeric (Patricia) tree, also
known as a Radix tree, is a compact representation of a trie in which a node that is the only child
of a parent is merged with its parent.
• A Merkle-Patricia tree, based on the definitions of Patricia and Merkle, is a tree that has a root
node that contains the hash value of the entire data structure.
• Internally, a hash function is used to calculate an index into an array of buckets from which the
required value can be found.
• Buckets have records stored in them using a hash key and are organized into a particular order.
• Distributed Hash Table (DHT) as a data structure where data is spread across various nodes, and
nodes are equivalent to buckets in a peer-to-peer network.
• data is passed through a hash function, which then generates a compact key. This key is then
linked with the data (values) on the peer-to-peer network.
• When users on the network request the data (via the filename), the filename can be hashed again
to produce the same key, and any node on the network can then be requested to find the
corresponding data.
13
14
SHA-3 Algorithm
• The SHA or SHA-3 (Secure Hash Algorithm 3) is known to be the latest member of
the SHA family of the secure hash algorithm stands it is published by the NIST on
the year 2015.
• the SHA-3 is different when we look at the internal structure of the SHA-3 because
the MD-5 structure is different from the SHA-1 and SHA-2.
• the SHA-3 is designed in order to provide a “random mapping” from a particular
string of binary data to a “message digest” that is fixed in size, the SHA-3 also
helps to achieve more security properties.
Difference Between SHA-256 and SHA-3
Block size 512 bits Variable, with the most common being the 1600 bits.
Performance Generally faster due to the simpler structure. Generally slower due to its more complex construction.
Padding scheme Uses the Merkle Damgard construction. Uses the sponge construction.
15
16
Keccak-256
• Keccak-256, a cryptographic function, is part of Solidity (SHA-3 Family).
Give a string as input, such as “Namaste Duniya,” then send it through a hash
function using keccak256.
This would lead to:
Namaste Duniya -> keccak-256(hashing function) ->
8a0fe4fd16bb35fbecde2e774008fb7f92a8568a680f3fa93d0948bcfbf68dc3
The string “Namaste Duniya”, is not the same as “namaste duniya”. If we hash
“namaste duniya”, we will get a totally different result.
namaste duniya -> keccak-256(hashing function) ->
544ff8f09d34fdfbfa5a8dcb9d7d57deb6c862026cb8b655cfd7bf9c192e4d21
• Small-sized cryptographic signature (by signing the hash instead of a larger input).