0% found this document useful (0 votes)
39 views42 pages

Dbatu University Blockchain Technology Notes BCT 2nd Unit

This is part two second unit for dbatu university blockchain subject which is called bct
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views42 pages

Dbatu University Blockchain Technology Notes BCT 2nd Unit

This is part two second unit for dbatu university blockchain subject which is called bct
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

Bitcoin and Blockchain

Double-Spending
• Double spending is when someone spends the same cryptocurrency twice.
• Double spending means the expenditure of the same digital currency twice or more to avail
the multiple services. It is a technical flaw that allows users to duplicate money.
• Since digital currencies are nothing but files, a malicious user can create multiple copies of the
same currency file and can use it in multiple places.
• This issue can also occur if there is an alteration in the network or copies of the currency are
only used and not the original one.
• There are also double spends that allow hackers to reverse transactions so that transaction
happens two times.
• By doing this, the user loses money two times one for the fake block created by the hacker and
for the original block as well.
• The hacker gets incentives as well for the fake blocks that have been mined and confirmed.
•Finney Attack: Finney Attack is a type of Double spending Attack. In this, a merchant
accepts an unauthorized transaction. The original block is eclipsed by the hacker using
an eclipse attack. The transaction is performed on an unauthorized one. After that, the
real block shows up and again the transaction is done automatically for the real block.
Thus the merchant loses money two times.
•Race attack: is an attack in which there is a ‘race’ between two transactions. The
attacker sends the same money using different machines to two different merchants.
The merchants send their goods but transactions get invalid.
•51% Attack: This type of attack is prevalent in small blockchains. Hackers usually
take over 51% of the mining power of blockchain and therefore can do anything of
their own will.
Bitcoin Script
 Bitcoin uses a scripting system for transactions. Forth-like, Script is simple,
stack-based, and processed from left to right. It is intentionally not Turing-
complete, with no loops.
Script is what’s known as a stack-based language. All this means is that, when
we read a set of instructions, we place them in what can be thought of as a vertical
column. The list A, B, C, for example, would result in a stack with A at the
bottom, and C at the top. When the instructions tell us to do something, we
operate on one or more elements beginning at the top of the stack.
Elements A, B, and C being added and “popped” from the stack.
 We can distinguish between the data (things like signatures, hashes, and public
keys) and the instructions (or opcodes). The instructions remove data and do
something with it. Here’s a very simple example of what a script could look like:
<xyz> <md5 hasher> <d16fb36f0911f878998c136191af705e> <check if equal>
 In red, we have data, and in blue, we have the opcodes. We read from left to
right, so we first put the string <xyz> onto the stack. Next up is the <md5
hasher> opcode. This one doesn’t exist in Bitcoin, but let’s say that it removes the
top element of the stack (<xyz>) and hashes it using the MD5 algorithm. Then, the
output gets added back onto the stack. The output here happens to be
d16fb36f0911f878998c136191af705e.
<check if equal> pops two elements off the top and checks if they’re equal. If
they are, it adds <1> to the stack. If not, it adds <0>.
Pay-to-Pubkey (P2PK)
 The structure was heavily used in the early days of Bitcoin, but nowadays, Pay-to-
Pubkey-Hash (P2PKH) has largely replaced it.
 The locking script for a P2PK transaction follows the format of <public
key> OP_CHECKSIG. Simple enough. You might have guessed
that OP_CHECKSIG checks for a signature against the provided public key. As
such, our scriptSig is going to be a simple <signature>. Remember, the scriptSig is
the key to the lock.
Pay-to-Pubkey-Hash (P2PKH)
The scriptPubKey in P2PKH is the following:
OP_DUP OP_HASH160 <public key hash> OP_EQUALVERIFY OP_CHECKSIG
OP_DUP
OP_DUP pops the first element, and duplicates it. Then, it adds both back to the stack. Typically, this is done so
that we can do an operation on the duplicate without affecting the original.

OP_HASH160
This pops the first element and hashes it twice. The first round will hash with the SHA-256 algorithm. The SHA-
256 output is then hashed with the RIPEMD-160 algorithm. The resulting output is added back onto the stack.

