0% found this document useful (0 votes)
15 views62 pages

Unit - IV

The document provides a comprehensive overview of Ethereum, highlighting its Turing-complete language for smart contracts and decentralized applications, contrasting it with Bitcoin's limited scripting capabilities. It details the structure of Ethereum accounts, including Externally Owned Accounts (EOAs) and Contract Accounts (CAs), as well as the transaction process, validation, and execution within the Ethereum Virtual Machine (EVM). Additionally, it covers aspects of gas fees, smart contract functionality, and the Ethereum mining process, including various mining types and pool considerations.

Uploaded by

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

Unit - IV

The document provides a comprehensive overview of Ethereum, highlighting its Turing-complete language for smart contracts and decentralized applications, contrasting it with Bitcoin's limited scripting capabilities. It details the structure of Ethereum accounts, including Externally Owned Accounts (EOAs) and Contract Accounts (CAs), as well as the transaction process, validation, and execution within the Ethereum Virtual Machine (EVM). Additionally, it covers aspects of gas fees, smart contract functionality, and the Ethereum mining process, including various mining types and pool considerations.

Uploaded by

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

UNIT – IV

ETHEREUM
ETHEREUM

 Turing-complete language that allows the development of arbitrary


programs (smart contracts) for blockchain and decentralized
applications.

 This concept is in contrast to Bitcoin, where the scripting language


is limited in nature and allows necessary operations only.

 Ether is the native cryptocurrency


WHY USE ETHEREUM
BITCOIN VS ETHEREUM
ELEMENTS OF ETHEREUM

 Keys and addresses


 Accounts

 Transactions and messages

 Ether cryptocurrency/tokens

 The EVM

 Smart contracts
KEYS AND ADDRESSES
 The private key is generated randomly and is kept secret
 public key is derived from the private key.
 Addresses are derived from the public keys which are a 20-
bytes code used to identify accounts.
 The process of key generation and address derivation is
described here:

1. Private key is randomly chosen (256 bits positive integer)


under the rules defined by elliptic curve specification.

2. Public key is then derived from this private key using ECDSA
recovery function.

3. An address is derived from the public key which is the right


most 160 bits of the Keccak hash of the public key.
ACCOUNTS

 Externally Owned Accounts (EOAs)


 Contract Accounts (CAs)
EXTERNALLY OWNED ACCOUNTS (EOAS)
 controlled by ECDSA signing key pair (pk,sk).
 An individual makes an account on Ethereum and a public-
private key pair is generated for the account. The account is not
identified by the person’s name or any personal information.
 Public key’s hash acts as the account number to which Ether can be
sent.
 This account also has some other state fields:

Nonce: number of transactions initiated by the account.

Balance: represents the balance of the account in Wei.

CodeHash: Empty string as EOA does not have any associated code.

Storage: Empty string as EOA does not have any data to store.
CONTRACT ACCOUNTS (CAS)

 Ether is owned and controlled by a piece of code known as

the smart contract instead of an entity.

 They have associated code that is kept in memory/storage on

the blockchain.

 They can get triggered and execute code in response to a

transaction or a message from other contracts. The code is

executed by Ethereum Virtual Machine (EVM) by each mining

node on the Ethereum network.


CONTRACT ACCOUNTS (CAS)
 This account has a unique address to receive Ether. However, it
does not need any private key to generate the transactions as
it is already deployed and trusted by the network.
 This account also has some other state fields:
 Nonce: number of transactions initiated by the account.
 Balance: represents the balance of the account in Wei.
 CodeHash: The hash of the smart contract code is stored in
this field.
 Storage: This field contains the data of the storage variables
within the smart contract.
TRANSACTIONS AND MESSAGES
 digitally signed data packet using a private key that contains
the instructions that, when completed, either result in a
message call or contract creation.
TYPES OF TRANSACTION
 Message call transactions:
 result in a state transition.
 A message call derives from an EOA that wants to interact
with another EOA or contract account
 Eg : sending Ether from one account to another, or
interacting with a smart contract

 Contract creation transactions:


 derives from an EOA to create a smart contract account
 result in the creation of a new contract account with the
associated code.
 Eg: deploying a storage smart contract to store data.
MESSAGES
 A message is a data packet passed between two accounts.

 data packet contains data and value(amount of Ether).

 It can either be sent via a smart contract or from an external actor in the

