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

Blockchain Basics

Blockchain is a distributed immutable ledger that allows for trustless transactions without intermediaries. It works using a distributed peer-to-peer network, cryptography, and a consensus mechanism. Blockchain was originally developed for Bitcoin and allows value to be transferred in a decentralized manner through cryptocurrencies. It has many applications beyond just currency, including supply chain tracking, smart contracts, and more efficient international payments.

Uploaded by

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

Blockchain Basics

Blockchain is a distributed immutable ledger that allows for trustless transactions without intermediaries. It works using a distributed peer-to-peer network, cryptography, and a consensus mechanism. Blockchain was originally developed for Bitcoin and allows value to be transferred in a decentralized manner through cryptocurrencies. It has many applications beyond just currency, including supply chain tracking, smart contracts, and more efficient international payments.

Uploaded by

Venkateswaran T
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Blockchain Basics

BlockChain is a Disruptive technology.

Internet - communication
Blockchain - Trust

Invention after the 2008 financial crisis.


For eg - NGO is the fund really reaching out needy?

Idea - Stuart Haber and W Scott Stornetta --> How to digitally time stamp a transaction? - paper name

What is BlockChain?
Blockchain is a Distributed immutable ledger which is completely transparent . It is a Decentralized
System.

Ledger Book becomes a --> Block --> data once entered in block can’t be changed
So Immutable

Application of BlockChain
1. Product Tracking → every product has a QR code → we will get the name and complete
information.

2. Smart contract → Program which runs on Ethereum Blockchain. For eg consider a Delivery
man who has to maintain a temperature less than 15 degree then the shop keeper will take it and pay
him back else he won’t pay him No need to take legal actions like if he provided the rotten fruits.

3. International Wire Transfer → Sender bank to Correspondent Bank then it is received by the
Receiver . So a lot of steps are involved so time taking → Huge Fees as a lot of steps are involved
(commission).

4. Health Care System → Eg. person A reached out to City A. But in another case because of a
medical emergency , he reached out to city B . But B has no medical history so it takes time to analyze
and then provide treatment. If the Database is decentralized in the form of a Single Block chain , then a
lot of time will be saved.

Hashing Algorithm

Block and its Components


Block has 4 components . They are
1. Block number
2. Data
3. Previous Hash - used for linking two blocks
4. Hash (So unique - used for identification)
generated by -> SHA256 Algorithm --> 64 Hexadecimal characters so 64*4 = 256 bits
Input like Document, audio , video outputs 64 hexadecimal characters.

First Block is called as Genesis Block


Requirement of Hashing Algorithm
1. One Way - Data can only be encrypted and not decrypted
2. Deterministic - for an input the same output will be provided . Eg for 123 is input then output
will be ABC . We can repeat this any time we will get the same output for the same input.
3. Withstand Collision - can’t be hacked
4. Avalanche Effect - For a small change is input then will be a huge change is output Hash
(Encrypted data) for eg. Hello and Hell will have completely different Hash generated.

Immutable Ledger
You liked a House . Wanted to buy it . Sign a Contract that the House is on our name with the Seller.
This data will be saved in a centralized Database or maintain a Register. This biggest problem is that it is
mutable and it can be corrupted or destroyed easily.

The idea of decentralization and distribution networks can make our lives easier.
If a Hacker hacks a particular block then the following will be corrupted because of avalanche effect
and this process goes on until the whole block chain gets corrupted . The other systems owning the
same blockchain it rectify and restore this blockchain

What is a P2P network?


P2P - Peer to Peer network . In the Client server model , the server has all the data of the clients. For
need in data , the client sends a query request and the server responds back with the data. A
Centralized server can be hacked and can lead to data leak --> no data privacy.

Distributed P2P network - peers are connected to each other . If Data in system A is corrupted , then
system B will provide the data needed .

How does it work?


Every mine has a block chain which was mined . Let us consider system A has mined a block and it is
added to it. Blockchain . Then this information is sent to all the systems connected with it. So they
update their blockchain.Every one has the same Blockchain.

Need of Distributed BlockChain


