0% found this document useful (0 votes)
19 views43 pages

BC Module 4

BLOCK CHAIN 4

Uploaded by

Veon Almeida
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views43 pages

BC Module 4

BLOCK CHAIN 4

Uploaded by

Veon Almeida
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Module 4

Public Blockchain
Topics to Cover WILL BE DONE IN PRACTICAL

1. Type of Test networks used in Ethereum


1. Introduction to Public Blockchain
2. Transferring Ethers using Metamask
2. Ethereum and its Components
3. Mist Wallet
3. Mining in Ethereum
4. Ethereum Frameworks
4. Ethereum Virtual Machine
5. Case study of Ganache for Ethereum
5. Transactions, Accounts
Blockchain.
6. Architecture & Workflow
6. Exploring etherscan.io & ether block
7. Comparison between Bitcoin &
structure.
Ethereum
Introduction to Public Blockchain
● Public Blockchain is A self-governed, purely decentralized and autonomous digital public
ledger.

● A public blockchain does not have restrictions. Anyone with an internet connection can
get access to the network and start validating blocks and sending transactions. Typically,
such networks tend to offer some kind of incentive for users who validate the blocks.

● Anyhow, this network tends to use Proof of Work or Proof of Stake consensus algorithms
for validating the transactions.

● It is completely decentralized, no single organization controls the ecosystem.

● A public blockchain surpassed the necessity of a third party. The system has a natural
flow of its own – just like a flowing river. No one controls the flow path, yet everyone uses
it.
Characteristics of Public Blockchain
● Every node has access to read and write on the ledger

● Anyone can download and add nodes to the system

● The technology is fully decentralized in nature

● It offers anonymity, which means no one can track your transactions back to you

● It’s a bit slower compared to the private blockchain

Bitcoin, Ethereum, and Litecoin etc.

Ethereum is actually the most popular public blockchain at the moment. In


reality, Ethereum took the concept of a public blockchain to a whole new level. At present, there are
so many applications based on this blockchain.
All About - Ethereum
● Ethereum is a blockchain-based computing platform that enables developers to
build and deploy decentralized applications—meaning not run by a centralized
authority.
All About - Ethereum
● Ethereum is a blockchain-based computing platform that enables developers to
build and deploy decentralized applications—meaning not run by a centralized
authority.

● Ethereum is a decentralized blockchain platform that establishes a peer-to-peer


network that securely executes and verifies application code, called smart
contracts.

● Smart contracts allow participants to transact with each other without a trusted
central authority.

● The Ethereum network is fueled by its own cryptocurrency called ‘ether’.

Smart contracts are applications that run exactly as programmed without any possibility
of downtime, censorship, fraud or third party interference
All About - Ethereum
● Transaction records are immutable, verifiable, and securely distributed across the
network, giving participants full ownership and visibility into transaction data.

● Transactions are sent from and received by user-created Ethereum accounts.

● A sender must sign transactions and spend Ether (Ethereum's native


cryptocurrency), as a cost of processing transactions on the network.

● Ethereum is often called Blockchain 2.0 since it proved the potential of blockchain
technology beyond the financial sector.

● The consensus mechanism used in Ethereum is Proof of Stakes(PoS), which is


more energy efficient when compared to that used in the Bitcoin network,
Ethereum Features
● Ether: This is Ethereum’s cryptocurrency. It is the only acceptable form of payment for
transaction fees on the Ethereum network.

● Smart contracts: Ethereum allows the development and deployment of these types of
contracts. Smart contracts are created mainly using a programming language called
solidity.

● Ethereum Virtual Machine: Ethereum provides the underlying technology—the architecture


and the software—that understands smart contracts and allows you to interact with it.
Ethereum Features
● Decentralized applications (Dapps): A decentralized application is called a Dapp (also
spelled DAPP, App, or DApp) for short. Dapp has its backend code running on a
decentralized peer-to-peer network. It can have a frontend and user interface written in
any language to make calls and query data from its backend. They operate on Ethereum
and perform the same function irrespective of the environment in which they get executed.