form of a transaction that has been digitally signed by the sender.

 Contracts can send messages to other contracts.

 Messages only exist in the execution environment and are never stored.

 Messages are produced by the contracts, whereas transactions are

produced by entities external (externally owned accounts) to the

Ethereum environment.

 A message consists of the components mentioned here:


 The sender of the message
 Recipient of the message
 Amount of Wei to transfer and message to the contract address
 Optional data field (Input data for the contract)
 The maximum amount of gas (startgas) that can be consumed
TRANSACTION VALIDATION AND
EXECUTION
 A transaction must be well-formed and RLP-encoded
without any additional trailing bytes
 The digital signature used to sign the transaction is
valid
 Transaction nonce must be equal to the sender's
account's current nonce
 gas limit must not be less than the gas used by the
transaction
 The sender's account contains enough balance to
cover the execution cost.
THE TRANSACTION SUBSTATE
Way to track the state of the contract before and after the
transaction
 Suicide set or self-destruct set: a set of accounts (if any) that will be
discarded after the transaction completes.
 Log series: allow the monitoring and notification of contract calls to the
entities external to the Ethereum environment, such as application
frontends. It works like a trigger mechanism that is executed every time a
specific function is invoked. Logs are created in response to events
occurring in the smart contract. Archived and indexable checkpoints of the
virtual machine’s code execution.
 Refund balance: amount to be refunded to the sender account after the
transaction.

Refunds are not immediately executed; the state is finalized by


determining the amount of unused gas to be refunded to the sender. In
addition to the unused gas, the sender is also refunded some allowance
TRANSACTION RECEIPTS
 structures are used to record the outcome of the transaction execution

4 Elements :
 The post-transaction state: state after the transaction has been
executed. It is encoded as a byte array.
 Gas used: total amount of gas used in the block that contains the
transaction receipt. The value is taken immediately after the transaction
execution is completed. The total gas used is expected to be a non-negative
integer.
 Set of logs: Log entries contain the logger's address, a series of log topics,
and the log data.

 The bloom filter: created from the information contained in the set of

logs. It is a probabilistic data structure that helps to identify whether an

element is likely to be in a set. It's used to Search for and retrieve data,

find transferred tokens etc


ETHER CRYPTOCURRENCY / TOKENS
ETHEREUM VIRTUAL MACHINE (EVM)

 runtime environment for smart contracts in Ethereum


 Turing complete programmable machine, which can execute
scripts to produce arbitrary outcomes.
 Ethereum Virtual Machine ensures that all transactions and smart
contracts made on the Ethereum blockchain are executed in
correct and expected manner as desired by the smart contract
code.
 facilitates DApp creation and execution on the blockchain.
 EVM is contained within the client software which is required to
run a node on Ethereum. Nodes on Ethereum keep copies of
transaction data, which the EVM processes to update the
distributed ledger.
PARTS OF EVM:
EVM (the part that runs solidity source code):
 Written in C++ and uses LLVM(Low level Virtual Machine) as its
compiler.
 full-featured virtual machine with all the features such as support for
multiple programming languages, security features, runtime
environments and more.
 Allows to write custom EVM bytecode .

Uncles:
 These are small pieces of smart contracts or data stored on the
blockchain.
 allows for you to store metadata about your program
 EVM Assembly: This is the bytecode of EVM, which you can use as
your programming language.
 EVM participates in block creation and transaction execution.
 In block creation, EVM sets standards for managing the state from
block to block. These states are stored in a Merkle Tree and hold the
ground truth state for Ethereum.
 In transaction execution, the EVM executes tasks (e.g., function
calls to a smart contract) by interpreting the instructions in Opcodes.
To get the data into bytecode, use a programming language such as
Solidity (i.e., the native programming language for smart contracts)
to compile and deploy the smart contract using bytecode.
 When the EVM executes tasks, it is limited to the amount of gas
provided by the transaction and the overall limitations of the EVM.
 Gas is a unit of measure for computing power on Ethereum.
EVM ARCHITECTURE
TYPES OF SPACE IN THE EVM
Stack:
 last-in, first-out container with a fixed size and maximum depth of
1,024 items to which values can be pushed and popped.
 Each stack item is 256 bits long. This was chosen to facilitate the
Keccak- 256 hash scheme and elliptic- curve computations.

Memory:
 This is a volatile and expandable word-addressed byte array.

Key/value store:
 This is a word-addressable word array.
 used as the long term account storage for the smart contract.