OP_EQUALVERIFY
OP_EQUALVERIFY combines two other operators – OP_EQUAL and OP_VERIFY. OP_EQUAL pops two
elements and checks if they’re identical. If they are, it adds a 1 to the stack. If not, it adds a 0. OP_VERIFY pops
the top element and checks if it’s True (i.e., non-zero). If it isn’t, the transaction fails. Combined,
OP_EQUALVERIFY causes the transaction to fail if the top two elements don’t match.
This time, the scriptSig looks like this:
<signature> <public key>
You need to provide a signature and the corresponding public key to unlock P2PKH outputs.
Bitcoin P2P
 In peer-to-peer network all the nodes are equal and each node plays
role of client and server with other nodes.

 In this network, multiple copies of same data are stored on different


nodes in the network.

 As data is available on multiple nodes, there is no chances of single


point of failure like in traditional client server model.
 Failure of a single node does not affect the data as multiple copies
of the same data remain safely and securely available on other nodes.

 If one copy of data changes or becomes inaccurate, on majority of


nodes/peers exact and accurate copies exists which makes false
record outdated. network.
Transaction in Bitcoin

 A transaction is a transfer of Bitcoin value on the blockchain. In


very simple terms, a transaction is when participant A gives a
designated amount of Bitcoin they own to participant B.
 Transactions are created through mobile, desktop or hardware
wallets.
 For Bitcoin users, sending a transaction is as simple as entering an
amount and an address in their wallet and pressing send. They don’t
have to worry about the technicalities of how it works. Many users
are curious how it works in practice though.
 Bitcoin makes use of public-key cryptography to ensure the integrity of
transactions created on the network. In order to transfer bitcoin, each
participant has pairs of public keys and private keys that control pieces of
bitcoin they own.

 A public key is a series of letters and numbers that a user must share in
order to receive funds. In contrast, a private key must be kept secret as it
authorizes the spending of any funds received by the associated public key.
To better illustrate how value is transferred in the Bitcoin network, we
will walk through an example transaction, where Alice sends .05 bitcoin
to Bob.
A transaction has three main parts:

Inputs. The bitcoin address that contains the bitcoin Alice wants to send. To
be more accurate, it is the address from which Alice had previously received
bitcoin to and is now wanting to spend.

Outputs. Bob’s public key or bitcoin address.

Amounts. The amount of bitcoin Alice wants to send.


 In order for Alice to send the .05 bitcoin to Bob, she signs a message
with the transaction details using her private key. The message contains
the input, output, and amount as described above. The transaction is then
broadcast to the rest of the Bitcoin network where nodes verify that Alice’s
private key is able to access the inputs (by checking that Alice’s private
key matches the public key she is claiming to own).
 Once a transaction is broadcasted to a node, this node then passes it
along the network until it reaches a mining node. Miners will then order
this transaction into what is called a block template. This is a blueprint for
the block which the miner is attempting to add to the blockchain. If a
miner finds the next block in the chain, then this block template is mined
and becomes an immutable block on the blockchain. Finally, this block is
broadcasted to the network’s nodes who will include it in their copy of the
chain.
Block Mining

 Block Mining / Bitcoin mining refers to ensuring that transactions


are valid and added to the Bitcoin blockchain correctly using a global
network of computers running the Bitcoin code. The process of
mining is also the means by which new Bitcoins are created.
 The process of bitcoin mining involves the verification of new
transactions against the Bitcoin network, which results in the
production of new bitcoins.
 Bitcoin mining is the process by which Bitcoin transactions are validated
digitally on the Bitcoin network and added to the blockchain ledger.

 It is done by solving complex cryptographic hash puzzles to verify blocks


of transactions that are updated on the decentralized blockchain ledger.

 Solving these puzzles requires powerful computing power and


sophisticated equipment. In return, miners are rewarded with Bitcoin,
which is then released into circulation hence the name Bitcoin mining.
Block Propagation & Propagation time

 Block propagation refers to the dissemination of newly created