The data which is corrupted , has to be recovered. Consider a situation when a hacker hacks a
particular blockchain of system A and the block which he attacks and consequently, the whole block
chain is hacked . So now system A wouldn’t know that its data was hacked. But the rest of the systems
present in the network will inform system A. That data which the posses doest match with the present
system A blockchain. And provides the data to recover it.
So it is impossible to hack mainly because of immutability and a p2p network.

Blockchain mining
Transaction --> Solve Math problem (as known as proof of work)--> if solved, a block is created (it
contains the transaction) --> miner verifies the Validity of the block --> block is added --> miner is
rewarded.

What is the need of blockchain mining?


1. For checking the validity of the transaction --> then solve the proof of work
2. Verifying the genuine of the block (he may be hacker or someone who is trying to
manipulate the info the blockchain so to avoid them) --> then add in blockchain
Byzantine Generals Problem
Consider a situation in which there are 4 soldiers in 4 different places, in that one is a traitor . They don’t
have a king to manage them but all four were confused about whether they should attack a city or not .
One soldier sent a message to the rest of the soldiers that they have to attack and similarly the other
two did the same but the traitor said that they shouldn’t attack. So we can clearly see that the
information in the network can’t be trusted easily and its validity has to be checked.

So Miguel Castro came up with a solution to this problem. Byzantine fault tolerance
The recovery mechanism allows the algorithm to tolerate any number of faults over the lifetime of the
system provided fewer than 1/3 of the replicas become faulty within a small window of vulnerability.

Consensus Protocol
1. Prevent Attacks
2. Competing chain problem

Prevent Attacks

1. Proof of Work
2. Proof of state , etc

Proof of work → when a hacker tries to add a block at the end of the blockchain we wouldn’t be able to
know that. Because the concept of immutable ledger can’t be applied.
Let's consider a miner mines a block but solving a problem , it’s very difficult to solve and the resources
of great amounts are used. After the proof that they have created a block So it is called as proof of
work. Then the block is added to the blockchain and similarly they will be rewarded. No one will waste
their time and money by doing malicious activities after doing this much hard work.
When system A adds a block then other nodes try to run an algorithm and check the validity of the
algorithm. Then they add that block to their blockchain.

Is it a time taking Process ?


No, the algorithm used for verification is very fast and it just takes a few seconds. Now solving the math
problem is a time taking problem.

Competing chain problem


In a situation where two systems - system A , system C at the same time they mined a block and added
to their blockchain. This information is passed to the near nodes. System A sends this to system F , E
and they update their blockchain similarly system C sends its info to system B it also updates. This
process goes on. This leads to irregularity in the blockchains of the network.

Solution : The blockchain with the longest number of blocks is accepted and the nodes that have the
largest computing power will be chosen as they add the block faster and become longest.

Orphan block → blocks which are deleted

● Consensus protocol - 51% majority


● Byzantine Fault Tolerance - 66% majority
All transactions in the orphan Block will be deleted and it will be dropped and no credit will be provided
to the miner.So that’s why wait for the 6 confirmations before assuming payment to be successful.
Cryptography basics

What is Bitcoin?
First crypto currency .
Founder of bitcoin - 2008 - Satoshi Nakamoto

Bitcoin vs Blockchain

1. Technology - Blockchain
2. Protocol/coin - Bitcoin , ethereum, waves (protocol is nothing but rules to be followed)
3. Token - used mainly for investment. Waves , ethereal have tokens as the follow the smart
contract but bitcoin doesn’t.they are mainly made from the protocols.

Bitcoin’s Monetary Policy


To minting the the supply demand

1. The halving
2. Block Frequency

The halving:
The number of bitcoins will be reduced to half for every 4 year that it is for every 210,000 blocks.
Note - Supply cap of bitcoin is 21 million. This is making it rare like gold.

Block Frequency:
This states that on an average it will take 10 minutes to create a new block.Different cryptocurrencies
will have different average time.
Both the processes are halving and block frequency is controlled by the blockchain algorithm which
makes it trustworthy and more beautiful.

How mining works ?


The Nonce
Definition of Nonce : The nonce is the number that blockchain miners are solving for.
Change in nonce value --> changes the hash value

Point to note : hash value should be less than or equal to the target value. Every miner will be provided
with a target value which is like a math problem that he has to solve with the help of nonce value.
The other parts of the block like block number, data (transactions)and prev hash can’t be edited . So
miners have to change and try different nonce values so that the hash value is in range (less than or
equal to target value). If the value comes in range then he will be rewarded for mining a block.
The whole math problem is about finding the hash value within the target value.

