0% found this document useful (0 votes)
13 views

Module-3 - Send

Uploaded by

YT modapk
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Module-3 - Send

Uploaded by

YT modapk
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Blockchain Technology

21MCA4405
Module 3
BITCOIN CONSENSUS
MODULE II- BITCOIN CONSENSUS

Bitcoin Consensus, Proof of Work (PoW)- Hashcash PoW , Bitcoin PoW, Attacks on PoW
,monopoly problem- Proof of Stake- Proof of Burn - Proof of Elapsed Time - Bitcoin Miner,
Mining Difficulty, Mining Pool-Permissioned model and use cases, Design issues for
Permissioned Blockchains, Execute contracts- Consensus models for permissioned
blockchain-Distributed consensus in closed environment.
Bitcoin Consensus
Bitcoin Consensus
Proof of Work(PoW) is the original consensus algorithm in a
blockchain network. The algorithm is used to confirm the transaction
and creates a new block to the chain. In this algorithm, minors (a group
of people) compete against each other to complete the transaction on the
network. The process of competing against each other is called mining.
As soon as miners successfully created a valid block, he gets rewarded.
The most famous application of Proof of Work(PoW) is Bitcoin.
In the below image, you can see that this block is composed of a block
number, data field, cryptographic hash associated with it and a nonce.
The nonce is responsible for making the block valid.
PoW
In the puzzle game, bitcoin software creates a challenge, and there is a
game begins. This game involves all miners competing against each
other to solve the challenges, and this challenge will take
approximately 10 minutes to be completed. Every single miner starts
trying to find the solution to that one Nonce that will satisfy the hash
for the block. At some specific point, one of those miners in the global
community with higher speed and great hardware specs will solve the
cryptography challenge and be the winner of the game. Now, the rest
of the community will start verifying that block which is mined by the
winner. If the nonce is correct, it will end up with the new block that
will be added to the blockchain. The concept of generating a block
provides a clear explanation of proof of work(PoW).
Hashcash PoW
• Hashcash is a proof-of-work (PoW) algorithm that was originally developed in
1997 by computer scientist Adam Back as a way to combat email spam. The
Hashcash PoW algorithm involves solving a cryptographic puzzle using a hash
function.
• The basic idea behind Hashcash is to require a computer to perform a certain
amount of computational work before being able to send an email or perform
other network activities. This computational work is designed to be difficult and
time-consuming, but easy to verify once it has been completed.
• In the context of Bitcoin mining, the Hashcash PoW algorithm is used to solve a
cryptographic puzzle that involves finding a nonce that, when combined with the
block data and hashed using the SHA-256 algorithm, produces a hash that meets
a specific target difficulty. This difficulty is adjusted periodically to ensure that the
rate of new blocks being added to the blockchain remains consistent.
• Miners compete to find a valid nonce by repeatedly hashing the block
data with different nonce values until they find one that produces a
hash that meets the target difficulty. The first miner to find a valid
nonce broadcasts the new block to the network, and other miners
can then verify the work by checking the hash of the block and the
nonce.
• The Hashcash PoW algorithm is widely used in cryptocurrency mining
as a way to ensure the security and integrity of the blockchain. It
requires miners to invest significant computational resources in order
to compete for block rewards, which helps to prevent malicious
actors from attempting to rewrite the blockchain or perform other
attacks.
Bitcoin PoW
• Proof of work (PoW) is a decentralized consensus mechanism that
requires network members to expend effort in solving an encrypted
hexadecimal number.
• Proof of work is also called mining, in reference to receiving a reward
for work done.
• Proof of work allows for secure peer-to-peer transaction processing
without needing a trusted third party.
• Proof of work at scale requires vast amounts of energy, which only
increases as more miners join the network.
Attacks on PoW
• 51% Attack
• Sybil Attack
• DDOS Attack
51% Attack
A 51% attack, also known as a majority attack, occurs when a single person or group of people
gains control of over 50% of a blockchain’s hashing power. That is usually achieved by renting
mining hash power from a third party.