● Decentralized autonomous organizations (DAOs): It is a decentralized organization that


works in a democratic and decentralized fashion. DAO relies on smart contracts for
decision-making or decentralized voting systems within the organization.
Ethereum and its Components
1. Nodes : There are two types of nodes in an Ethereum network. They are as follows.

● Mining Node – These nodes are responsible for writing all the transactions that
have occurred in the Ethereum network in the block.

● Ethereum Virtual Machine Node – These are the nodes in the Ethereum
network in which Smart Contracts (it is a type of contract between supporter and
developer in which there are a set of rules based on which both the parties agree
to interact with each other. The agreement will be automatically executed when
the pre-defined rules are met.) are implemented. By default, this node utilizes a
30303 port number for the purpose of communication among themselves.
Ethereum and its Components
1. Nodes : There are two types of nodes in an Ethereum network. They are as follows.
● Mining Node – These nodes are responsible for writing all the transactions that have
occurred in the Ethereum network in the block.
● Ethereum Virtual Machine Node – These are the nodes in the Ethereum network in
which Smart Contracts are implemented. By default, this node utilizes a 30303 port
number for the purpose of communication among themselves.
Ethereum and its Components
2. Ether :
✓ Ether is a type of cryptocurrency used in the Ethereum network just like a bitcoin is
used in a blockchain network. It is a peer-to-peer currency, similar to Bitcoin. It tracks
and promotes each transaction in the network.
✓ It is the second-largest cryptocurrency in the world. The first one is Bitcoin. Other
cryptocurrencies can be used to get ether tokens, but vice versa is not true.
✓ It is used in the Ethereum algorithm as an incentive for miners who connect blocks to
the blockchain using a proof-of-work method.
✓ It is the only currency that can be used to pay transaction costs, which go to miners as
well. The block reward, as well as transaction fees, provide miners with an
opportunity to keep the blockchain rising.
Ethereum and its Components
3. Gas :
✓ Gas is an internal currency of the Ethereum network. We need gas to run applications
on the Ethereum network, much as we need gas to run a vehicle.
✓ Gas is a unit of measurement on the Ethereum network for the computing
power used to execute a smart contract or a transaction.

4. Ethereum Accounts: There are two types of Ethereum accounts. They are as
follows.
Externally owned account – These accounts are used to store transactions
Contract account – As the name itself suggests, these accounts store the details of
Smart Contracts.
Properties of EOAs and CAs
EXTERNALLY OWNED ACCOUNT CONTRACT ACCOUNT
• They have a state. They have a state.
They are associated with a human user, They are not intrinsically associated with any user or actor
hence are also called user accounts. on the blockchain.

• EOAs have an ether balance. CAs have an ether balance.


• They are capable of sending They have associated code that is kept in memory/storage
transactions. on the blockchain. They have access to storage.
• They have no associated code • They can get triggered and execute code in response to a
transaction or a message from other contracts.
They are controlled by private keys. CAs cannot start transaction messages.

• EOAs cannot initiate a call message. CAs can initiate a call message.

Accounts contain a key-value store. CAs contain a key-value store.


EOAs can initiate transaction messages. CAs' addresses are generated when they are deployed.
This address of the contract is used to identify its location
on the blockchain.
Ethereum and its Components
5. Nonce :
✓ The nonce is a number that is incremented by one every time a transaction is sent by
the sender.
✓ It must be equal to the number of transactions sent and is used as a unique identifier
for the transaction.
✓ A nonce value can only be used once. This is used for replay protection on the
network.
Mining in Ethereum https://ethereum.org/en/developers/docs/consensus-mechanisms/pow/mining/

Mining is the process of creating a block of transactions to be added to the Ethereum


blockchain in Ethereum's now-deprecated proof-of-work architecture.
Ethereum mining was a way to secure the network by creating, verifying, publishing and
propagating blocks in the blockchain.
Mining ether = Securing the Network

Ethereum miners - computers running software - used their time and computation
power to process transactions and produce blocks prior to the transition to proof-of-stake .

Proof-of-work is no longer underlying Ethereum's consensus mechanism,