Program counter in an EVM indicates the specific instruction from


the code, that should be read and executed next by the EVM.
HOW DOES THE EVM WORK?
 Developers on Ethereum write their smart contract code in a
programming language called Solidity. The code is then translated
to byte code so that the EVM can read the instructions.
 Instructions are first broken down into ‘opcodes’.
 Every line of code is converted to opcodes so that the EVM knows
exactly how to execute a transaction.
 Every transaction on Ethereum requires a gas fee to be executed.
 The more opcodes there are, the higher your gas fees will be.
 Gas: The amount of computational effort required to execute
operations on a blockchain network. Every EVM computation
requires gas fees otherwise, the transaction will not be processed.
ETHEREUM – GAS AND FEES
 Gas is the energy fueling smart contract execution in EVM
 Gas refers to the unit that measures the amount of computational
effort required to execute specific operations on the Ethereum
network.
 The gas fee is the amount of gas used to do some operation,
multiplied by the cost per unit gas.
 The fee is paid regardless of whether a transaction succeeds or fails.
 Gas fees have to be paid in Ethereum's native currency, ether (ETH).
 Gas prices are usually quoted in gwei, which is a denomination of
ETH. Each gwei is equal to one-billionth of an ETH (0.000000001 ETH
or 10-9 ETH).
HOW ARE GAS FEES CALCULATED?
 The total gas you pay is divided into two components: the base
fee and the priority fee (tip).
 The base fee is set by the protocol - you have to pay at least this
amount for your transaction to be considered valid.
 The priority fee is a tip that you add to the base fee to make
your transaction attractive to validators so that they choose it for
inclusion in the next block.
 Max fee: To execute a transaction on the network, users can
specify a maximum limit they are willing to pay for their
transaction to be executed. This optional parameter is known as
the maxFeePerGas. For a transaction to be executed, the max fee
must exceed the sum of the base fee and the tip.
SMART CONTRACT
 Self executing contracts which contains the terms and conditions
of an agreement between the peers
 Smart contracts are the executable programs that run on the
Ethereum blockchain.
 written using specific programming languages like solidity and
vyper that compile to EVM bytecode
 allows secure and trusted transactions between anonymous
parties without consulting a central authority.
WHY SMART CONTRACTS ?
DESIGN METHODOLOGY FOR SMART
CONTRACT APPLICATION
USE CASE FOR SMART CONTRACT
ETHEREUM ARCHITECTURE
Ethereum client:
 Geth 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

web3.js library
 allows interaction with the node in the ethereum
network
DECENTRALIZED APPLICATION (DAPP)
 Dapp is an application that uses smart contracts.
 Dapp provides a user-friendly interface to smart contracts
 Dapp main components are smart contract and files for web
user interface front-end/back-end
DAPP CREATION WORKFLOW
HOW DOES ETHEREUM WORK?
 When a transaction triggers a smart contract all the nodes of the network will

execute every instruction.

 All the nodes will run the EVM as part of the block verification, where the nodes will

go through the transactions listed in the block and runs the code as triggered by the

transaction in the EVM.

 All the nodes on the network must perform the same calculations for keeping their

ledgers in sync.

 Every transaction must include:


 Gas limit.
 Transaction Fee that the sender is willing to pay for the transaction.

 If the total amount of gas needed to process the transaction is less than or equal to

the gas limit then the transaction will be processed and if the total amount of the gas

needed is more than the gas limit then the transaction will not be processed the fees

are still lost.

 Thus it is safe to send transactions with the gas limit above the estimate to increase
VARIOUS ETHEREUM CLIENTS
 Parity written in rust
 Geth written in Go

 Cpp-ethereum written in C++

 Pyethereum written in python

 Mantis written in Scala

 Harmony written in java


GETH & ETHEREUM COMMAND LINE
 It is implemented in GO language
 By installing and running geth, you can take

part in frontier
 Mine Ether

 Transfer Fund between different addresses

 Create smart contract and deploy it


WHAT ETHEREUM CLIENT CAN DO?
 Create a node
 Create an account

 Check Account Balance

 Unlock Account

 Start mining

 Transfer funds

 Add fees

 Contract creation

 Deploy Contract etc


ETHEREUM MINING & REWARDS

 Ethereum Mining is a process of creating and adding a block of


transactions to the blockchain network of Ethereum.
 All transactions taking place in the Ethereum network need to