Successful attackers gain the ability to block new transactions from being confirmed as well as
change the ordering of new transactions. It also allows the malicious agents to essentially rewrite
parts of the blockchain and reverse their own transactions, leading to an issue known as double
spending. This problem was traditionally an issue faced mostly by electronic payments where a
network was incapable of proving that two or more people didn’t spend the same digital asset.

The attacker could trigger the double-spending problem, they cannot reverse others’ transactions
on the network or prevent users from broadcasting their transactions to the network. Additionally,
a 51% attack is incapable of creating new assets, stealing assets from unrelated parties or
altering the functionality of block rewards.
Sybil Attack
• A Sybil Attack is an attempt to manipulate a P2P network by creating
multiple fake identities. To the observer, these different identities look like
regular users, but behind the scenes, a single entity controls all these fake
entities at once.
• This type of attack is important to consider especially when you think
about online voting. Another area where we are seeing Sybil attacks is in
social networks where fake accounts can influence the public discussion.
• Another possible use for Sybil attacks is to censor certain participants.
• A number of Sybil nodes can surround your node and prevent it from
connecting to other, honest nodes on the network. This way one could try
to prevent you from either sending or receiving information to the
network.
DDOS Attack
• A DDoS attack, which stands for “distributed denial-of-service” is a
malicious attempt to disrupt the normal traffic of a targeted server,
service or network by overwhelming the target or its surrounding
infrastructure with a flood of Internet traffic.
• Once a DDoS starts on one computer, it will spread to others in the
same network, leading to catastrophic failure.
• A DDOS attack is much harder to tackle because to do so you need to
differentiate between legitimate and malicious requests. This is a very
hard problem.
• The motivation to introduce transaction fees was to eliminate spam.
Monopoly problem
Monopoly problem
Proof of Work depends on the computing resources available to a
miner. If a miner can possess a huge amount of computational
resources, then there is a possibility that the miner can control the
entire network or gain control over the network. It may happen that a
minor can gradually generate a lot of blocks in the current blockchain. If
a huge number of blocks in the blockchain go from a particular miner,
then that particular miner can control the entire flow of transactions in
the blockchain. This particular problem is called the monopoly problem
in the bitcoin network.
Proof of Stake(PoS)
• The amount of bitcoin that the miner holds instructs which miner can
generate the next block. So if a miner holds one percent of the total
bitcoins, then the miner can mine one percent of PoS blocks.
• In PoS: Acquire sufficient stake to mine a new block, consumes no
external resource, but participate in transactions, and power-
efficient.
Proof of Burn (PoB)
• The miners need to prove that they have burned some coins. In this
context, burned means they have sent coins to a verifiable un-
spendable address so that no one can spend those coins.
• In PoB: Burn some wealth to mine a new block, consumes virtual or
digital resources, and power-efficient.
Proof of Elapsed Time (PoET)

• Each participant in the blockchain network waits a random amount of


time, and the first participant to finish becomes the leader for the
next block. Intel proposes it as a part of Hyperledger sawtooth – A
blockchain platform for building distributed ledger applications.
Comparisons of PoW vs. PoS
Proof of Work (PoW) Proof of Stake (PoS)

The probability of validating a new block is determined by


The probability of mining a block is determined by how
how large of a stake a person holds (how many coins they
much computational work is done by miner.
possess).

A reward is given to first miner to solve cryptographic The validator donot receive a block reward instead they
puzzle of each block. collect network fee as their reward.

To add each block to chain, miners must compete to solve There is no competition as block creator is .chosen by an
difficult puzzles using their computer process power algorithm based on user stake.

Hackers would need to have 51% of computation power Hackers would need to own 51% of all cryptocurrency on
to add malicious block. network, which is practically impossible.

Proof of work systems are less energy efficient and are Proof of Stake systems are much more cost and energy
less costly but more proven. efficient than POW systems but less proven.
Comparisons of PoW vs. PoB

• In PoW, the miners have to invest in Physical resources like