meaning mining has been switched off.

Instead, Ethereum is secured by validators who stake ETH


WHY DO MINERS EXIST?
● In decentralized systems like Ethereum, we need to ensure that everyone agrees on the
order of transactions. Miners helped this happen by solving computationally difficult
puzzles to produce blocks, securing the network from attacks.

● Miners had to purchase dedicated computer hardware, and have access to inexpensive
energy sources. The average computer was unlikely to earn enough block rewards to
cover the associated costs of mining.

Cost of mining
• Potential costs of the hardware necessary to build and maintain a mining rig
• Electrical cost of powering the mining rig
• If you were mining in a pool, these pools typically charged a flat % fee of each block generated by the pool
• Potential cost of equipment to support mining rig (ventilation, energy monitoring, electrical wiring, etc.)
HOW ETHEREUM TRANSACTIONS WERE
1. A user writes and signs a transactionMINED
request with the private key of some account.

2. The user broadcasts the transaction request to the entire Ethereum network from
some node.

3. Upon hearing about the new transaction request, each node in the Ethereum
network adds the request to their local mempool, (a list of all transaction requests they’ve
heard about that have not yet been committed to the blockchain in a block).
HOW ETHEREUM TRANSACTIONS WERE MINED
4. At some point, a mining node aggregates several dozen or hundred transaction
requests into a potential block, in a way that maximizes the transaction fees they
earn while still staying under the block gas limit. The mining node then:
1. Verifies the validity of each transaction request (i.e. no one is trying to transfer ether out of an
account they haven’t produced a signature for, the request is not malformed, etc.), and then executes
the code of the request, altering the state of their local copy of the EVM. The miner awards the
transaction fee for each such transaction request to their own account.

2. Begins the process of producing the proof-of-work “certificate of legitimacy” for the potential
block, once all transaction requests in the block have been verified and executed on the local EVM
copy.
HOW ETHEREUM TRANSACTIONS WERE MINED
5. Eventually, a miner will finish producing a certificate for a block which includes
our specific transaction request. The miner then broadcasts the completed block,
which includes the certificate and a checksum of the claimed new EVM state.

6. Other nodes hear about the new block. They verify the certificate, execute all
transactions on the block themselves and verify that the checksum of their new
EVM state after the execution of all transactions matches the checksum of the state
claimed by the miner’s block. Only then do these nodes append this block to the
tail of their blockchain, and accept the new EVM state as the canonical state.

7. Each node removes all transactions in the new block from their local mempool of
unfulfilled transaction requests.
HOW ETHEREUM TRANSACTIONS WERE MINED

Every transaction is mined once, but executed and verified by every participant in the
process of advancing the canonical EVM state.

This highlights one of the central mantras of blockchain: Don’t trust, verify.
Transactions
● A transaction in Ethereum is a data packet that is digitally signed using a private key.
● It contains the instructions that, when completed, that transaction will either result in
a ME S S A G E C A LL OR C ONTR A C T C R E A TION.
● Thus, Transactions can be divided into two types based on the output they produce:

○ Mes s age C all Trans actions : This transaction simply produces a message call
that is used to pass messages from one CA to another.

○ C ontract C reation Trans actions : As the name suggests, these transactions


result in the creation of a new CA. This means that when this transaction is executed
successfully, it creates an account with the associated code.
Transactions
● Both of these transactions are composed of some standard fields, which are described
as follows:

○ Nonce: The nonce is a number that is incremented by one every time a transaction is sent
by the sender. It must be equal to the number of transactions sent and is used as a unique
identifier for the transaction. A nonce value can only be used once. This is used for replay
protection on the network.

○ G as price: The gas price field represents the amount of Wei required to execute the
transaction. In other words, this is the amount of Wei you are willing to pay for this
transaction. This is charged per unit of gas for all computation costs incurred as a result of
the execution of this transaction.
Transactions
○ G as limit: The gas limit field contains the value that represents the maximum amount of gas
that can be consumed to execute the transaction. This is the fee amount, in ether, that a user (for
example, the sender of the transaction) is willing to pay for computation