The target

1. Target is a number used in mining.


2. It is a number that a block hash must be below for that block to be added on to the blockchain.
3. The target adjusts every 2016 blocks (roughly two weeks) to try and ensure that blocks are
mined once every 10 mins on average.

Hexadecimal number - output of the SHA256 is in this form. (64 characters * 4bits = 256 bits)

In all the possible hashes a particular target is set , above which hashes are considered invalid.

CPU vs GPU vs ASCI


How fast the hash is generated --> determines the success of mining.

1. Cpu < 10 MH/s (10 million Hashes per second)


2. GPU < 1 GH/s (1 giga Hashes , giga --> 1 billion )
3. ASIC > 1000 GH/s

** 2014 stats

Mining pools
When the hashing power of an individual miner is less, they form a network and try to hash together so
that --> they increase the chance of solving.
This is achieved by forming mining pools. In mining pool
1. Reward will be distributed in proportion to that hashing power.
2. The hashing range will be divided between the miner in the mining pool(network) so that
maximum resources are being utilized and no computational power is wasted.
3. This concept was developed because the large mining companies which have the highest
computational power succeed very easily and get rewarded . This becomes disadvantageous to the
small miner with minimal resources .So they joined together forming a mining pool.

Nonce Range
Nonce is a 32 bit number
Range of nonce 0 to 2^32-1 = 4 * 10^9 (4 billion)
Total number of possible hashes = 16*16*16* (64 times) = 10^77

10^77 is much much much larger than 4*10^9.


If the nonce value doesn’t map with the hash value generated. It can be clearly seen that the range of
nonce is not enough for the range of hash functions generated by the SHA256 algorithm.

A modest mines does 10^8 hashes/ second (it means nonces/ second)
4* 10^9 nonce will be covered in (4*10^9)/(10^8) = 40 seconds.

So what do the miners do when all the nonces get exhausted and miners have not hit the target?

Time Stamp
In a block here is a section that contains Timestamp (UNIX time).

As we know that due to the avalanche effect, there will be a greater change in the hash value.
A miner exhausts 4 billion nonce in 40seconds. --> A miner will exhaust 0.1 Billion nonce in 1 seconds.

In 1 sec , 0.1 billion nonce will be exhausted and the time stamp changes (1 sec) and the nonce can be
reused. This overcomes the problem faced above.

Current easing rate is equal to 180 million trillion hashes / sec (of a complete network nowadays) 10^6 -
million 10^12 - trillion
4 * 10^9 will be covered in = (10^6 * 10^12) = 4*10^-9 seconds
4* 10^-9 sec is very very very small than 1 second.

So now the timestamp is not that useful. As nonces are getting exhausted before 1 sec .

What should the miners do in their idle time ? Should they wait for the timestamp to change?

Mempool
Every transaction has a id and transaction fees
Mempool- contains thousands of transactions. Miners choose unconfirmed transactions from it which
have the higher transaction fees.

If the nonces are drained and time is not one second then the transaction with the lowest transaction
with the highest transaction present in the mempool . This change because of the avalanche effect
creates nonces to start from first. This process repeats until the timestamp increases by one second.
The nonces will be hashed as usual.

How does mempool work (behind the screen)?


Node - whose does the transaction
Miner - who mine the coins

Fig a Fig b

When a transaction is carried out by a node it will be added to mempool this information is passed to all
the mempools and miners present in the network. By continuing this process, mempool contains
thousands of transactions. Miner has access to mempools . Miner choose a transaction and add it in the
blockchain. After it is verified by others, everyone adds the block in the blockchain and that added
transactions are removed from the mempools.

Transaction and UTXOs


UTXO = Unsent transaction output
Transactions present in the blocks are called UTXOs.

Fig 1 Fig 2 Fig 3

It can be clearly seen that how a transaction takes place in a transaction takes place and the
immutability is maintained . It is an example showing a transaction which we have made for buying the
coffee.