computational power, computational time, electricity bill, and money
to purchase computational hardware.
• In PoB, miners have to spend digital or logical resources such as coins.
The miner has to spend certain coins to participate in the mining
procedure to show that they have interest in the mining procedure. If
a miner (attacker) wants to attack this system, the attacker actually
has to lose a huge amount of coins.
Bitcoin context for PoS or PoB

The main idea is that once the PoW mechanism gets saturated, no
more bitcoins will be rewarded to the miners that are the way bitcoins
generate in the bitcoin network. There won’t be any motivation to do
mining. However, to run the entire ecosystem, the system may
Bitcoin Consensus
gradually adopt proof of stake or proof of burned-based mechanism.
Bitcoin Miner
The life of a Miner in Bitcoin Network

The first task is to validate the transactions and construct a new block.
Once they have constructed a new block, they employ their hash
power and vote on consensus to determine who will complete the
work first and then propose that block as a new block. Add that new
block to the existing bitcoin blockchain, and broadcast that updated
blockchain to the peers. So that way, the entire blockchain gets
propagated in the network.
Bitcoin Miner-Mining Bitcoin
• The first and foremost task is to join the network, listen for transactions,
and validate the proposed transactions from the network clients.
• Listen for the new blocks proposed by other miners, validate, and re-
broadcast to the peer nodes. This is the standard policy followed by the
bitcoin network nodes to avoid the Sybil attack.
• Collect the transactions for a predefined time, and construct a new block
that includes all the transactions not included in a block of the main bitcoin
blockchain received from the peer nodes.
• The miner task is to find a nonce to make the new block valid by utilizing
the predefined difficulty function. That means the proposed new block
must have a certain minimum number of zeros at the prefix. This is also
called “Proof of Work” for consensus that a miner had done some work
quicker than other miners in the bitcoin network.
• Once a miner can generate a valid block and quicker compared to other
miners. The miner will broadcast that new block to the peers, and
everybody in the peering system will accept that block if it is part of the
main chain.
• In the typical bitcoin network, multiple new valid blocks may be generated together
by the different miners, and these blocks may or may not have a list of the same
transactions.
• Flooding rule: If multiple valid blocks are received from the peer nodes to an
individual (a node or miner), the individual will accept the valid blocks but
rebroadcast the block received from more peers.
• The bitcoin blockchain always has the main chain and multiple orphans blocks. The
main chain is the longest blockchain in the network, and orphans blocks are blocks
from the fork chain that come out from the main chain but do not grow longer than
the main chain.
• Whenever a miner finds a new valid block and can successfully append it to
the main chain, the miner earns a certain reward. However, other mines
may be trying to generate a valid block during the same period, but already
one of the miners found the valid one. In that case, they will discard the
generation process and start collecting all the new transactions that are
not there in the new append block of the bitcoin blockchain.
In the context of blockchain, a fork is a technical phenomenon that occurs when a blockchain splits into two
separate branches. These two branches share their transaction history up until the point of the split. From
there on, they each go independently each in their own direction.

In blockchain terms, orphan blocks are blocks mined simultaneously as another block but not accepted by the
blockchain
Mining Difficulty
Mining Difficulty
• It is a measure of how difficult it is to find a hash below the giving target.
The mining procedure says that we are going to generate a 256-bit hash
value. And there is mining difficulty, and it is represented in this way. Out of
256-bit hash, at least the first 64 bit should be zeros. This says that you
have to generate a hash value wherein the final hash result, at least the
first 64 bits, should be zero, and after that, the remaining bits can be zeros
and ones.
• This is the difficulty of the mining procedure, and based on that, we
defined a metric called mining difficulty. These difficulty parameters
change for every 2016 block or every two weeks. The desire rate of
generation of a block is every 10 minutes. If the system tries to generate a
new block every 10 minutes, then 2 weeks are required to generate 2016
blocks.
Difficulty level readjustment mechanism
(Valid for every 2 weeks or 2016 blocks):
• The difficulty level readjustment works as follows. The system finds
out whether miners can generate 2016 blocks within 2 weeks or
not. If they are taking less time, that means the difficulty is too
simple for the miners. So the system increases the difficulty
parameters for the next round of 2016 blocks. On the other hand, if
the miners take more than 2 weeks to generate 2016 blocks. It means
that the current difficulty is too hard for the miners. So the system
reduces the difficulty parameters for the next round of 2016 blocks.
• This way, the bitcoin network dynamically changes the difficulty
levels. In general, the change in difficulty is in proportion to the
amount of time over or under two weeks the previous 2016 blocks
took to find.
Difficulty formula
The difficulty level readjustment happens after every two weeks or
2016 blocks, whichever comes first. The expectation is that within 2
weeks, 2016 blocks must be generated so that inter-block generation
time becomes equal to 10 minutes. The formula to generate or find the
current difficulty is as follows:
Mining Pool-Permissioned model and use
cases
Mining Pool-Permissioned model and use
cases

