You are on page 1of 114

Introduction to Blockchain and Distributed Ledger

Department of Computer Science & Engineering


Course Code: 19CS3618 Semester: VI
Course Title: Introduction to Blockchain and distributed ledger Year: III
Faculty Name: Dr Pramod Kumar Naik

1
MODULE 3 :Syllabus
Ethereum Blockchain
The Ethereum network, Components of the Ethereum ecosystem, Ethereum
Virtual Machine Execution Environment, Opcodes and their meaning,
Structure of a Block, Genesis Block, Merkle tree, Geth, Transactions,
Transaction receipts, Nonce, Gas - gasPrice, gasLimit, Ether, Mining, Wallets,
Ethereum network (main net, test net)

2
Module 3
Ethereum
Blockchain
Development
7

What is
Ethereum?
What is Ethereum?
Ethereum is the open source decentralized software program that allows you to
create and deploy applications.
What is Ethereum Blockchain ?
❖ Ethereum is an operating system for Decentralized Applications and smart
contracts. The cryptocurrency generated by the Ethereum blockchain is called
Ether.

❑ Ethereum is an operating system (world computer) for Decentralized Applications (DApps)

❑ Ether is a decentralized and immutable cryptocurrency running on the Ethereum network

❑ DApps are a tamper-proof and secure way to record contracts called smart contracts

❑ DApps are not controlled by an individual or a central entity

❑ Tokens can be issued via Smart Contracts


Ethereum is a blockchain that enables you to run programs in its confided
environment.
This appears differently in relation to the Bitcoin blockchain, which just enables
you to oversee cryptocurrency.
Ethereum has a virtual machine, called the Ethereum Virtual Machine (EVM).

12
The Ethereum blockchain
Components of the Ethereum ecosystem
The Ethereum Network
The Ethereum network is a peer-to-peer network where nodes participate in order to maintain the blockchain and contribute
to the consensus mechanism. Networks can be divided into three types, based on the requirements and usage.

The mainnet
The mainnet is the current live network of Ethereum. Its network ID is 1 and its chain ID is also 1. The network and chain IDs
are used to identify the network. This can be used to explore the Ethereum blockchain.

Testnets
There is a number of testnets available for Ethereum testing. The aim of these test blockchains is to provide a testing
environment for smart contracts and DApps before being deployed to the production live blockchain.

Private nets
As the name suggests, these are private networks that can be created by generating a new genesis block. This is usually the
case in private blockchain networks, where a private group of entities start their blockchain network and use it as a
permissioned or consortium blockchain.
The Ethereum Virtual Machine (EVM)
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.

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
The Ethereum Virtual Machine (EVM)
Execution environment
There are some key elements that are required by the execution environment to execute the code. The key
parameters are provided by the execution agent; for example, a transaction. These are listed as follows:

• The system state.

• The remaining gas for execution.

• The address of the account that owns the executing code.

• The address of the sender of the transaction. This is the originating address of this execution (it can be different

from the sender).

• The gas price of the transaction that initiated the execution.

• Input data or transaction data depending on the type of executing agent. This is a byte array; in the case of a

message call, if the execution agent is a transaction, then the transaction data is included as input data.
Execution environment
• The address of the account that initiated the code execution or transaction sender. This is the address of the

sender in case the code execution is initiated by a transaction; otherwise, it is the address of the account.

• The value or transaction value. This is the amount in Wei. If the execution agent is a transaction, then it is the

transaction value.

• The code to be executed presented as a byte array that the iterator function picks up in each execution cycle.

• The block header of the current block.

• The number of message calls or contract creation transactions (CALLs, CREATEs or CREATE2s) currently in

execution.

• Permission to make modifications to the state.


Execution environment

The execution results in producing the


resulting state, the gas remaining after
the execution, the self-destruct or
suicide set, log series, and any gas
refunds.
What is Ethereum Gas?
As explained in the introduction, Gas is a unit that measures the amount of computational effort that it will
take to execute certain operations
Ethereum Gas
Ethereum Gas

1 GWei = 109 Wei


MyContract 1 Ether = 1018 Wei

func(x): 3 gas
a = x + 1 30 gas
b = 20000 gas
hash(a) 20033
Mem[0] = gas
I want to run
func(1) How Much?

User 1 GWei per gas?


Miner(s)
Meh...
(0.00002 eth)
Transaction fees / Ethereum gas prices are Super Volatile
Gas Cost

