Through Cryptographic Hashing and Consensus Mechanisms. Here's A Step
Through Cryptographic Hashing and Consensus Mechanisms. Here's A Step
The above example is the most common and simple form of a Merkle tree, i.e., Binary
Merkle Tree. There are four transactions in a block: TX1, TX2, TX3, and TX4. Here you can
see, there is a top hash which is the hash of the entire tree, known as the Root Hash, or
the Merkle Root. Each of these is repeatedly hashed, and stored in each leaf node, resulting
in Hash 0, 1, 2, and 3. Consecutive pairs of leaf nodes are then summarized in a parent node
by hashing Hash0 and Hash1, resulting in Hash01, and separately hashing Hash2 and Hash3,
resulting in Hash23. The two hashes (Hash01 and Hash23) are then hashed again to
produce the Root Hash or the Merkle Root.
UNIT -2
Merkle Root is stored in the block header. The block header is the part of the bitcoin block
which gets hash in the process of mining. It contains the hash of the last block, a Nonce, and
the Root Hash of all the transactions in the current block in a Merkle Tree. So having the
Merkle root in block header makes the transaction tamper-proof. As this Root Hash
includes the hashes of all the transactions within the block, these transactions may result in
saving the disk space.
The Merkle Tree maintains the integrity of the data. If any single detail of transactions or
order of the transaction's changes, then these changes reflected in the hash of that
transaction. This change would cascade up the Merkle Tree to the Merkle Root, changing
the value of the Merkle root and thus invalidating the block. So everyone can see that
Merkle tree allows for a quick and simple test of whether a specific transaction is included
in the set or not.
Merkle trees have three benefits:
o It provides a means to maintain the integrity and validity of data.
o It helps in saving the memory or disk space as the proofs, computationally easy and
fast.
o Their proofs and management require tiny amounts of information to be transmitted
across networks.
Proof of Work
Proof of Work (PoW) is a consensus mechanism used in blockchain networks to validate
transactions and secure the network. Here’s a simple step-by-step breakdown of how PoW
works:
Step 1: Transaction Creation
• What Happens: Users create transactions on the blockchain network. These
transactions contain details such as sender, receiver, and amount.
• Example: Alice wants to send 1 Bitcoin to Bob.
Step 2: Transaction Pool
UNIT -2
• What Happens: Created transactions are broadcast to the network and collected into
a pool of unconfirmed transactions (also known as the mempool).
• Example: Alice's transaction is added to the pool along with others waiting to be
confirmed.
Step 3: Block Formation
• What Happens: Miners (participants in the network) select transactions from the
pool to include in a new block.
• Example: A miner selects Alice’s transaction and several others to form a new block
of transactions.
Step 4: Finding a Nonce
• What Happens: To add the new block to the blockchain, miners must solve a complex
mathematical problem, which involves finding a nonce. This is a number that, when
combined with the block’s data and hashed, produces a hash that meets a certain
difficulty target.
• Example: The miner begins by trying different nonce values (starting from 0) and
hashing the block header until they find a hash that starts with a certain number of
zeros (the difficulty target).
Step 5: Hashing
• What Happens: The miner repeatedly hashes the block header with different nonce
values until they find a valid hash.
• Example: After many attempts, the miner finds that using a nonce of 456 produces a
valid hash that meets the difficulty requirement.
Step 6: Broadcasting the Block
• What Happens: Once a miner finds a valid hash, they broadcast the newly created
block to the entire network for verification.
• Example: The miner shares the block containing Alice’s transaction and the valid hash
with other nodes in the network.
Step 7: Verification by Other Nodes
• What Happens: Other nodes in the network verify the block and its hash. They check
if the hash is valid and if all included transactions are legitimate (i.e., they follow the
rules of the blockchain).
• Example: Nodes confirm that Alice’s transaction is valid and that the block's hash
meets the required criteria.
UNIT -2
Step 8: Adding the Block to the Blockchain
• What Happens: Once verified, the block is added to the blockchain, and the
transactions within it are confirmed.
• Example: Alice’s transaction is now part of the blockchain, and Bob receives the 1
Bitcoin.
Step 9: Miner Reward
• What Happens: The miner who successfully created and validated the block receives
a reward, usually in the form of newly created cryptocurrency (block reward) and
transaction fees from the transactions in the block.
• Example: The miner earns a reward of 6.25 Bitcoins (the current block reward) plus
transaction fees.
Proof of stake
Proof of Stake (PoS) is a consensus mechanism used in blockchain networks to validate
transactions and secure the network. It differs from Proof of Work (PoW) by relying on the
amount of cryptocurrency held (staked) by participants rather than computational power.
Here’s a simple step-by-step breakdown of how PoS works:
Step 1: Transaction Creation
• What Happens: Users create transactions on the blockchain, such as sending
cryptocurrency to another user.
• Example: Alice wants to send 1 Ethereum to Bob.
Step 2: Transaction Pool
• What Happens: Transactions are broadcast to the network and collected into a pool
of unconfirmed transactions.
• Example: Alice's transaction is added to this pool alongside others waiting to be
confirmed.
Step 3: Validators and Staking
• What Happens: Users (validators) must stake a certain amount of cryptocurrency to
participate in the validation process. The more coins they stake, the higher their
chances of being chosen to validate the next block.
• Example: Alice decides to stake 10 Ethereum to become a validator.
Step 4: Block Creation
• What Happens: The network selects a validator (or validators) to create the next
block based on their stake and possibly other factors like randomization.
UNIT -2
• Example: The network randomly selects Alice to create the next block because of her
stake.
Step 5: Validating Transactions
• What Happens: The chosen validator (Alice) compiles the transactions from the pool,
verifies their legitimacy, and creates a new block containing those transactions.
• Example: Alice verifies that her transaction to Bob is valid and adds it to the new
block.
Step 6: Broadcasting the Block
• What Happens: The newly created block is broadcast to the rest of the network for
verification.
• Example: Alice shares the block with other nodes in the network.
Step 7: Verification by Other Nodes
• What Happens: Other nodes verify the block and ensure all transactions within it are
legitimate. They check that the block follows network rules and that Alice’s
transaction is valid.
• Example: Nodes confirm that Alice’s transaction is legitimate and that the block
adheres to the consensus rules.
Step 8: Adding the Block to the Blockchain
• What Happens: Once verified, the new block is added to the blockchain, and all
transactions within it are confirmed.
• Example: Alice’s transaction is now permanently recorded on the blockchain, and Bob
receives the 1 Ethereum.
Step 9: Validator Reward
• What Happens: The validator (Alice) earns rewards, typically in the form of
transaction fees or newly minted cryptocurrency, for their role in creating and
validating the block.
• Example: Alice receives a small reward for successfully validating the block.
UNIT -2
Delegated Proof of Stake (DPoS) is a consensus mechanism used in blockchain networks
that aims to improve the efficiency and scalability of traditional Proof of Stake (PoS). Here’s
a simple and understandable breakdown of how DPoS works:
1. Understanding the Basics
• Delegation: In DPoS, token holders don’t directly participate in the validation of
transactions. Instead, they delegate their voting power to trusted representatives
(called delegates or witnesses) who will do the validating on their behalf.
2. How DPoS Works
Step 1: Token Ownership
• What Happens: Users own tokens or cryptocurrency on the blockchain network (like
EOS or TRON).
• Example: Alice holds 100 tokens on the DPoS blockchain.
Step 2: Voting for Delegates
• What Happens: Alice and other token holders can vote for delegates (also known as
block producers) based on their performance, reputation, and community
engagement.
• Example: Alice votes for Bob and Charlie as her chosen delegates to represent her
interests.
Step 3: Election of Delegates
• What Happens: The delegates with the most votes are elected to validate
transactions and create new blocks.
• Example: Bob and Charlie, along with a few others, are elected as delegates because
they received the most votes from token holders.
Step 4: Validation of Transactions
• What Happens: The elected delegates take turns validating transactions and creating
new blocks. They are responsible for maintaining the network and ensuring that
transactions are accurate and secure.
• Example: Bob validates transactions for a specific time period and creates the next
block in the blockchain.
Step 5: Earning Rewards
• What Happens: Delegates earn rewards (such as transaction fees or newly created
tokens) for their work in validating transactions and producing blocks.
UNIT -2
• Example: Bob receives rewards for successfully validating and adding blocks to the
blockchain.
Step 6: Distribution of Rewards
• What Happens: Some DPoS systems distribute a portion of the rewards back to the
token holders who voted for the delegates, creating an incentive for participation.
• Example: Since Alice voted for Bob, she may receive a small share of the rewards Bob
earns as a delegate.
3. Benefits of DPoS
• Efficiency: DPoS allows for faster transaction validation since only a limited number of
delegates are involved, reducing the time taken to create new blocks.
• Scalability: The system can handle more transactions as the number of validators is
limited to a manageable number of elected delegates.
• Decentralization with Representation: Token holders can influence the network by
voting for representatives while not needing to run their own nodes or spend
resources on validation.
• Incentive Alignment: Delegates are motivated to act in the best interest of token
holders to maintain their votes and stay elected.
UTXO model in blockchain
The UTXO (Unspent Transaction Output) model is a fundamental accounting model used in
some blockchains, such as Bitcoin, to manage and verify transactions. It differs from the
account-based model (used by Ethereum) by tracking the remaining balance from
transactions rather than directly tracking account balances. Here’s an easy-to-understand
breakdown of how the UTXO model works:
1. Understanding UTXO Basics
• In the UTXO model, every transaction produces outputs, which are amounts of
cryptocurrency sent to recipients.
• These outputs are unspent transaction outputs (UTXOs) until they are used as inputs
in a new transaction.
2. How the UTXO Model Works
Step 1: Starting with UTXOs
• What Happens: Every user has a set of UTXOs associated with their address. These
UTXOs represent the total funds available to them.
UNIT -2
• Example: Alice receives 2 Bitcoin from Bob and 3 Bitcoin from Carol, which are
recorded as two separate UTXOs in her wallet.
Step 2: Creating a New Transaction
• What Happens: When Alice wants to send Bitcoin, she selects one or more UTXOs as
inputs for her transaction.
• Example: Alice wants to send 4 Bitcoin to Dave. She selects her 3 BTC UTXO and 2 BTC
UTXO to use as inputs, giving her a total of 5 BTC to work with.
Step 3: Defining Outputs
• What Happens: Alice creates outputs for the transaction, which include the amount
she’s sending to Dave and any remaining change back to herself.
• Example: Alice’s transaction has:
o Output 1: 4 BTC sent to Dave.
o Output 2: 1 BTC (the remaining balance) sent back to Alice as change.
Step 4: Broadcasting the Transaction
• What Happens: Alice’s transaction is broadcast to the network, where miners verify
and record it on the blockchain. Her selected UTXOs are now considered “spent” and
can no longer be used.
• Example: The network confirms Alice’s transaction, and the 3 BTC and 2 BTC UTXOs
are marked as “spent.”
Step 5: Creating New UTXOs
• What Happens: Dave receives 4 BTC as a new UTXO, and Alice receives a new UTXO
of 1 BTC as her change.
• Example: Now, Alice has a 1 BTC UTXO, and Dave has a 4 BTC UTXO. These UTXOs can
now be used in future transactions.
3. Benefits of the UTXO Model
• Enhanced Security: Each transaction creates new UTXOs, ensuring traceability and
reducing the risk of double-spending.
• Parallel Processing: UTXOs are independent, allowing for transactions to be
processed in parallel, which can improve scalability.
• Privacy: By grouping different UTXOs into transactions, users can improve their
privacy as it’s harder to track balances directly.
UNIT -2
The Global State Model is a model used by some blockchains, such as Ethereum, to keep
track of the entire network's current state, including account balances, smart contract code,
and storage. It differs from the UTXO (Unspent Transaction Output) model used by Bitcoin,
as it tracks the state of each account directly rather than focusing on individual transaction
outputs.
Here’s a breakdown of how the Global State Model works in an easy-to-understand way:
1. Understanding the Basics of the Global State Model
• Global State: In the Global State Model, the blockchain maintains a global view of the
state of all accounts and smart contracts on the network.
• Accounts-Based: Each user and smart contract has an account that stores
information like balances, transaction history, and any associated data or code (in the
case of smart contracts).
2. How the Global State Model Works
Step 1: Account Creation
• What Happens: Every participant has an account on the blockchain. There are two
types of accounts in networks like Ethereum:
o Externally Owned Accounts (EOAs) for users, which hold balances and are
controlled by private keys.
o Smart Contract Accounts that contain code and data for smart contracts.
• Example: Alice creates an account, which will store her balance, transaction history,
and any interactions with smart contracts.
Step 2: Transaction Processing
• What Happens: Transactions in the Global State Model are processed to update
account balances or interact with smart contracts.
• Example: Alice sends 5 ETH to Bob, which triggers a change in both accounts'
balances in the global state. Alice’s balance decreases, and Bob’s balance increases by
5 ETH.
Step 3: State Updates
• What Happens: Every time a transaction is processed, the global state is updated to
reflect the new account balances, contract data, or any other changes.
• Example: Alice also interacts with a smart contract to deposit 3 ETH into a
decentralized finance (DeFi) application. The global state updates to show that the
DeFi smart contract account now holds the 3 ETH she deposited.
UNIT -2
Step 4: Storage and Execution in Smart Contracts
• What Happens: Smart contracts in the Global State Model can store data, execute
code, and interact with other accounts based on the transactions they receive. The
state of each smart contract is also tracked as part of the global state.
• Example: The DeFi smart contract has stored data about Alice’s deposit, and this
information is part of the blockchain’s global state.
Step 5: Keeping Track of the Global State
• What Happens: Every block in the blockchain contains a snapshot of the global state.
This snapshot records all balances, data, and contract states up to that point, allowing
the network to validate future transactions based on the current state.
• Example: After Alice’s transactions are processed, a new block is created that records
the updated state, including changes to both Alice’s and Bob’s accounts and the smart
contract.
3. Benefits of the Global State Model
• Direct Account Balances: Since each account has a direct balance, it’s easier to
manage funds without tracking multiple UTXOs as in Bitcoin.
• Smart Contract Functionality: This model allows for complex smart contract
functionality and interactions, essential for platforms like Ethereum that support
decentralized applications (dApps).
• Efficient State Tracking: The model tracks the current state of all accounts in one
place, making it easier to execute and verify transactions quickly.
Wallets
In the blockchain world, wallets are essential tools that allow users to store, send, and
receive cryptocurrencies securely. Blockchain wallets manage the private and public keys for
users, enabling secure access and transactions on the blockchain. Wallets can range from
software applications to hardware devices, each with unique security and usability features.
Here’s an easy breakdown of blockchain wallets:
1. Understanding How Blockchain Wallets Work
• Private Key: A secret code that allows access to your wallet and funds. Think of it as a
password; whoever has the private key can control the cryptocurrency in the wallet.
• Public Key: A code derived from the private key that can be shared publicly. It’s often
linked to a wallet address and allows others to send you funds.
• Wallet Address: An alphanumeric identifier derived from the public key. It’s similar to
an email address for receiving cryptocurrency.
UNIT -2