Transaction Fee
For authorizing a transaction , miners have to be provided with some commission , that is called
transaction fees.
Transaction fees are usually decided by the node .
Higher the fee, the more the miner will be interested , lower the fee no tier will pick that transaction and
finally after two or more days it will be removed from the lists.
Here 0.1 etc will be added in UTXOs of the miner.

Cryptocurrency Wallets
Wallets try to find the unused transaction and try to sum them up. With the help of UTXOs.

Private key and public key


Private key shouldnt be disclosed to anyone. But public is used for receive transactions

Message + private key = signature


Message + Public key + signature --> verification function --> yes/no
This shows that transactions done by us are verified and can be viewed by others.

Bitcoin address
If in future hackers are able to find the private key from the public then hackers may steal or corrupt the
data.
Bitcoin addresses are used to get the transaction from others. This is derived by the 256SHA algorithm.

Public is used when we are providing the bitcoins and bitcoin address is used when others are
providing the bitcoins to us. It provides another layer of security .

Segregated Witness
Increase in block size can increase the number of transactions which in turn lead to higher commission
of the miners. But the main disadvantage is that as the size increases the traveling of the block across
the network takes much.
Every transaction has the following fields

1. the encrypted transaction


2. Who is sending it?
3. to whom it is sent?
4. signature
5. Public key

Here signature and public key are together called as Script sig

60 to 60% of the block is occupied by the signature and public key.


So this problem is overcome with the help of segregation of the witness (that is signature and public
key).

Hierarchy deterministic (HD)wallet


When we use the bitcoin address to make payment daily in the shop that we visit, the hacker can
clearly see that that particular bitcoin has made transactions in a regular interval of times. So they might
track you down. This is yet another privacy issue which needs to be solved.

Master private key → private key 1 → public key 1 → address 1


(Master private key +1) --> private Key 2 --> public key 2 --> address2
(Master private key +2) --> private Key 3 --> public key 3 --> address3
(Master private key +3) --> private Key 4 --> public key 4 --> address4

We can clearly see that bitcoin addresses are continuously changing.


Master private key can track down all that Transaction of all the private keys but vice versa is not
possible.

Master public is used to track down the transaction and they can’t make payment. Only using private
keys , we can perform a transaction.
Ethereum basics

Founder of Ethereum - Vitalik Buterin


Ethereum - is a open source blockchain based platform
Eg Bitcoin - bitcoin ,Ethereum - ether

Types of nodes

1. Full node
2. Light node
3. Achieved node

Full node

1. locally stores the entire copy of the blockchain


2. verify and validate the transactions.
3. It requires a lot of resources.
4. mainly they are miners.

Light node

1. stored only the block header.


2. depends on the full node for data
3. For low capacity defied which cannot afford to store the gigabytes of data.

Archive nide

1. Stores everything kept in the full node


2. It is an archive of historical data.
3. required terabytes of disk space.

Ethereum Accounts
This unity has an ether(ETH) balance that can send or receive transactions on ethereum .

Types of ethereum account

1. Externally owned account


2. Contract account

1. Externally owned account

When we create a wallet , an externally owned account is created which can be assessed only through
the private key . Private key is used to open the wallet.This wallet is used for
● sending ether
● receiving ether , and
● interaction with the smart contracts.

1. Contract account

It is controlled by a contract pool. Contract account has a unique address which is called contract code.
Through this account the interaction between the ethereum and smart contract. We have to deploy a
smart contract in the ethereal blockchain . This deployment leads to the generation of unique
addresses.

Different between two accounts

Smart Contract
A program which runs on the ethereum blockchain.
For bitcoin generation we use bitcoin script
For ethereal we use the solidity language
Bitcoin script - not Turing complete (it doesn’t have the concept of loops)
Solidity - Turing complete (any logics can be implemented)
If we write an infinite loop then what will happen ? It will lead to an ethereum crash. So to rectify
this , for running a program in ethereum we need to buy something called gas (we need to pay for it). If
the gas ends it will lead to stop of the running of the program( which includes an infinite loop as well).

Smart contract runs on all the nodes of the network.


Each node has the following (considering node as a full node)

● current state of all smart contracts


● history of the transaction and contracts

Decentralized Apps(Dapps)
Ethereum Virtual Machine (EVM)
Apps will be running on all the nodes. to keep the nodes safe we need to use the virtual machine on
our computer.