• A mining pool is a joint group of multiple miners who share the


processing power over a network to mine the new blocks and split
the reward proportionally to the amount of work they contributed.
• In a mining pool, hundreds or thousands of miners may be
participating in a pool, and they communicate through some special
protocols.
What is a Permissioned Blockchain?
• A permissioned blockchain is a distributed ledger that is not publicly
accessible. It can only be accessed by users with permissions. The users can
only perform specific actions granted to them by the ledger administrators
and are required to identify themselves through certificates or other digital
means.
• You might consider the addition of permissioned users as an extra
blockchain security system. Administrators maintain an access control layer
to allow certain actions to be performed only by certain identifiable
participants. Records are kept within the blockchain of who is involved in
the transactions. This makes permissioned blockchains different from
public blockchains.
• Permissioned blockchains have been used to manage supply chains, create
contracts, handle claims, verify payment between parties, and administer
user identity.
Mining Pool Methods-Basic Setup:
• B is the per block reward minus the pool fee. It means whenever a
miner participates in a block mining pool, there is a pool fee that
needs to be paid by the miner. Here, B is the effective reward
received by an individual miner for mining a block.
• p is the probability of finding a block in a shared attempt. (p = 1/D),
where D is the block difficulty. Whenever multiple miners try to do
that, and if D is block difficulty, then 1/D is the probability of finding a
block.
• The multiple mechanisms for the distribution of share are:
Pay Per Share (PPS), Proportional Share, Pay per Last N Share (PPLNS)
Pay Per Share (PPS)
In this scheme, there is an instant guaranteed payout to a miner.
Whenever a miner joins the mining pool, the miners are paid from the
pool’s existing balance, and the miner share is calculated as R = B * p.
Here, R is the amount of money given to every individual miner joining
the pool. However, the miners get almost equal payment in this
architecture, but the risk is at the pool operator. PPS scheme follows
instant and guaranteed payment to the participant who is participating
in this pool. It may always happen that the pool is not getting any
reward, but still, the pool operator needs to pay the individual miners.
Proportional Share

In this scheme, the miners earn the share until the pool finds a block at
the end of the mining round. It means every mining round, whenever
the pool is finding out a block. The total share will be divided by the
individual miners: R = B * n/N, where n is the amount of individual
work done, and N is all shared. The payments are made once a pool
finds out a block.
Pay per Last N Share (PPLNS)

This scheme is similar to the proportional sharing method, along with


the Miner’s reward is calculated based on N’s last shares, and the
Miners get more profit for a short round.
Design issues for Permissioned
Blockchains
Design issues for Permissioned
Blockchains
Issue 1 is a relaxed version of a common BC.
• Instead of having identical contents, one can allow each node to have slightly different contents in a
new block yet to be voted on.
• This is to allow each node to receive different messages from different sources due to asynchronous
messaging. However, as a part of the voting process, all working nodes must decide on the contents of
the new block.
• In this way, after voting, all the nodes will have identical content in the newly created block.

