Unit-1 Notes
Unit-1 Notes
UNIT 1
What is Blockchain?
• It contains every single record of each transaction. Bitcoin is the most popular
cryptocurrency an example of the blockchain. Blockchain Technology first came
to light when a person or group of individuals name ‘Satoshi Nakamoto’ published
a white paper on “BitCoin: A peer-to-peer electronic cash system” in 2008.
• Blockchain Technology Records Transaction in Digital Ledger which is distributed
over the Network thus making it incorruptible. Anything of value like Land Assets,
Cars, etc. can be recorded on Blockchain as a Transaction.
• Distributed: Each participant in the network has access to the blockchain, and it
is not controlled by any single entity, which ensures redundancy and fault
tolerance.
• Immutability: Once data is written into a block and confirmed by the network, it
cannot be modified or deleted, which makes blockchain an immutable source of
truth.
Blocks: Each block in the blockchain contains a set of transactions that are grouped
together and added to the chain in a linear, chronological order. Each block also contains
a unique code called a "hash" that links it to the previous block in the chain, creating a
secure and unbreakable link.
Nodes: Nodes are the computers or devices that make up the network and are
responsible for validating and recording transactions on the blockchain. They can be
divided into two types: full nodes and lightweight nodes. Full nodes store the entire
blockchain and validate transactions, while lightweight nodes rely on full nodes to
validate transactions.
Smart contracts: Smart contracts are self-executing contracts that are stored on the
blockchain and can be used to automate certain processes and enforce certain
conditions. They are written in a programming language and are executed by the nodes
on the network.
Cryptography: Blockchain uses cryptography to secure the network and ensure the
integrity of the data stored on it. Cryptography is used to encrypt data, create digital
signatures, and ensure that only authorized parties have access to the data.
Wallet : A digital wallet is a program that stores public and private keys and interacts with
various blockchain to enable users to send and receive digital currencies and monitor
their balance.
Mining: In order for a new block to be added to the blockchain, it must be mined by a
node on the network. The process of mining involves solving a complex mathematical
problem that is used to validate transactions and create new blocks.
Forks : Sometimes the blockchain network may split into two different versions. This is
called a fork. The reason for the fork can be due to changes in the underlying code of the
blockchain or due to disagreements among the nodes of the network.
Since block is one of the building block of blockchain technology, block structure and its
key components are important to learn.
Block structure:
Components of Blockchain
Block: The basic unit in the blockchain. Each block typically contains the following
elements:
1. Block Header:
• Block Number: Each block has a unique identification number, or “block number,”
which indicates where that block falls in the timeline of the blockchain. It’s
common to refer to the first block as “Block 0” or the “Genesis Block.”
• Timestamp: The block’s timestamp contains the precise date and time of block
creation. It assists in determining the blockchain’s block order.
Each block apart from the Genesis Block makes reference to the hash of the block before
it. This links the blocks together to form a continuous chain, hence the name
“blockchain.” The integrity of earlier data is ensured by the hash of the prior block, which
also acts as cryptographic evidence of the block’s place in the chain.
3. Tree of Merkle:
• A cryptographic structure known as the Merkle tree root serves as a summary of
all transactions contained in a block. The Merkle root is produced by a Merkle tree,
which divides transactions into pairs, hashes each pair, and repeats this process
until it produces a single root hash. The block header contains the root hash.
• The Merkle tree structure makes it possible to quickly determine whether a certain
transaction is part of the block without disclosing any of the transaction’s
specifics.
The nonce is a random value or counter used in the process of mining, particularly in
Proof of Work (PoW) consensus algorithms. Miners must find a nonce that, when
combined with other block data, produces a hash that meets certain criteria usually
starts with a certain number of leading zeros. This process is computationally intensive
and ensures that blocks are added to the blockchain at a controlled rate.
5. Transactions:
• Each transaction contains the sender, receiver, amount, and any additional data
necessary for the operation of the particular blockchain.
• The largest amount of data that may be stored in a block, including all of its
transactions and other information, is referred to as block size. Block size
restrictions vary amongst blockchain networks.
• The block size restriction is crucial for preserving network efficiency and
scalability. It stops blocks from growing too big and clogging the network.
The block header of blockchains powered by PoW, such as Bitcoin, contains a field called
“difficulty target.” The complexity of this target determines how tough it is for miners to
locate a reliable nonce. To maintain a constant block manufacturing rate, it makes
adjustments from time to time.
8. Additional Metadata:
Blockchain Decentralization
There is no Central Server or System which keeps the data of the Blockchain. The data is
distributed over Millions of Computers around the world which are connected to the
Blockchain. This system allows the Notarization of Data as it is present on every Node
and is publicly verifiable.
Blockchain nodes
A node is a computer connected to the Blockchain Network. Node gets connected with
Blockchain using the client. The client helps in validating and propagating transactions
onto the Blockchain. When a computer connects to the Blockchain, a copy of the
Blockchain data gets downloaded into the system and the node comes in sync with the
latest block of data on Blockchain. The Node connected to the Blockchain which helps
in the execution of a Transaction in return for an incentive is called Miners.
Disadvantages of the current transaction system and the need of decentralised
system:
• The need for a third party for verification and execution of Transactions makes the
process complex.
• If the Central Server like Banks is compromised, the whole system is affected
including the participants.
• Organizations doing validation charge high process thus making the process
expensive.
Since Blockchain enhances trust across a business network. It’s not that you can’t trust
those who you conduct business with it’s that you don’t need to when operating on a
Blockchain network.
• Distributed: The distributed ledger is shared and updated with every incoming
transaction among the nodes connected to the Blockchain. All this is done in real
time as there is no central server controlling the data.
• Flexible: Smart Contracts which are executed based on certain conditions can be
written into the platform. Blockchain Networks can evolve in pace with business
processes.
Benefits of Blockchain:
• Tighter security: No one can tamper with Blockchain Data as it is shared among
millions of Participants. The system is safe against cybercrimes and Fraud.
• Collaboration: It permits every party to interact directly with one another while
not requiring third-party negotiation.
1. Transaction Initiation
A blockchain process begins when a user initiates a transaction. This could involve
transferring digital assets, such as cryptocurrency (e.g., Bitcoin), or executing smart
contracts. The transaction could also involve transferring information, verifying
supply chain data, or executing business logic encoded in a smart contract.
• Example: Alice wants to send 5 BTC to Bob. Alice initiates the transaction by
creating a digital message that includes the following:
• Network Nodes: These are the computers or devices that are connected to the
blockchain network. Each node has the full history of the blockchain and helps in
validating transactions.
3. Validation of Transactions
Once the transaction reaches the network, it needs to be validated to ensure that it is
legitimate. Several things are checked:
• Digital Signatures: The transaction must have a valid signature from the sender
(Alice, in this case) to prove that they have authorized the transaction.
• Double-Spending: The system must check whether Alice already spent her 5 BTC
elsewhere. This is done by comparing the current transaction with the previous
blocks in the blockchain to ensure that there are no conflicting transactions.
• Rules Compliance: The transaction must comply with the blockchain’s predefined
rules. For example, in Bitcoin, the rules include validating the amount and
ensuring that Alice has enough BTC in her wallet.
After the transaction is validated, it is grouped with other validated transactions into
a block. A block contains:
• Transaction Data: The list of all valid transactions that were broadcasted to the
network.
• Timestamp: The date and time when the block was created.
• Nonce: A random number used in the mining process to help generate the correct
hash for the block.
• Block Hash: A unique identifier generated using the cryptographic hash function
that represents the contents of the block.
• Previous Block Hash: The hash of the previous block, linking it to the current block,
thus creating a chain of blocks (hence the name blockchain).
• Nonce: The nonce is a random number that miners vary during the mining process
to create a valid hash. It is included in the block and, through a trial-and-error
process, miners find the nonce that makes the block's hash meet the required
criteria.
• Difficulty: Difficulty is a measure of how hard it is to mine a block. The higher the
difficulty, the more computations a miner needs to perform to find a valid nonce.
The difficulty is dynamically adjusted by the network to ensure that new blocks are
added at a steady rate (e.g., every 10 minutes in Bitcoin).
1. Miners take the block’s data (transactions, timestamp, previous block’s hash,
etc.).
2. They start with a nonce value (which can be any random number).
3. They hash the block data combined with the nonce using a cryptographic hash
function (such as SHA-256 in Bitcoin).
4. If the resulting hash meets the difficulty target (i.e., the hash is lower than the
target value), the block is considered valid, and the miner has successfully mined
the block.
5. The miner then broadcasts the block to the network for validation.
6. Consensus Mechanism
Once a miner finds a valid block, the network must reach consensus to add it to the
blockchain. Other nodes in the network verify the validity of the block by checking:
• The transactions within the block are valid and properly signed.
• The previous block’s hash links correctly to the newly mined block.
This process ensures that only valid blocks are added to the blockchain, and no one
can manipulate the blockchain's history. If a majority of the nodes agree that the block
is valid, the block is added to the chain.
• The block hash becomes part of the chain, linking this block to the previous one.
The previous block’s hash field in the new block is updated with the hash of the
newly added block, ensuring that all blocks are securely chained together.
8. Transaction Completion
The transaction initiated by Alice (sending 5 BTC to Bob) is now part of the blockchain.
It is considered confirmed once it is included in a valid block. As more blocks are
added on top of this block, the transaction becomes more secure and less likely to be
altered. Each additional block further solidifies the transaction, making it increasingly
difficult to reverse or tamper with the transaction.
One of the key features of blockchain technology is its decentralized nature, which is
different from traditional centralized systems (like banks or payment providers).
Because there is no central authority controlling the blockchain, the data is
distributed across all the nodes. This decentralization offers several advantages:
• Security: Since all nodes maintain copies of the blockchain, a malicious actor
cannot easily manipulate the data. To alter a block, an attacker would need to
change it on every node, which is computationally impractical.
After Alice's transaction is included in a block and added to the blockchain, the
process is complete for that transaction. As more blocks are added to the blockchain,
they continue to increase the security and immutability of all prior transactions.
This process repeats for each new transaction, ensuring that the blockchain remains
up-to-date and secure.
Understanding Nonce and Difficulty in Proof of Work (PoW)
• Nonce: A nonce is a random number that miners change during the mining
process in PoW. The goal is to find a nonce that, when combined with the other
data in the block (e.g., transactions and the previous block's hash), produces a
hash that meets the target difficulty level.
o Why Nonce? The nonce ensures that miners do not repeatedly generate
the same hash. It introduces variability into the mining process, making it
computationally challenging to find the correct nonce.
• Difficulty: In PoW, difficulty refers to how hard it is to find the correct hash for a
block. It is typically represented as a target value that the block’s hash must be
lower than. The higher the difficulty, the more computational power is required to
mine the block.
Consensus algorithm:
In a distributed network:
• Some nodes may act maliciously, trying to manipulate the system for personal
gain.
• The system must ensure that all participants agree on a common, valid state.
Bitcoin:
Bitcoin is a decentralized digital currency that allows users to send and receive payments
without relying on a central authority like a bank. Transactions are recorded on a public
ledger called the blockchain, which ensures transparency and security. Bitcoin was invented
by an anonymous person or group known as Satoshi Nakamoto in 2008.
Proof of work (PoW) is a common consensus mechanism used by the most popular
cryptocurrency networks, such as Bitcoin and Litecoin. It requires a participant node to prove
that the work done and submitted by them was valid and a large network of programs to
verify it. However, the Bitcoin consensus mechanism requires high energy consumption and
long processing times.
Consensus in bitcoin:
Bitcoin Mining:
Bitcoin mining is the process of validating and adding new transactions to the Bitcoin
blockchain. Miners use powerful computers to solve complex mathematical puzzles,
and in return, they earn Bitcoin rewards and transaction fees.
Mining Requirements:
3. Block Header Formation: Includes version number, previous block hash, Merkle
root, timestamp, nonce, and target.
4. Solving the Hash Puzzle: Miners adjust the nonce until the resulting hash meets
network difficulty requirements.
5. Block Validation & Addition: The first miner to solve the puzzle adds a new block
to the blockchain and earns Bitcoin as a reward.
• Previously, CPU-based mining was profitable, but now ASIC miners are required.
• Miners select transactions from the mempool and bundle them into a block.
• The goal is to find a hash value (SHA-256) that meets the difficulty target set by
the network.
• The first miner to find the correct hash wins the right to add the block to the
blockchain.
• If the block is valid, all nodes add it to their copy of the blockchain.
• Bitcoin follows the "longest chain rule", meaning the valid blockchain is the one
with the most accumulated Proof of Work.
• The shorter chain is abandoned, and miners switch to the longest chain.
Traditional Currency
Bitcoin
Form
Governed by a consensus
Governance mechanism in which the Purely governed by the central bank
majority rules
Capped at 21 million
Supply Fiat currency has no supply limit
bitcoin
The concepts of
decentralization,
Less secure as it can be negatively
cryptography, and
Security affected by fluctuations in government
consensus guarantee a
policies
secure network and security
of bitcoin transactions