Unit 3 - Part 1
Unit 3 - Part 1
UNIT-III
ETHEREUM
Ethereum is a decentralized, open-source blockchain platform that enables developers to build and deploy
decentralized applications (DApps) and smart contracts. It was proposed by Vitalik Buterin in late 2013 and went
live on July 30, 2015. Ethereum aims to provide a platform for decentralized applications that is more flexible and
programmable than Bitcoin's blockchain.
With its robust features, active community, and ongoing development efforts, Ethereum continues to play a pivotal
role in shaping the future of decentralized finance, digital asset management, decentralized governance, and other
blockchain-enabled applications.
UNIT-III
CONSENSUS MECHANISMS
The term 'consensus mechanism' is often used colloquially to refer to 'proof-of-stake', 'proof-of-work' or 'proof-of-
authority' protocols. However, these are just components in consensus mechanisms that protect against Sybil attacks.
Consensus mechanisms are the complete stack of ideas, protocols and incentives that enable a distributed set of nodes
to agree on the state of a blockchain.
WHAT IS CONSENSUS?
By consensus, we mean that a general agreement has been reached. Consider a group of people going to the cinema.
If there is no disagreement on a proposed choice of film, then a consensus is achieved. If there is disagreement, the
group must have the means to decide which film to see. In extreme cases, the group will eventually split.
In regard to the Ethereum blockchain, the process is formalized, and reaching consensus means that at least 66% of
the nodes on the network agree on the global state of the network.
UNIT-III
Ethereum uses a proof-of-stake-based consensus mechanism that derives its crypto-economic security from a set of
rewards and penalties applied to capital locked by stakers. This incentive structure encourages individual stakers to
operate honest validators, punishes those who don't, and creates an extremely high cost to attack the network.
Then, there is a protocol that governs how honest validators are selected to propose or validate blocks, process
transactions and vote for their view of the head of the chain. In the rare situations where multiple blocks are in the
same position near the head of the chain, there is a fork-choice mechanism that selects blocks that make up the
'heaviest' chain, measured by the number of validators that voted for the blocks weighted by their staked ether balance.
Some concepts are important to consensus that are not explicitly defined in code, such as the additional security offered
by potential out-of-band social coordination as a last line of defense against attacks on the network. These components
together form the consensus mechanism.
1. PROOF-OF-WORK (POW)
The Ethereum network began by using a consensus mechanism that involved Proof-of-work (PoW). This allowed
the nodes of the Ethereum network to agree on the state of all information recorded on the Ethereum blockchain and
prevented certain kinds of economic attacks. However, Ethereum switched off proof-of-work in 2022 and started
using proof-of-stake instead.
Proof-of-work has now been deprecated. Ethereum no longer uses proof-of-work as part of its consensus
mechanism. Instead, it uses proof-of-stake.
UNIT-III
When racing to create a block, a miner repeatedly put a dataset, that could only be obtained by downloading and
running the full chain (as a miner does), through a mathematical function. The dataset was used to generate a mixHash
below a target that is dictated by the block difficulty. The best way to do this is through trial and error.
The difficulty determined the target for the hash. The lower the target, the smaller the set of valid hashes. Once
generated, this was incredibly easy for other miners and clients to verify. Even if one transaction were to change, the
hash would be completely different, signalling fraud.
Hashing makes fraud easy to spot. But proof-of-work as a process was also a big deterrent to attacking the chain.
The objective of proof-of-work was to extend the chain. The longest chain was most believable as the valid one
because it had the most computational work done to generate it. Within Ethereum's PoW system, it was nearly
impossible to create new blocks that erase transactions, create fake ones, or maintain a second chain. That's because a
malicious miner would have needed to always solve the block nonce faster than everyone else.
To consistently create malicious yet valid blocks, a malicious miner would have needed over 51% of the network
mining power to beat everyone else. That amount of "work" requires a lot of expensive computing power and the
energy spent might even have outweighed the gains made in an attack.
FINALITY
A transaction has "finality" on Ethereum when it's part of a block that can't change.
Because miners worked in a decentralized way, two valid blocks could be mined at the same time. This creates a
temporary fork. Eventually, one of these chains became the accepted chain after subsequent blocks were mined and
added to it, making it longer.
To complicate things further, transactions rejected on the temporary fork may not have been included in the accepted
chain. This means it could get reversed. So finality refers to the time you should wait before considering a transaction
irreversible. Under the previous proof-of-work Ethereum, the more blocks were mined on top of a specific block N,
the higher confidence that the transactions in N were successful and would not be reverted. Now, with proof-of-stake,
finalization is an explicit, rather than probabilistic, property of a block.
2. PROOF-OF-STAKE (POS)
Proof-of-stake (PoS) underlies Ethereum's consensus mechanism. Ethereum switched on its proof-of-stake
mechanism in 2022 because it is more secure, less energy-intensive, and better for implementing new scaling solutions
compared to the previous proof-of-work architecture.
UNIT-III
VALIDATORS
To participate as a validator, a user must deposit 32 ETH into the deposit contract and run three separate pieces of
software: an execution client, a consensus client, and a validator client. On depositing their ETH, the user joins an
activation queue that limits the rate of new validators joining the network. Once activated, validators receive new
blocks from peers on the Ethereum network. The transactions delivered in the block are re-executed to check that the
proposed changes to Ethereum's state are valid, and the block signature is checked. The validator then sends a vote
(called an attestation) in favor of that block across the network.
Whereas under proof-of-work, the timing of blocks is determined by the mining difficulty, in proof-of-stake, the tempo
is fixed. Time in proof-of-stake Ethereum is divided into slots (12 seconds) and epochs (32 slots). One validator is
randomly selected to be a block proposer in every slot. This validator is responsible for creating a new block and
sending it out to other nodes on the network. Also in every slot, a committee of validators is randomly chosen, whose
votes are used to determine the validity of the block being proposed. Dividing the validator set up into committees is
important for keeping the network load manageable. Committees divide up the validator set so that every active
validator attests in every epoch, but not in every slot.
FINALITY
A transaction has "finality" in distributed networks when it is part of a block that can't change without a large amount
of ETH getting burned. On proof-of-stake Ethereum, this is managed using "checkpoint" blocks. The first block in
each epoch is a checkpoint. Validators vote for pairs of checkpoints that it considers to be valid. If a pair of checkpoints
attracts votes representing at least two-thirds of the total staked ETH, the checkpoints are upgraded. The more recent
of the two (target) becomes "justified". The earlier of the two is already justified because it was the "target" in the
previous epoch. Now it is upgraded to "finalized".
To revert a finalized block, an attacker would commit to losing at least one-third of the total supply of staked ETH.
Since finality requires a two-thirds majority, an attacker could prevent the network from reaching finality by voting
with one-third of the total stake. There is a mechanism to defend against this: the inactivity leak. This activates
whenever the chain fails to finalize for more than four epochs. The inactivity leak bleeds away the staked ETH from
validators voting against the majority, allowing the majority to regain a two-thirds majority and finalize the chain.
UNIT-III
SMART CONTRACTS
Smart contracts are self-executing contracts with the terms of the agreement directly written into code. They run on a
blockchain network and automatically execute transactions and enforce agreements when predefined conditions are
met. Smart contracts enable trustless and decentralized execution of agreements, eliminating the need for
intermediaries and enhancing security and efficiency in various applications.
UNIT-III
3. Result and Confirmation: Once the contract's code is executed and its outcome verified by the network, the
transaction is confirmed and added to a block on the blockchain. The transaction, along with the contract's
execution result, becomes a permanent part of the blockchain's immutable ledger, providing transparency and
auditability of the contract's execution.
The working of smart contracts involves several steps, from creation to execution on a blockchain network.
Smart contracts operate as self-executing agreements deployed on blockchain networks, enabling automated and
trustless execution of transactions and agreements. They follow a predefined lifecycle, from creation and deployment
to interaction, execution, and eventual termination or settlement. Smart contracts leverage the security, transparency,
and immutability of blockchain technology to provide reliable and efficient execution of agreements across various
industries and applications.
UNIT-III
UNIT-III
METAMASK
MetaMask is a cryptocurrency wallet and browser extension that enables users to interact with decentralized
applications (DApps) and blockchain networks directly from their web browsers. It serves as a digital wallet for storing
cryptocurrencies, managing assets, and facilitating transactions on blockchain platforms, primarily Ethereum.
MetaMask provides users with a user-friendly interface accessible via a browser toolbar icon. From there, users can
access their wallet, view transaction history, manage account settings, and interact with DApps seamlessly without the
need for additional software or tools.
MetaMask Setup
Setting up MetaMask involves several steps, including installation, account creation, and configuration.
UNIT-III
• Seed Phrase Backup: MetaMask will prompt users to verify their seed phrase by entering it in the correct
order. Users must carefully enter the words to ensure accuracy.
• Network Selection: MetaMask supports multiple Ethereum networks, including the Ethereum Mainnet and
various testnets. Users can select the desired network from the dropdown menu in the MetaMask interface.
4. Additional Settings:
• Privacy Settings: Users can configure privacy settings in MetaMask to control data sharing and permissions
for accessing wallet data and interacting with decentralized applications (DApps).
• Token Management: MetaMask allows users to manage Ethereum-based tokens by adding custom tokens
to their wallets, viewing token balances, and sending or receiving tokens.
• Customization: Users can customize MetaMask settings, such as language preferences, currency display
options, and transaction preferences, to suit their preferences and needs.
5. Backup and Recovery:
• Backup Seed Phrase: MetaMask emphasizes the importance of backing up the mnemonic seed phrase
generated during wallet creation. Users should securely store the seed phrase in multiple locations to ensure
they can recover their wallet in case of loss or device failure.
• Wallet Recovery: In case of wallet loss or device change, users can restore their MetaMask wallet using the
mnemonic seed phrase. They need to install MetaMask on a new device and select the option to restore a
wallet using the seed phrase.
6. Security Measures:
• Security Best Practices: MetaMask encourages users to follow security best practices, such as enabling two-
factor authentication (2FA), using strong and unique passwords, and keeping their devices and browsers up
to date.
• Phishing Protection: MetaMask provides phishing protection features to warn users about suspicious
websites or DApps that may attempt to steal their cryptocurrency or sensitive information.
ETHEREUM ACCOUNTS
Ethereum accounts play a crucial role in the Ethereum blockchain ecosystem, serving as the primary means for users
to interact with the network, store funds, and execute transactions. Ethereum accounts are essential components of the
Ethereum blockchain ecosystem, enabling users to interact with the network, store funds, and execute transactions
securely and autonomously. Understanding the structure and functionality of Ethereum accounts is crucial for
participating in the Ethereum ecosystem and leveraging its capabilities for decentralized finance, decentralized
applications, and other blockchain-based solutions.
UNIT-III
algorithms. They serve as the destination for sending Ether and tokens and as identifiers for interacting with
contracts.
• Private Key: For externally owned accounts (EOAs), the private key is used to control and manage the
account. Private keys are randomly generated 256-bit numbers and are mathematically linked to the account's
public key and address. Private keys must be kept secure and should never be shared or exposed.
• Balance: Ethereum accounts maintain a balance, which represents the amount of Ether and tokens held by
the account. The balance is recorded on the Ethereum blockchain and can be queried by anyone using the
account's address.
3. Account Management and Transactions:
• Transactions: Ethereum accounts can send and receive transactions on the Ethereum blockchain.
Transactions involve transferring Ether or tokens between accounts, interacting with smart contracts, or
executing other operations on the Ethereum network.
• Digital Signatures: Transactions sent from EOAs require digital signatures generated using the account's
private key. Digital signatures provide cryptographic proof of ownership and authorization for the transaction.
Contract accounts execute transactions based on the rules defined in the associated smart contract code.
• Nonce: Each Ethereum account has a nonce, which is a unique sequential number assigned to each transaction
sent from the account. The nonce prevents replay attacks and ensures the order and integrity of transactions
from the account.
4. Account Interaction:
• Sending Transactions: Users can send transactions from their Ethereum accounts using wallet software or
browser extensions like MetaMask. Transactions involve specifying the recipient address, amount of Ether
or tokens to send, and optional data payload.
• Interacting with Contracts: Ethereum accounts can interact with smart contracts deployed on the Ethereum
blockchain. Interactions include calling functions defined in the smart contract code, sending data to the
contract, and executing specific actions based on the contract's logic.
5. Security Considerations:
• Private Key Security: Securing the private key is critical for protecting Ethereum accounts from
unauthorized access and theft. Users should store private keys securely, preferably offline, and avoid sharing
them or exposing them to potential risks.
• Phishing and Scams: Users should be cautious of phishing attacks and scams targeting Ethereum accounts.
They should verify the authenticity of websites, applications, and messages before sharing sensitive
information or executing transactions.
RECEIVING ETHER
Receiving Ether (ETH) involves obtaining funds sent to your Ethereum account from another account or address.
Receiving Ether involves generating an Ethereum address, sharing it with the sender, and confirming the receipt of
funds in your Ethereum account after the sender initiates the transaction. Understanding the process of receiving Ether
is essential for effectively managing your Ethereum holdings and participating in cryptocurrency transactions on the
Ethereum network.
UNIT-III