Issue 2 is important in a permissioned BC as failed nodes should not be involved in future voting until
they are fully recovered. The recovered node also needs to retrieve any missing data during the absent
period.
Issue 3 is important as compromised nodes should not be involved as a compromised
node can cause significant troubles for a BC. In fact, they should be excluded from the BC
operation completely as soon as they are identified as the damage done by compromised
nodes is far greater than the damage done by failed nodes.

Issue 4 is a new problem in a permissioned BC as each second numerous data may enter
the BC, and those valid data must be stored to maintain the trust of the BC. For example, a
lottery machine may send out ticket information to a permissioned BC. Due to message
delays, some messages did not get into every node, and they were not included in the
new block. As they are valid tickets, they should be stored in the next block. This scenario
is considered as false negative as a valid message was excluded due to various reasons.

Issue 5 is a new problem due to Issue 4 as data not included in the previous block can be
included in the next new block to be created, thus potentially an increasing number of
data can be postponed and continued to be considered for inclusion. But some of these
data may not be valid at all, and should be removed for good rather than to be re-
considered in future blocks. This scenario is considered as false positive as invalid
messages continued to be considered in block creation.
Execute contracts- Consensus models
for permissioned blockchain
What Is a Smart Contract?

• A smart contract is a self-executing program that automates the


actions required in an agreement or contract. Once completed, the
transactions are trackable and irreversible.
• Smart contracts permit trusted transactions and agreements to be
carried out among disparate, anonymous parties without the need for
a central authority, legal system, or external enforcement mechanism.
• While blockchain technology has come to be thought of primarily as
the foundation for Bitcoin, it has evolved far beyond underpinning a
virtual currency.
Execute contracts- Consensus models
for permissioned blockchain
Permissioned blockchains usually use pbft algorithms
( practical byzantine fault tolerance algorithm (PBFT) )

In this model, each node exists in an internal state, which means that it will
maintain an ongoing specific information or status. Each time a node
receives a message, they use the message with respect to their internal state
to perform a computation or operation. Consequently, this computation will
send messages to other nodes to ask if the transaction is valid. After
receiving verification from all of the other nodes, the first node will
broadcast that decision with all the other participants in the network. A
consensus decision is achieved based on the total confirmations submitted
by all the nodes.
Distributed consensus in closed
environment.
Distributed consensus in closed
environment.
Consider following messages communication between two persons:

· Mr. A: Hey Mr. B! Let’s have a drink.

· Mr. B: What about coffee?

· Mr. A: Cool. coffee it is.

Mr. A and Mr. B wanted to have a drink. Mr. B SUGGESTED having “coffee”. Mr. A AGREED to Mr. B’s
suggestions and both of them are having “coffee”.

They both agreed on a VALUE that is SUGGESTED by one of them and took actions based on that VALUE. This is
a consensus.

In simple words, a consensus is a general agreement on value.


So what is a consensus in a distributed system?

· There were only two parties to agree on what to drink in the above scenario.

· What if three or four more people joined them. They may give more suggestions and
more votes on what to drink.

· So, when multiple parties trying to agree on some value, it is a distributed consensus
problem. In such a case, coming to an agreement is not that easy.

· When the number of parties involving the agreement goes higher, the complexity of achieving
consensus is going higher too.
A distributed system is s set of nodes (generally computers) that are accomplishing a common task concurrently
by communicating with each other over a network. With that idea of a distributed system, it can be said that
nodes in a distributed system agreeing on some value is a distributed consensus.
Why distributed consensus?

· Nodes in distributed systems are trying to achieve some common goal (maybe processing a large
computation). Then they need some kind of coordination among them.

· They need to know the effect of their doings to the whole system. That’s where distributed systems
need a consensus protocol.

· In any distributed consensus protocol a node can say “Guys, I SUGGEST value v. Do you all agree?”.
Only after all of the other nodes AGREED on v, each node (including suggesting node) can carry on their
work keeping “v is decided” in their mind.

· Another node can also say “I prefer w.” and SUGGEST another value(w) before the system decides v.
Then the distributed system should choose either v or w. In such a case, achieving consensus is a bit
complicated process.

You might also like