• Gas Price: current market price of a unit of Gas (in Wei)


▪ Check gas price here: https://ethgasstation.info/
▪ Is always set before a transaction by user

• Gas Limit: maximum amount of Gas user is willing to spend


• Helps to regulate load on network
• Gas Cost (used when sending transactions) is calculated by
gasLimit*gasPrice.
▪ All blocks have a Gas Limit (maximum Gas each block can use)

89
Blockchain and Ethereum architecture
How are blocks related to each other?
What is Genesis Block and why Genesis Block is needed?
The genesis block is the first block in any blockchain-based protocol. It is the basis on which additional blocks are
added to form a chain of blocks, hence the term blockchain.

Without Genesis Block, it would be really difficult for the miners to trust a blockchain and to know when and
how it started. This would be extremely impractical.
The Genesis Block
Geth
❖ Geth is the official client software provided by the Ethereum Foundation.

❖ It is written in the Go programming language. When you start geth, it connects to other Ethereum clients (also

called nodes) in the network and downloads a copy of the blockchain.

❖ It will constantly communicate with other nodes to keep it’s copy of the blockchain up to date.

❖ It also has the ability to mine blocks and add transactions to the blockchain, validate the transactions in the

block and also execute the transactions.


Ethereum is not just a digital currency

Bitcoin Ethereum

▪ Bitcoin is the first decentralised cryptocurrency created ▪ Ethereum was released in 2015 by a cryptocurrency
research and programmer named Vitalik Buterin
in 2009 by an unknown person named Satoshi
▪ A decentralised programmable platform which supports
Nakamoto
DApps (distributed applications) running smart contracts

▪ A cryptocurrency and worldwide payment system and using digital tokens

▪ Ethereum enables peer-to-peer transactions and can


▪ Bitcoin enables peer-to-peer transactions, purchase of
handle accounts, transactions as well store, execute
goods/services, long-term storage of value newly coded programming logic
Ethereum Accounts
In Ethereum,
--the state is made up of objects called "accounts",
--each account having a 20-byte address
--state transitions being direct transfers of value and information
between accounts.
An Ethereum account (address) contains four fields:
1. The nonce, a counter used to make sure each transaction can only
be processed once
2. The account's current ether balance
3. The account's contract code, if present
4. The account's storage (empty by default)
There are two types of accounts:
--Externally owned accounts: controlled by private keys and with only
Ether balance;
--Smart contract account: that has executable code
Transactions and Messages

• Transactions contain

• Signature identifying sender

• Recipient address

• Ether to send

• Data field (Optional)

• STARTGAS value

• GASPRICE value
Transaction (stored on blockchain)
• Transaction has a message, …here is snapshot from Remix, for the Ballot register()

status 0x1 Transaction mined and execution succeed


transaction hash 0xef8df4a73cac62d056d54572469b539b99cbf3944a2fb6b62830a4173b54cc11
from 0xca35b7d915458ef540ade6068dfe2f44e8fa733c
to BallotV3.register(address) 0x692a70d2e424a56d2c6c27aa97d1a86395877b3a
gas 3000000 gas
transaction cost 49000 gas
execution cost 26320 gas
hash 0xef8df4a73cac62d056d54572469b539b99cbf3944a2fb6b62830a4173b54cc11
input 0x442...c160c

decoded input { "address voter": "0x14723A09ACff6D2A60DcdF7aA4AFf308FDDC160C" }

decoded output {}
logs []
value 0 wei
MINING
IN
ETHEREUM
Mining

❑Mining is a computationally intensive work that requires a


lot of processing power and time.

❑Mining is the act of participating in a given peer


distributed cryptocurrency network in consensus.

❑The miner is subsequently rewarded for providing solutions


to challenging math problems.

❑It is done by putting the computer’s hardware to use with


mining applications.
Individual Mining
Mining Pool
Nonce
❑A nonce refers to a number or value that can only be used once. Nonces are often
used on authentication protocols and cryptographic hash functions.

❑In the context of blockchain technology, a nonce refers to a pseudo-random


number that is utilized as a counter during the process of mining.

❑The Nonce is a random whole number, which is a 32-bit (4 byte) field, which is
adjusted by the miners, so that it becomes a valid number to be used for hashing
the value of block. Nonce is the number which can be used only once.
Nonce
Thank You

You might also like