get approved by the miners.
 Miners use a Hashing Scrypt (Ethash) to solve computationally
hard puzzles for successfully mining the blocks of
transactions, in the Ethereum Blockchain Network.
 This process helps secure the network from attacks like
hacking or manipulation of identity.
 Miners get rewards for mining and gas fee
TYPES OF ETHEREUM MINING
 Pool Mining
 Solo Mining

 Cloud Mining
POOL MINING

 Pool Mining is the easiest and fastest way to get started with
Ethereum Mining.
 Miners will work along with other people together in a single pool.
 Rewards will be shared by everyone in the pool.
 Important Factors to be considered before joining a Pool are:
 Pool size
 Minimum Payout
 Pool fee
 Pool size is the factor that determines the number of blocks you
find in the Ethereum network and its share rewards. As the
number of miners increases, the chances to get rewards also
increase.
 Minimum Payout is the minimum amount of Ethereum you need
to mine before it gets credited to your wallet.
 Pools with large Minimum Payouts are not beneficial as you will
have to wait in the same pool for a longer period before getting
your reward.
 Pool fee is the amount to be paid to continue using the pool.
This amount is percentage-based, on the amount of Ethereum
you are mining. It mainly varies between 1% to 3%
SOLO MINING

 In Ethereum Solo Mining, you will get rewarded only if you


solve the puzzle and mine the Ethereum block first.
 Solo Mining is only profitable when you have plenty of
resources
 Disadvantages:
 Electricity costs
 Space
CLOUD MINING
 In Ethereum Cloud Mining, you pay someone else with the
equipment to mine Ethereum for you.
 You pay some amount of money as fees to them for
investing their time and resources, and in return, they
provide you with the reward they gain by mining Ethereum.
HOW DOES THE MINING PROCESS
WORK?
HOW DOES THE MINING PROCESS
WORK?
 A user requests a transaction with the help of the private key of his

digital wallet account.

 Then the request is shared worldwide with the Ethereum network.

 Next, the requested transaction is added to a list of pending

transactions that need to be added to the Ethereum blockchain

network.

 The miner then verifies and validates the requested transaction and

performs a complex mathematical puzzle on the transaction data.

 Once the requested transaction is verified and it stores a copy of it in

EVM, the process of "Proof-of-Work" begins for the respective block.


HOW DOES THE MINING PROCESS WORK?

 Then, the nodes of the Ethereum Network verify that the

checksum of the state of the miner's block matches the

checksum of their updated state of EVM after execution of

all transactions.

 Only after that, the block is added to the Ethereum

Blockchain Network.

 On successfully mining the block, it rewards the miner with

some amount of Ether in their wallet.

 Then the requested transaction is approved and credited to

the respective wallet/wallets.


TOOLS TO MINE ETHEREUM
 An Ethereum wallet to store all your currency earned.
 GPU drivers or Graphics Card with a minimum of 3GB
RAM.
 A mining software suitable according to your hardware
like GPU.
 And a compatible operating system (Windows 7 or 10, 64
bit).
TYPES OF REWARDS
 Block reward
 Gas fee

 Burned fee

 Uncle /Nephew Block reward


Block reward:
 A fixed inflationary reward that only changes at forks.
 The block reward is currently set to 2ETH.

Transaction gas fees:


 Each transaction on Ethereum requires a certain amount
of gas units to execute Opcode commands on the EVM which
change the state of the network.
 The rate at which a user pays for those gas units changes
based on a block’s baseFeePerGas and the user
specified maxPriorityFeePerGas (miner tip).
 The basic formula for calculating the gas fee is
Burned fees:
 The baseFeePerGas is burned/removed from the Ethereum protocol altogether.
 To calculate the total amount of burned fees in a block you can use the
following formula:

Uncle and nephew block rewards:


 An uncle block occurs when two miners create blocks at almost the same time.
While both blocks are valid, the network can only accept one block at a time.
Therefore one block is rejected and labeled as an uncle block.
 Instead of letting this block go stale, a nephew reward equal to 1/32 of a block
reward is issued to any miner willing to later include this uncle block inside a
block they are mining. Additionally, an uncle reward is issued to the miner of
the uncle block.
 The size of the uncle reward is determined by the following formula:

 Currently its 2ETH/32=0.0652 ETH

Miner Reward = Block reward+ gas fee+ uncle block reward – burned
fee

You might also like