blocks across the blockchain network. When a miner successfully
mines a new block, it needs to be quickly shared with other nodes in
the network so that they can validate and add it to their copy of the
blockchain.
It is an average time that is needed for the new block to reach most
nodes in the network.
 In a large-decentralized network like Bitcoin, whenever the new
block is generated, it is broadcasted according to the transfer
protocol.
 Then the node transfers this block to those nodes which asked it to
do that. Before the block reaches each full-node in the network, it
passes through 7 intermediary nodes.
It is important that every honest node verifies the block before
relaying it to other peers
Distributed Consensus in Open environment

A procedure to reach a common agreement in a distributed or decentralized


multi-agent platform. It is important for the message passing system.
A number of processes in a network decide to elect a leader. Each process
begins with a bid for leadership. In traditional or conventional distributed
systems, we apply consensus to ensure reliability and fault tolerance.
It means, in a decentralized environment when you have multiple
individual parties, and they can make their own decision, then it may
happen that some node or some parties are working maliciously or working
as a faulty individual. So in those particular cases, it is important to come to
a decision or common point of view.
 So having a common point of view in an environment where people can behave
maliciously or people can crash the work in a faulty way, is the main difficulty.
So under this kind of distributed environment, our objective is to ensure
reliability which means to ensure correct operation in the presence of faulty
individuals.
Feature
•It ensures reliability and fault tolerance in distributed systems.
•In the presence of faulty individuals, it is Ensure correct operations .
How to achieve distributed consensus :
There are some conditions that need to be followed in order to achieve
distributed consensus.
•Termination – Every non-faulty process must eventually decide.
•Agreement – The final decision of every non-faulty process must be identical.
•Validity – Every non-faulty process must begin and ends with the same value.
•Integrity – Every correct individual decides at most one value, and the decided
value must be proposed by some individual.
Consensus in Bitcoin Network

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
Types of Consensus Mechanisms

Proof of work, or PoW: it is a method of verifying and tracking the


creation of new cryptocurrency and transactions that occur on a
cryptocurrency blockchain. Cryptocurrencies, such as bitcoin, rely on
proof of work algorithms to maintain their respective crypto networks.
•Proof of work is a method that uses computing power to achieve
distributed consensus.
•Proof of work cryptocurrencies rely on large networks of computers
operated by crypto miners, who are responsible for verifying and
tracking transactions and minting new currency.
•Proof of work transactions are maintained on a public distributed
ledger called a blockchain, which is nearly impossible to hack or edit.
•Anyone with a compatible computer, a fast internet connection, and
the right computer skills, can use the proof of work protocol as a
crypto miner.
Proof of work is what cryptocurrency miners must show, and show
the fastest, to win the right to mine a block of crypto. The “work” is
solving highly complex math problems, and the “proof” is the
solution to the problem.
Computers around the world specialized for quickly solving these
complex math problems compete against each other to solve the
puzzle, earning the right to verify the next block of crypto
transactions. The winning miner that verifies the block and earns a
reward, paid in cryptocurrency.
With the need to rapidly complete computational work, crypto miners
use computing equipment that is designed to quickly verify crypto
transactions and maintain a record of past transactions for the
blockchain network. The use of cryptographic technology allows
anyone to send and receive digital assets securely.
Bitcoin, the oldest and the largest cryptocurrency by market
capitalization uses proof of work to verify transaction
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.
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.
Attacks on poW
1.Sybil Attacks
2.Denial of Service(DOS) Attacks
SybilAttacks :
In Sybil attacks, the attacker attempts to fill the network with the clients
under its control. When this thing happens the attacker can actually
control or get a monopoly over the network and these clients can do
different kinds of actions based on the instruction from the attacker.
They can refuse to relay the valid blocks or they can only relay the
blocks which are generated by the attackers and those blocks can lead to
double-spending.
Denial of Service (DOS) Attacks :
In this attack, the attacker sends a lot of data to a particular
node so that node will not able to process normal Bitcoin
transactions. As a result, the metabolism of the mining
procedure will get delayed which wastes the power for
computation and in that meantime, the attacker can also send
new nodes to the network resulting in a monopoly which is
nothing but a Sybil attack.
Proof of stake (PoS)
 Proof of stake (PoS) is an approach used in the cryptocurrency