○ To: As the name suggests, the To field is a value that represents the address of the recipient of
the transaction. This is a 20 byte value.

○ Value: Value represents the total number of Wei to be transferred to the recipient; in the case of
a CA, this represents the balance that the contract will hold.
Transactions
○ Signature: The signature is composed of three fields, namely V, R, and S. These values
represent the digital signature (R, S) and some information that can be used to recover
the public key (V). Also, the sender of the transaction can also be determined from
these values. To sign a transaction, the ECDSASIGN function is used, which takes the
message to be signed and the private key as an input and produces V, a single-byte
value; R, a 32-byte value; and S, another 32-byte value. The equation is as follows:
EC DS A S IG N (Mes s age, Private Key) = (V, R, S)
Transactions
○ Init: The Init field is used only in transactions that are intended to create contracts, that
is, contract creation transactions. This represents a byte array of unlimited length that
specifies the EVM code to be used in the account initialization process. The code
contained in this field is executed only once when the account is created for the first
time, it (init) gets destroyed immediately after that.

○ Data: If the transaction is a message call, then the Data field is used instead of init, and
represents the input data of the message call. It is also unlimited in size and is organized
as a byte array.
Transactions
○ The structure of a transaction is visualized in the following diagram,
Where a transaction is a tuple of the fields, which is then included in a TR ANS A CTION TRIE (a
modified Merkle-Patricia tree (MPT)) composed of the transactions to be included. Finally, the root
node of the transaction trie is hashed using a Keccak 256-bit algorithm and is included in the
block header along with a list of transactions in the block.
Ethereum Virtual Machine
● The EVM is a simple Stack-based Execution machine that runs bytecode
instructions to transform the system state from one state to another.

● The word size of the EVM is set to 256-bit. The stack size is limited to 1,024 elements
and is based on the Last In, First Out (LIFO) queue.

● The EVM is a Turing-complete Machine but is limited by the amount of gas that is
required to run any instruction.
Ethereum Virtual Machine
● The EVM also supports Exception Handling. Thus when exceptions occur, such as not
having enough gas or providing invalid instructions, in which case the machine would
immediately halt and return the error to the executing agent.

● The EVM is an entirely isolated and sandboxed runtime environment. The code
that runs on the EVM does not have access to any external resources such as a network
or filesystem. This results in increased security, deterministic execution, and allows
untrusted code (code that can be run by anyone) to be executed on Ethereum
blockchain.
Ethereum Virtual Machine
There are three main types of storage available for contracts and the EVM:

• Memory: The first type is called memory or volatile memory, which is a word-addressed
byte array. When a contract finishes its code execution, the memory is cleared. It is akin to
the concept of RAM. write operations to the memory can be of 8 or 256 bits, whereas read
operations are limited to 256-bit words. Memory is unlimited but constrained by gas fee
requirements.

• Storage: The other type is called storage, which is a key-value store and is permanently
persisted on the blockchain. Keys and values are each 256 bits wide. It is allocated to all
accounts on the blockchain. As a security measure, storage is only accessible by its own
respective CAs. It can be thought of as hard disk storage.
Ethereum Virtual Machine
There are three main types of storage available for contracts and the EVM:

Stack: EVM is a stack-based machine, and thus performs all computations in a data area
called the stack. All in-memory values are also stored in the stack. It has a maximum depth of
1024 elements and supports the word size of 256 bits.
Ethereum Virtual Machine
● The following diagram shows the design of the EVM where the virtual ROM stores the
program code that is copied into the main memory using the CODECOPY instruction.
● The main memory is then read by the EVM by referring to the program counter and
executes instructions step by step.
● The program counter and EVM stack are updated accordingly with each instruction
execution:
Ethereum Virtual Machine
The machine state
✓ The machine state is also maintained internally, and updated after each execution cycle
of the EVM.
✓ An iterator function runs in the EVM, which outputs the results of a single cycle of the
state machine.
✓ The machine state is a tuple that consists of the following elements:
• Available gas
• The program counter, which is a positive integer of up to 256
• The contents of the memory (a series of zeroes of size 2256)
• The active number of words in memory .
(counting continuously from position 0)
• The contents of the stack
The iterator function
● The iterator function mentioned earlier performs various vital functions that are used to
set the next state of the machine and eventually the world state. These functions include
the following:
• It fetches the next instruction from a byte array where the machine code is stored in
the execution environment.
• It adds/removes (PUSH/POP) items from the stack accordingly.
• Gas is reduced according to the gas cost of the instructions/opcodes. It increments
the Program Counter (PC).

