Hash & Digital Signature
Hash & Digital Signature
Creating Blocks:
In a blockchain, transactions are grouped into blocks, which are then
added to the blockchain. Each block contains a list of transactions and
a unique code called a “hash” or “digest,” which is produced using a
hash function. The hash of a block is based on the contents of the
block, and it serves as a unique identifier for that block. When a new
block is added to the blockchain, the previous block’s hash is included
in the new block, creating a chain of blocks secured using hashes.
Hash Function in Blockchain Technology
Verifying Transactions:
Hash functions are also used to verify the authenticity of transactions on
the blockchain. When a transaction is made on the blockchain, it is
broadcast to the network, where its consensus algorithm validates it. As
part of this process, the transaction’s hash is calculated and compared to
the hash stored in the block. The transaction is considered valid and
added to the blockchain if the hashes match. If the hashes do not match,
the transaction is rejected.
Hash Function in Blockchain Technology
Providing Security:
Hash functions are an essential part of the security of a blockchain. The
output of a hash function (the “hash” or “digest”) is a fixed-size value
that is produced from an input of any size. Finding two different inputs
that produce the same output (a collision) is challenging. This makes it
difficult for someone to alter the data stored in a block without being
detected, as any changes to the data would result in a different hash
being produced.
Digital Signatures
Digital Signatures Digital signatures are an essential part of blockchain
technology, as they ensure the authenticity and integrity of transactions on the
blockchain. A digital signature is a type of electronic signature used to
authenticate the identity of the sender of a message or document and to ensure
that the original content of the message or document has not been altered.
• Ensuring Authenticity: In blockchain technology, digital signatures are
used to verify the authenticity of transactions. When a user wants to make a
transaction on the blockchain, they must sign it using their private key. The
private key is a unique piece of information used to create the digital
signature and is known only to the user who owns it. The digital signature is
then attached to the transaction and broadcast to the network.
Digital Signatures
• Providing Non-Repudation: Digital signatures also provide non-
repudiation, meaning that the transaction’s sender cannot deny having
made the transaction. Once a transaction is signed with a digital
signature, it is irreversible, and the sender cannot deny having made
the transaction. This helps to ensure the integrity of the data stored on
the blockchain, as it is not possible for someone to alter or delete a
transaction once it has been made.
Digital Signatures
• Ensuring Data Integrity: Digital signatures also help to ensure the
integrity of the data stored on the blockchain. When a transaction is
signed with a digital signature, it is cryptographically secure, which
means altering the transaction without being detected is complicated.
This helps ensure that the data stored on the blockchain is accurate and
reliable and helps prevent fraud and tampering.
Consensus mechanism
• Generally, consensus means that the majority of a group has agreed in favour
of a decision. When it comes to blockchain, reaching a consensus is important.
• In the blockchain, a consensus mechanism is a system that validates a
transaction and marks it as authentic. This mechanism lists all valid
transactions of a coin in a blockchain to build trust in the coin among traders.
Several currencies, such as Bitcoin, Ethereum etc., use this system for security
purposes.
• A consensus algorithm is a procedure through which all the peers of the
Blockchain network reach a common agreement about the present state of the
distributed ledger. In this way, consensus algorithms achieve reliability in the
Blockchain network and establish trust between unknown peers in a
distributed computing environment.
Proof-of-Work
• The algorithm is used to verify the transaction and create a new block
in the blockchain. The idea for Proof of Work(PoW) was first
published in 1993 by Cynthia Dwork and Moni Naor and was later
applied by Satoshi Nakamoto in the Bitcoin paper in 2008. The term
“proof of work” was first used by Markus Jakobsson and Ari
Juels in a publication in 1999.
• Cryptocurrencies like Litecoin, and Bitcoin are currently using PoW.
Ethereum was using PoW mechanism, but now shifted to Proof of
Stake(PoS).
How does PoW Work?
• The PoW consensus algorithm involves verifying a transaction
through the mining process.
• Mining:
• The Proof of Work consensus algorithm involves solving a
computationally challenging puzzle in order to create new blocks in
the Bitcoin blockchain. The process is known as ‘mining’, and the
nodes in the network that engages in mining are known as ‘miners’.
How does PoW Work?
• Energy and Time consumption in Mining:
• The process of verifying the transactions in the block to be added,
organizing these transactions in chronological order in the block, and
announcing the newly mined block to the entire network does not take
much energy and time.
• The energy-consuming part is solving the ‘hard mathematical problem’
to link the new block to the last block in the valid blockchain.
• When a miner finally finds the right solution, the node broadcasts it to
the whole network at the same time, receiving a cryptocurrency prize
(the reward) provided by the PoW protocol.
Bitcoin’s PoW System?
• Bitcoin uses the Hashcash Proof of Work system as the mining basis. The ‘hard
mathematical problem’ can be written in an abstract way like below :
• Given data A, find a number x such as that the hash of x appended to A results
is a number less than B.
• The miners bundle up a group of transactions into a block and try to mine. To
mine it, a hard mathematical problem has to be solved.
• This problem is called the proof of work problem which has to be solved to
show that the miner has done some work in finding out the solution to the
problem and hence the mined block must be valid.
• The answer to the problem needs to be a lower number than the hash of the
block for it to be accepted, known as the ‘target hash’.
How does PoW Work?
• Common cryptographic protocols used in PoW:
The most widely used proof-of-work consensus is based on SHA-256
and was introduced as a part of Bitcoin. Others include Scrypt, SHA-3,
scrypt-jane, scrypt-n, etc.
Proof of Stake
• Proof of Stake (PoS) is a type of algorithm which aims to achieve
distributed consensus in a Blockchain.
• A stake is value/money we bet on a certain outcome. The process is
called staking.
• As understandable from the name, nodes on a network stake an amount
of cryptocurrency to become candidates to validate the new block and
earn the fee from it. Then, an algorithm chooses from the pool of
candidates the node which will validate the new block. This selection
algorithm combines the quantity of stake (amount of cryptocurrency) with
other factors (like coin-age based selection, randomization process) to
make the selection fair to everyone on the network.
Proof-of-Work
• Coin-age based selection: The algorithm tracks the time every
validator candidate node stays a validator. The older the node
becomes, the higher the chances of it becoming the new validator.
• Random Block selection: The validator is chosen with a combination
of ‘lowest hash value’ and ‘highest stake’. The node having the best
weighted-combination of these becomes the new validator.
A typical PoS based mechanism workflow:
1.Nodes make transactions. The PoS algorithm puts all these transactions in a pool.
2.All the nodes contending to become validator for the next block raise a stake. This stake is
combined with other factors like ‘coin-age’ or ‘randomized block selection’ to select the
validator.
3.The validator verifies all the transactions and publishes the block. His stake still remains
locked and the forging reward is also not granted yet. This is so that the nodes on the
network can ‘OK’ the new block.
4.If the block is ‘OK’-ed, the validator gets the stake back and the reward too. If the algorithm
is using a coin-age based mechanism to select validators, the validator for the current block’s
has its coin-age reset to 0. This puts him in a low-priority for the next validator election.
5.If the block is not verified by other nodes on the network, the validator loses its stake and is
marked as ‘bad’ by the algorithm. The process again starts from step 1 to forge the new
block.
Advantages of PoS:
• Energy-efficient: As all the nodes are not competing against each other to
attach a new block to the blockchain, energy is saved. Also, no problem has to
be solved( as in case of Proof-of-Work system) thus saving the energy.
• Decentralization: In blockchains like Bitcoin(Proof of Work system to
achieve distributed consensus), an extra incentive of exponential rewards are
in place to join a mining pool leading to a more centralized nature of
blockchain. In the case of a Proof-of-Stake based system(like Peercoin),
rewards are proportional(linear) to the amount of stake. So, it provides
absolutely no extra edge to join a mining pool; thus promoting
decentralization.
• Security: A person attempting to attack a network will have to own 51% of
the stakes(pretty expensive). This leads to a secure network.
Byzantine General’s Problem
• In 1982, The Byzantine General’s Problem was invented by Leslie Lamport, Robert
Shostak, and Marshall Pease. Byzantine Generals Problem is an impossibility result
which means that the solution to this problem has not been found yet as well as
helps us to understand the importance of blockchain. It is basically a game theory
problem that provides a description of the extent to which decentralized parties
experience difficulties in reaching consensus without any trusted central parties.
• The Byzantine army is divided into many battalions in this classic problem called
the Byzantine General’s problem, with each division led by a general.
• The generals connect via messenger in order to agree to a joint plan of action in
which all battalions coordinate and attack from all sides in order to achieve
success.
• It is probable that traitors will try to sabotage their plan by intercepting or changing
the messages.
• As a result, the purpose of this challenge is for all of the faithful commanders to
reach an agreement without the imposters tampering with their plans.
Byzantine General’s Problem
Practical Byzantine Fault Tolerance
• Practical Byzantine fault tolerances was formulated by Castro &
Liskov (2002) [14].
• The algorithm is designed to work in asynchronous systems and to
provide liveness and safety.
• Liveness is reflected in the fact that some consensus will certainly be
reached.
• Safety refers to the ability to reach a valid consensus in a situation
where at most (n-1)/3 nodes act maliciously, with n being the total
number of nodes participating in the decision-making. If we denote the
faulty nodes with f, then the total number of nodes must be n = 3f +1
Practical Byzantine Fault Tolerance
• To prevent misrepresentation and confusion, each node signs messages with its own
secret key. Also, each message has an authentication code, and when sent, it is
compressed using the hash function. Each node communicates with all other nodes
in the system. Nodes can identify each other based on the signature and check if the
message was changed during transmission.
• Before the consensus-building process begins, the nodes are divided hierarchically,
with one chosen as the leader and the others as the backup. The role of the nodes
changes before each new round of decision-making on a round robin basis. One
round of consensus-building consists of four phases.
• In the first phase, the client sends a message to the leader wanting to change the state
of the system.
• In the second phase, the leader forwards the message to the backup nodes. Backup
nodes consider the content of the message and send a response in the third phase.
• In the last phase, the client collects f +1 identical responses from the backup. The
selected response represents the attitude of the entire system towards the message
sent by the client.
Practical Byzantine Fault Tolerance
• The key advantage of pBFT in relation to all permissionless
blockchains protocols is lower computational complexity, and, thus,
lower electricity consumption. Also, the throughput is higher than with
the mentioned systems. However, pBFT is intended for systems with a
small number of participants.
• Increasing the number of nodes exponentially increases the volume of
communication, so application in permissionless blockchains would
lead to congestion. Of the known blockchain platforms, Hyperledger
Fabric and Zilliqa use pBFT.