industry to help validate transactions.
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.
Benefits of pos
•Smaller resource requirements. The ability to add a node to the blockchain,
requires less computing power.
•Lower energy utilization. With the need for less computing power comes a
corresponding decline in the amount of energy consumed in order to validate a
transaction.
•Speed. A node can be added quicker with PoS, enabling faster transaction
throughput.
•Scalability. The PoS-based approach has the potential to be more scalable than
PoW as the requirements and resources to have a stake may be lower than the
hardware and energy costs of PoW.
The life of a Bitcoin Miner
 Sender creates a transaction.
 Sender's bitcoin wallet validates the transaction.
The transaction is sent to Mempool.
 Miners get the transaction from Mempool and start mining the block using a
consensus algorithm.
 After the block is fully mined, it is added to the network.
The chain validates the new block and every peer in the network will get the
blockchain with the new block added.
 Finally, the Receiver get your BTCs
Mining Pool
A mining pool is a joint group of cryptocurrency miners who combine their computational
resources over a network to strengthen the probability of finding a block or
otherwise successfully mining for cryptocurrency.
How a Mining Pool Works?
· Individually, participants in a mining pool contribute their processing power toward the
effort of finding a block.
· If the pool is successful in these efforts, they receive a reward, typically in the form of the
associated cryptocurrency.
· Rewards are usually divided between the individuals who contributed, according to the
proportion of everyone’s processing power or work relative to the whole group.
· In some cases, individual miners must show proof of work in order to receive their rewards.
·Anyone who wants to make a profit through cryptocurrency mining has the choice to either go
solo with their own dedicated devices or to join a mining pool where multiple miners and their
devices combine to enhance their hashing output.
Basics of mining difficulty

As a cryptocurrency like Bitcoin becomes more popular, the number of computers


participating in its peer-to-peer network increases. Miners compete against each other
for limited block rewards. With more participants and more computing power, the so-
called “hashpower” of the entire network increases accordingly.
· This is also referred to as the mining difficulty or difficulty. Bitcoin transactions
are stored in blocks, which are added to the blockchain every 10 minutes (= 600
seconds).

· To maintain the time it takes to process one block at around 10 minutes, difficulty
has to be adjusted periodically.
Proof of Burn

In the Proof of Burn (PoB) algorithm, miners reach a consensus


by burning the coins. It’s a process in which crypto coins get
permanently eliminated from regular circulation. In such cases,
the burning of coins mechanism is used to validate transactions.
Hence, the more coins a miner burns, the higher the chances of
adding the block to the network.
We have 6 miners, each having their own block of
transactions. As per the process, the miners have to burn
some amount of coins to get an opportunity to add their
block to the network.
See the below diagram. Each miner sends some of their
coins to the burn address
John wins as he burns the maximum number of coins. Hence, he gets
the chance to add his block of transactions to the network.
Moreover, the block added by John will be verified by other network
validators. If the block is found invalid, then the second-highest
(Ross) gets the chance to add a new block.
Proof of Elapsed Time (PoET)

 PoET is a consensus algorithm used in a permissioned blockchain


network to decide mining rights and next block miner. FYI,
a permissioned blockchain network requires participants to prove
their identity, whether they are allowed to join. Hence, it needs
permission (or invitation) to join the decentralized network as a new
participant ( or node).
 The PoET algorithm was developed by Intel Corporation
 Intel introduced PoET as a time-lottery-based consensus algorithm
secured by cryptography. The concept basically motivates the idealogy
of giving equal chances of getting a reward like a lottery.
 The time-lottery concept allows everyone in the network an equal chance
of winning the reward and being able to forge a new block to the network.
The PoET controller maintains a stopwatch for each participating node. It
ensures their waiting time ended, and now they can forge a new block. When the
node wakes up, it submits the block and a cryptographic test to the PoET
controller for verification.
 A newly proposed block selects if the controller approves the newly proposed
block by the first woken up node. Else it gets discarded. And then, the selection
process of assigning waiting time starts again.

You might also like