● The EVM is also able to halt in normal conditions if STOP, SUICIDE, or RETURN opcodes are
encountered during the execution cycle.
Ethereum Architecture
Ethereum and its Components
The Ethereum blockchain consists of various components.

1. At the core, there is the Ethereum blockchain running on the peer-to-peer Ethereum
network.

2. Secondly, there's an Ethereum client (usually Geth) that runs on the nodes and
connects to the peer-to-peer Ethereum network from where blockchain is
downloaded and stored locally. It provides various functions, such as mining and
account management. The local copy of the blockchain is synchronized regularly
with the network.

3. Another component is the web3.js library that allows interaction with the geth client
via the Remote Procedure Call (RPC) interface.
● From your web or wallet application, you can use the web3 object provided by the web3.js library to
communicate with the Ethereum network. It works with any Ethereum client.

● Behind the scenes, it connects to a local or remote Ethereum node and makes RPC calls. In some
sense, this is like the old client-server model, where DApps are the client, and the entire Ethereum
network as a whole, acts as a server.

● To DApps, the Ethereum network is just like a giant world computer, assembled together with
thousands of computing devices throughout the internet. Once you connect to the network, you could
connect to any node in the decentralized network, as shown in the following diagram:
Beyond smart contracts and the EVM, an Ethereum client provides all blockchain components
to maintain world state and state transitions in the blockchain network, including the following:
• Managing transaction and state transition with the Ethereum blockchain
• Maintaining world state and account state
• Managing P2P communication Block finalization with mining
• Managing transaction pool
• Managing cryptoassets, gas, ether, and tokens
What is DApp
● A DApp is an application or service that runs on a blockchain network and enables direct
interaction between consumers and providers, for example, connecting buyers and sellers in a
decentralized marketplace.

● Similar to the centralized application architecture, a DApp usually involves a decentralized


backend that runs on the blockchain network and a centralized frontend that allows end users
to access their wallets and make a transaction.

● The below diagram shows the differentiation between centralized and decentralized
applications:
What is DApp
● Although there are many different viewpoints, it is a common belief that a DApp must be
completely decentralized and open source. It must run on a blockchain network and use and
generate cryptographic tokens. Most DApps often start with a whitepaper and a working
prototype.

● Instead, as a DApp, Ethereum provides a platform for anyone to write smart contracts and
decentralized applications based on your business needs and value propositions. It is intended
as the world computer for the decentralized world. As such, Ethereum provides four
decentralized computing facilities, along with a large list of development and testing tools,
which make it very easy to develop and deploy DApps on to the Ethereum blockchain.

● The four decentralized computing facilities are as follows:


• Ethereum blockchain for decentralized state
• Smart contracts for decentralized computing
• Swarm and IPFS for decentralized storage
• Whispers for P2P messaging
Comparison between Bitcoin & Ethereum

● https://www.geeksforgee
ks.org/difference-
between-bitcoin-and-
ethereum/
REFERENCES

● https://aws.amazon.com/blockchain/what-is-ethereum/
● https://cointelegraph.com/learn/what-is-ethereum-a-beginners-guide-to-eth-
cryptocurrency
● https://consensys.net/knowledge-base/ethereum/
● https://www.slideshare.net/DanielChan57/ethereum-in-a-nutshell - Important
● https://www.geeksforgeeks.org/components-of-ethereum-network/ -
Components
● https://iq.opengenus.org/components-of-ethereum/
● https://ethereum.org/en/smart-contracts/ - Smart Contracts

You might also like