Ethereum Gas
For running a code, energy(gas) is required. Every operation has its gas.for example add has 3 gas,
multiply needs 5 gas.
Some important point to note
● any transaction that modifies the blockchain costs gas
● the user that generated the transaction pays for the gas.

Ethereum gas price


It is the amount the sender wants to pay per unit of gas to get the transaction mined. gasPrice is set by
the sender.
Gas prices are denoted in Gwei (1 Gwei = 10^ -9 eth)
The higher the gas price the faster the transaction will be mined. It is just like the Transaction in bitcoin.

Ethereum Gas Limit


It is the maximum gas which the transaction can consume.
Set by the sender
Let's say A wants to send B 2eth . So what will be the total fees A that has to pay?

Solution
Case 1:
A sets the gas price per unit = 100gwei
Transaction gas limit = 21000 units
Total fees = gas units(limit) * gas price per unit

Total fee will be : 21000*100 = 210,000gwei = 0.0021ETH

Case 2:when the transaction limit < 21000units


Transaction gas limit = 20000
Transaction failed

Case3: when the transaction limit > 21000 units


Transaction gas limit = 22000
22000 - 21000 = 1000 will be returned.
1000 will be returned.
Decentralized Autonomous Organization(DAO)

Traditional system in organization Difference between them

Eg in an NGO we can write a smart contract, and make it trustworthy.

The DAO Attack


Here, The DAO is an organization which uses the concept of DAO. It was started in Germany in 2016.
DAO attack led to hard fork.

Hard Fork
The ethereum split into 2. One was ethereum classics and the second one was ethereum . There was
an error in the smart contract. Some wanted to rectify it but others didn’t want to change and follow the
principles of blockchain .So there came a split in the ethereum.

● During a hard fork, software implementing a protocol and its mining procedures is upgraded.
● Once a user upgrades the software , that version rejects all the transactions from the older
software effectively creating a new branch of the blockchain.
● However , those users who retain the old software continue to process transactions.

The split in bitcoin is depicted here.


Because of the change in the size of the block , there is a split in the blockchain and thus there is no
going back now.

Soft Fork

● Soft fork is the change to the protocol, but the end product remains unchanged.
● A soft fork is a backward compatible upgrade, meaning that the upgraded nodes can still
communicate with the non-upgraded ones.
● Old nodes (not upgraded nodes ) could still validate blocks and transactions (the formatting
didn’t break the rules) but they just wouldn’t understand them.

Because of the longest chain rule, the 0.8mb block is removed as the majority has the maximum
hashing power and hence generates the block more rapidly than the non-upgraded blocks. Here we
can see that the blockchain didn’t split and still communicate with each other.

Initial Coin Offering (ICO)

This is the structure of ICO. You won’t have


More the share more the power in the company
control but you will enjoy some benefits.
- this is the structure of an IPO.

Ethereum 2.0 or serenity

● Scalability
● Security
● Sustainability

Eth2 major updates


● Proof of stake(POS)
● Sharding

Proof of stake
No miner, only validator.
Validator has to given some ethers to the system (there is a minimum requirement for eg 32 eth)
Attaching of block => attestation
After his job is completed , he will provide back the ether and transaction fees. If the validator is trying
to do sth wrong then it won’t be provided with ether and fees as well. This concept is called as proof of
stack.

There is no competition in mining between the validators. They are selected randomly. But the more
ether you pay , the more chance of getting randomly selected.

Sharding
What are the issues in proof of work?
Information lag may take place
Miners get paid for mining and not validation and verifying has to be done ( which is a time taking
process) so they are paid less and it is indirectly leading to time waste.
Maintenance becomes very difficult.
Sharding is similar to splitting a database because miners can deal with the particular amount of data.
Major benefits
● transaction per second increase
● powerful and expensive computer will not be needed
● More validator will job
● Envy consumption can be reduced

Beacon chain + ethereum main net + shard chain will be integrated and this will be a revolutionary
technology.

Alt coins
Coins which are not bitcoin are called alt coins. Example tether, chainlink, litecoin, finance coin.

● Consensus protocol
● New capabilities

As of march 2021 , there were almost 9000 cryptocurrencies.


Ethereum and finance coins were the largest alt coins by market capitalization as of march 2021 .

You might also like