Blockchain
Basics
Dr. Mallikarjun Reddy Dorsala
Blockchain researcher and lead
McKinley Rice
What is Blockchain?
“Open, distributed ledger that records transactions
between two parties in a verifiable and immutable
way”
What is Blockchain?
Blockchain is a distributed ledger that…
➔ can contain financial and/or non-financial transactions.
➔ Contain a ledger that is replicated (distributed) across a number of systems
in near real-time over a peer-to-peer network.
➔ Every participant “owns” the same copy of the ledger and gets updates
when any transaction is added to the ledger.
➔ Every participant helps determine the intrinsic “immutability” of all
existing records.
➔ uses cryptography and digital signatures to prove identity, authenticity and
enforce read/write access rights.
➔ has mechanisms to make it hard to change historical records, or at least
make it easy to detect when someone is trying to change it.
Little History
➔ 1991 - Stuart Haber & W. Scott - cryptographically secured chain
of blocks.
➔ 1992 - Merkle trees + cryptographically secured chain of blocks
➔ 2004 - Hal Finley - Reusable Proof-of-work (RPoW) - Digital
cash
➔ 2008 - Satoshi Nakamoto - Bitcoin
➔ 2014 - Vitalik Buterin - Ethereum 1.0
➔ 2022 - Vitalik Buterin - Ethereum 2.0
Blockchain components
An open, public Blockchain is a combination of
several components.
➔ Peer-to-peer network
➔ Public-key cryptography
➔ Distributed ledger
➔ Consensus protocol
➔ Smart contracts
➔ A one or more client softwares
➔ Wallets
Peer-to-peer network
➔ All the communications (transactions) occur
directly between peers without a central entity.
➔ Each peer stores and forwards information to all
other peers.
➔ Advantages with P2P networks:
◆ Decentralization
◆ High Availability
◆ Immune to DoS attacks
◆ No censorship by central authorities
➔ Examples : Napster, Bit torrent, Skype
Public-key cryptography
➔ Every peer in the Blockchain network is associated
with a public-private key pair.
➔ The public key is used to identify a peer uniquely
in the network. All the assets are listed under the
public key.
➔ But a corresponding private key is required to
transfer the ownership of the asset.
Distributed ledger
➔ A distributed ledger can be described as a ledger of any
transactions or contracts maintained in a decentralized form
across different locations and peers.
➔ Every peer in the network has access to information stored at
the distributed ledger, and no single peer can control the data
stored at the ledger.
Distributed ledger vs Blockchain
➔ Distributed ledgers can be of many types and Blockchain is a specific
type of distributed ledger.
➔ A Blockchain distributed ledger is maintained as a set of blocks, such
that each block is cryptographically chained to its parent block (except
first block).
Blockchain vs blockchain (ledger)
➔ In general, to differentiate between the distributed ledger in Blockchain
and the whole Blockchain technology, the following terminology is used
◆ blockchain - represents distributed ledger in Blockchain
◆ Blockchain - Network + ledger + consensus
Block structure
➔ A Block contains:
◆ Header
● Hash of the previous Block
● Merkle hash of the transactions
● Consensus information
◆ Body
● Contains transactions
➔ Bitcoin Block structure
◆ https://blockstream.info/
➔ Ethereum Block structure
◆ https://etherscan.io/
Genesis Block
➔ Genesis => First
➔ The genesis block of Bitcoin is as follows:
https://blockstream.info/block/000000000019d6689c085ae1658
31e934ff763ae46a2a6c172b3f1b60a8ce26f?expand
“The Times 03/Jan/2009 Chancellor on brink of second bailout for banks”.
➔ The genesis block of Ethereum is as follows:
https://etherscan.io/block/0
Consensus algorithm
➔ If all the peers have their own copy of ledger, how do they all
have the same copy of the ledger?
➔ In Blockchain, a secure consensus algorithm is executed by a set
of decentralized peers known as miners to agree on a common
global state of the distributed ledger.
➔ Consensus algorithm also guarantees the security of the ledger.
Consensus algorithms examples
➔ PBFT
➔ Paxos
➔ RAFT
➔ PoW
➔ PoS
➔ DPoS
➔ PoA
Proof-of-work
➔ In PoW, a computer is required to solve a computational problem of a
predetermined level of difficulty.
➔ In Bitcoin Pow, a miner has to find a nonce such that the hash of a
block is less than some predetermined value.
➔ The predetermined value is called as target. Target is a 256-bit
number. Lower the target value, difficult it is to produce new block.
➔ It’s like a lottery. You will win if your ticket number is less than some
value.
➔ Here, a miner is allowed to produce a new block, if he can generate the
hash of the block less than the target.
➔ Formally: G(nonce,H({blockHeader}/nonce)) < target. G and H are
256-bit hash functions.
➔ Nonce is also a 256-bit number. By varying the nonce form 1 to 2256 a
miner has to find the hash
Proof of work example
➔ Let the nonce is 4-bits i.e, nonce has values 0-15.
➔ Let G and H outputs the hash of 4 bits.
➔ Let target is also 4 bits.
➔ Let the current target is 1100
➔ Let the H({blockHeader}/nonce) = 1001
➔ Then we have to find a nonce such that H(nonce,1001)<1100
◆ Now H can output 0000,0001,0010,0011,0101,0110,0111,1000,1001
◆ Probability of finding the nonce is 9/16
➔ Let increase the difficulty by lowering the target. Let the new target is
0011.
◆ Now H can output 0000,0001,0010
◆ Probability of finding the nonce is 3/16
Disadvantages of Proof-of-Work
➔ PoW is a computation heavy algorithm.
➔ The search space is 2256, meaning that in the worst-case scenario,
that is for the lowest target, a miner has to perform 2256 hash
operations.
➔ Due to large number of computations, a lot of power (current) is
wasted in finding the nonce.
➔ Many miners will compete to produce a new block, but only one will
succeed. Thereby wasting all the power.
➔ 51% attack
Proof-of-Stake
➔ In PoS, the miner/validator is selected based on the stake he is having
rather than competing to solve a computational problem.
➔ There are multiple variations of PoS:
◆ Coin-age based PoS
◆ Random-stake based PoS
◆ Fixed-stake based PoS (Ethereum 2.0 PoS)
◆ DPoS
Putting it all together
1. Person A want to transfer 10 ETH to Person B
2. Person A creates a transaction
3. With the help of his wallet, person A, signs the transaction and sends the nodes to a
remote node.
4. If remote node is full node, it verifies that transaction and broadcast it. Otherwise, it will
simply broadcast the transaction.
5. All the receiving nodes verifies the transaction and add it to buffer called mempool /
transaction pool.
6. All the mining/validator node try to produce the next block in the ledger, which may
have A’s transaction.
7. One of the mining node will succeed in producing a new block containing A’s
transaction.
8. Then, the new block is broadcast to the network. All the receiving nodes verify the block,
if block is valid, then they add the new block to their local copy of blockchain and
continue to compete for producing the next block.
9. Person A’s wallet will show transaction confirmation message and updates the balance.
Smart contracts
➔ A smart contract is a program deployed and stored in a
Blockchain.
➔ A smart contract can hold many contractual clauses between
mutually distrusted parties.
➔ Similar to transactions, the smart contract is also executed by
miners and, its execution correctness is guaranteed by miners
running the consensus protocol.
➔ Assuming that the underlying consensus algorithm of a
Blockchain is secure, the smart contract can be thought of as a
program executed by a trusted global machine that will
faithfully execute every instruction.
Properties of a Blockchain system
➔ Decentralization
➔ Immutability
➔ Transparency
➔ Persistency
➔ Public Auditability
➔ Privacy
➔ Programmability
Quiz
➔ How Blockchain solves Double spending attack?
◆ Let us assume a person A try to spend same amount of money by sending it to two
different persons. A->B and A->C are the two transactions. Now, a mining node
might receive both or only one transaction.
● If a mining node receives both:
○ He chooses one of the transactions, executes the transaction and rejects
the second transaction as it is a double spending transaction.
● If a mining node receives only one transaction. He includes that in a block and
propagates the block. All other mining nodes, receives the block, re-executes
the transaction. Now, if any other mining nodes receive the second transaction,
they will simply discard it. Because, they already have the first transaction
recorded.
➔ What is the purpose of proof-of-work algorithm?
◆ It is a leader election algorithm. The person solving the PoW, gets the rights to
produce next block.
➔ What is 51% attack.
◆ If an attacker gets 51% of the hashing power in the network, he can produce blocks
faster than rest of the network, there by jeopardizing the security of the Blockchain.