0% found this document useful (0 votes)
14 views31 pages

Blockchain Unit-3

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)
14 views31 pages

Blockchain Unit-3

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/ 31

ETHEREUM

Ethereum is a blockchain with a computer embedded in it. It is the foundation for building apps
and organizations in a decentralized, permissionless, censorship-resistant way.

In the Ethereum universe, there is a single, canonical computer (called the Ethereum Virtual
Machine, or EVM) whose state everyone on the Ethereum network agrees on. Everyone who
participates in the Ethereum network (every Ethereum node) keeps a copy of the state of this
computer. Additionally, any participant can broadcast a request for this computer to perform
arbitrary computation. Whenever such a request is broadcast, other participants on the network
verify, validate, and carry out ("execute") the computation. This execution causes a state change
in the EVM, which is committed and propagated throughout the entire network.

Requests for computation are called transaction requests; the record of all transactions and the
EVM's present state gets stored on the blockchain, which in turn is stored and agreed upon by all
nodes.

Cryptographic mechanisms ensure that once transactions are verified as valid and added to the
blockchain, they can't be tampered with later. The same mechanisms also ensure that all
transactions are signed and executed with appropriate "permissions" (no one should be able to
send digital assets from Alice's account, except for Alice herself).

ETHER
Ether (ETH) is the native cryptocurrency of Ethereum. The purpose of ETH is to allow for a
market for computation. Such a market provides an economic incentive for participants to verify
and execute transaction requests and provide computational resources to the network.

Any participant who broadcasts a transaction request must also offer some amount of ETH to the
network as a bounty. The network will award this bounty to whoever eventually does the work of
verifying the transaction, executing it, committing it to the blockchain, and broadcasting it to the
network.

The amount of ETH paid corresponds to the resources required to do the computation. These
bounties also prevent malicious participants from intentionally clogging the network by
requesting the execution of infinite computation or other resource-intensive scripts, as these
participants must pay for computation resources.

ETH is also used to provide crypto-economic security to the network in three main ways: 1) it is
used as a means to reward validators who propose blocks or call out dishonest behavior by other
validators; 2) It is staked by validators, acting as collateral against dishonest behavior—if
validators attempt to misbehave their ETH can be destroyed; 3) it is used to weigh 'votes' for
newly proposed blocks, feeding into the fork-choice part of the consensus mechanism.
SMART CONTRACTS

In practice, participants don't write new code every time they want to request a computation on
the EVM. Rather, application developers upload programs (reusable snippets of code) into EVM
state, and users make requests to execute these code snippets with varying parameters. We call
the programs uploaded to and executed by the network smart contracts.

At a very basic level, you can think of a smart contract like a sort of vending machine: a script
that, when called with certain parameters, performs some actions or computation if certain
conditions are satisfied. For example, a simple vendor smart contract could create and assign
ownership of a digital asset if the caller sends ETH to a specific recipient.

Any developer can create a smart contract and make it public to the network, using the
blockchain as its data layer, for a fee paid to the network. Any user can then call the smart
contract to execute its code, again for a fee paid to the network.

Thus, with smart contracts, developers can build and deploy arbitrarily complex user-facing apps
and services such as: marketplaces, financial instruments, games, etc.

TERMINOLOGY

Blockchain

The sequence of all blocks that have been committed to the Ethereum network in the history of
the network. So named because each block contains a reference to the previous block, which
helps us maintain an ordering over all blocks (and thus over the precise history).

ETH

Ether (ETH) is the native cryptocurrency of Ethereum. Users pay ETH to other users to have
their code execution requests fulfilled.

EVM

The Ethereum Virtual Machine is the global virtual computer whose state every participant on
the Ethereum network stores and agrees on. Any participant can request the execution of
arbitrary code on the EVM; code execution changes the state of the EVM.

Nodes

The real-life machines which are storing the EVM state. Nodes communicate with each other to
propagate information about the EVM state and new state changes. Any user can also request the
execution of code by broadcasting a code execution request from a node. The Ethereum network
itself is the aggregate of all Ethereum nodes and their communications.

Accounts
Where ETH is stored. Users can initialize accounts, deposit ETH into the accounts, and transfer
ETH from their accounts to other users. Accounts and account balances are stored in a big table
in the EVM; they are a part of the overall EVM state.

Transactions

A "transaction request" is the formal term for a request for code execution on the EVM, and a
"transaction" is a fulfilled transaction request and the associated change in the EVM state. Any
user can broadcast a transaction request to the network from a node. For the transaction request
to affect the agreed-upon EVM state, it must be validated, executed, and "committed to the
network" by another node. Execution of any code causes a state change in the EVM; upon
commitment, this state change is broadcast to all nodes in the network. Some examples of
transactions:

Send X ETH from my account to Alice's account.

Publish some smart contract code into EVM state.

Execute the code of the smart contract at address X in the EVM, with arguments Y.

Blocks

The volume of transactions is very high, so transactions are "committed" in batches, or blocks.
Blocks generally contain dozens to hundreds of transactions.

Smart contracts

A reusable snippet of code (a program) which a developer publishes into EVM state. Anyone can
request that the smart contract code be executed by making a transaction request. Because
developers can write arbitrary executable applications into the EVM (games, marketplaces,
financial instruments, etc.) by publishing smart contracts, these are often also called dapps, or
Decentralized Apps.
Blockchain technology gained public notice with the advent of bitcoin in 2009. Bitcoin is
a cryptocurrency that runs on blockchain technology and is by far, the most popular and most
ranked cryptocurrency. Ethereum was initially released in 2015. Within two years of its release,
it was ranked the second best blockchain network, Bitcoin is the first. The Ethereum network
acquired more global interest when china stated that it is the best blockchain network ever
created.

Ethereum
Ethereum is a Blockchain network that introduced a built-in Turing-complete programming
language that can be used for creating various decentralized applications(also called Dapps). The
Ethereum network is fueled by its own cryptocurrency called ‘ether’.

The Ethereum network is currently famous for allowing the implementation of smart contracts.
Smart contracts can be thought of as ‘cryptographic bank lockers’ which contain certain values.

These cryptographic lockers can only be unlocked when certain conditions are met.

Unlike bitcoin, Ethereum is a network that can be applied to various other sectors.

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, that is, Proof of Work(PoW). PoS
depends on the amount of stake a node holds.

History of Ethereum
2013: Ethereum was first described in Vitalik Buterin’s white paper in 2013 with the goal of
developing decentralized applications.

2014: In 2014, EVM was specified in a paper by Gavin Wood, and the formal development of
the software also began.

2015: In 2015, Ethereum created its genesis block marking the official launch of the platform.

2018: In 2018, Ethereum took second place in Bitcoin in terms of market capitalization.

2021: In 2021, a major network upgrade named London included Ethereum improvement
proposal 1559 and introduced a mechanism for reducing transaction fee volatility.

2022: In 2022, Ethereum has shifted from PoW( Proof-of-Work ) to PoS( Proof-of-State )
consensus mechanism, which is also known as Ethereum Merge. It has reduced Ethereum’s
energy consumption by ~ 99.95%.
Features of Ethereum
Smart contracts: Ethereum allows the creation and deployment of smart contracts. Smart
contracts are created mainly using a programming language called solidity. Solidity is an Object
Oriented Programming language that is comparatively easy to learn.

Ethereum Virtual Machine (EVM): It is designed to operate as a runtime environment for


compiling and deploying Ethereum-based smart contracts.

Ether: Ether is the cryptocurrency of the Ethereum network. It is the only acceptable form of
payment for transaction fees on the Ethereum network.

Decentralized applications (Daaps): 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.

Type of Ethereum Accounts

Ethereum has two types of accounts: An externally owned account (EOA), and a Contract
account. These are explained as following below:

Externally owned account (EOA): Externally owned accounts are controlled by private keys.
Each EOA has a public-private key pair. The users can send messages by creating and signing
transactions.

Contract Account: Contract accounts are controlled by contract codes. These codes are stored
with the account. Each contract account has an ether balance associated with it. The contract
code of these accounts gets activated every time a transaction from an EOA or a message from
another contract is received by it. When the contract code activates, it allows to read/write the
message to the local storage, send messages and create contracts.

Ethereum Working
Ethereum implements an execution environment called Ethereum Virtual Machine (EVM).

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 the chances
of getting it processed.

Real-World Applications of Ethereum

Voting: Voting systems are adopting Ethereum. The results of polls are available publicly,
ensuring a transparent fair system thus eliminating voting malpractices.

Agreements: With Ethereum smart contracts, agreements and contracts can be maintained and
executed without any alteration. Ethereum can be used for creating smart contracts and for
digitally recording transactions based on them.

Banking systems: Due to the decentralized nature of the Ethereum blockchain it becomes
challenging for hackers to gain unauthorized access to the network. It also makes payments on
the Ethereum network secure, so banks are using Ethereum as a channel for making payments.

Shipping: Ethereum provides a tracking framework that helps with the tracking of cargo and
prevents goods from being misplaced.

Crowdfunding: Applying Ethereum smart contracts to blockchain-based crowdfunding platforms


helps to increase trust and information symmetry. It creates many possibilities for startups by
raising funds to create their own digital cryptocurrency.

Domain names: Ethereum name service allows crypto users to buy and manage their own
domain names on Ethereum, thus simplifying decentralized transactions without putting users to
remember long, machine-readable addresses.

Benefits of Ethereum
Availability: As the Ethereum network is decentralized so there is no downtime. Even if one
node goes down other computing nodes are available.

Privacy: Users don’t need to enter their personal credentials while using the network for
exchanges, thus allowing them to remain anonymous.

Security: Ethereum is designed to be unhackable, as the hackers have to get control of the
majority of the network nodes to exploit the network.

Less ambiguity: The smart contracts that are used as a basis for trade and agreement on
Ethereum ensure stronger contracts that differ from the normal traditional contracts which
require follow-through and interpretation.

Rapid deployment: On Ethereum decentralized networks, enterprises can easily deploy and
manage private blockchain networks instead of coding blockchain implementation from scratch.

Network size: Ethereum network can work with hundreds of nodes and millions of users.

Data coordination: Ethereum decentralized architecture better allocates information so that the
network participants don’t have to rely on a central entity to manage the system and mediate
transactions.

Drawbacks of Ethereum
Complicated programming language: Learning solidity from programming smart contracts on
Ethereum can be challenging and one of the main concerns is the scarcity of beginner-friendly
classes.

Volatile cryptocurrency: Ethereum investing can be risky as the price of Ether is very volatile,
resulting in significant gains as well as a significant loss.

Low transaction rate: Bitcoin has an average transaction rate of 7TPS and Ethereum has an
average speed of 15 TPS which is almost double that of bitcoin but it is still not enough.

Blockchain technology gained public notice with the advent of bitcoin in 2009. Bitcoin is
a cryptocurrency that runs on blockchain technology and is by far, the most popular and most
ranked cryptocurrency. Ethereum was initially released in 2015. Within two years of its release,
it was ranked the second best blockchain network, Bitcoin is the first. The Ethereum network
acquired more global interest when china stated that it is the best blockchain network ever
created.

Block in Ethereum
In Ethereum, a block is a collection of transactions and other data that are added to the Ethereum
blockchain. Each block contains a unique code called a “hash” that allows it to be distinguished
from every other block, as well as a “hash” of the previous block in the chain, linking the two.

In addition to transactions, blocks in Ethereum also contain other types of data such as smart
contract code and the results of that code being executed. Each block also includes a timestamp
and information about the miner who mined the block.

The blocks in Ethereum blockchain are added through a consensus mechanism called Proof of
Stake, which is different from Bitcoin’s Proof of Work mechanism.

Ethereum blocks are mined at a fixed rate of around 15 seconds, which makes the Ethereum
blockchain faster than Bitcoin’s, which has a block time of 10 minutes.

An Ethereum block is a collection of transactions that are processed and verified by the
network’s nodes. Each block contains a block header and body.

The block also contains the transactions themselves, which are grouped into a single Merkle tree.
This allows for efficient verification of transactions without having to include the entire block
data in the header.
Structure of Blocks

Every block in Ethereum consists of 2 main parts:

Header

Body
Header

An Ethereum block header contains several fields that provide information about the block,
miner, and current state of the network including:

1. Parent Block’s hash: The parent block’s hash, also known as the “previous block hash,” is a
reference to the hash of the previous block in the blockchain. It is included in the header of each
block in the Ethereum blockchain and is used to link blocks together in a chain. This creates a
tamper-evident and transparent way to verify the integrity of the entire blockchain.

2. Uncle Hash: An Uncle Hash is a reference to the hash of a block that is not included in the
main blockchain but is still considered valid. In Ethereum, when a miner finds a new block, other
miners may also be working on finding a new block at the same time. If two miners find a new
block at the same time, the one whose block gets added to the main blockchain first is called the
“main block”, while the other is called an “uncle block”.
The Uncle Hash is included in the header of the main block and is a reference to the hash of the
uncle block. Uncle blocks are rewarded with a smaller amount of Ether than main blocks, as a
way to incentivize miners to continue to mine even if their blocks do not make it into the main
blockchain.

By including the Uncle Hash in the block header, Ethereum allows for the recognition of work
done by miners even if the block is not included in the main chain, and also helps to promote
network security.

3. State Root: The state root is a reference to the root of the state trie in the Ethereum blockchain.
The state trie is a data structure that stores the current state of the Ethereum network, including
the balance of all accounts, the storage of all contracts, and the nonce of all accounts. The state
trie is a modified version of the Merkle trie, a data structure that allows for efficient verification
of the contents of the trie.

The state root is included in the header of each block in the Ethereum blockchain. It is a 32-byte
hash that serves as a summary of the entire state trie at a specific point in time. This allows the
entire state of the Ethereum network to be verified by only looking at the state root in the block
header, rather than having to download and verify the entire state trie.

By including the state root in the block header, Ethereum allows for a compact way to verify the
integrity of the state of the network and allows for a more efficient way to sync a node with the
Ethereum network.

4. Transaction root: The transaction root is a reference to the root of the transaction trie in the
Ethereum blockchain. The transaction trie is a data structure that stores all the transactions
included in a block. The trie allows for efficient verification of the contents of the transactions in
a block.

The transaction root is included in the header of each block in the Ethereum blockchain. It is a
32-byte hash that serves as a summary of all the transactions in the block. This allows the entire
transactions in a block to be verified by only looking at the transaction root in the block header,
rather than having to download and verify the entire transaction trie.

By including the transaction root in the block header, Ethereum allows for a compact way to
verify the integrity of the transaction in a block and allows for a more efficient way to sync a
node with the Ethereum network. This ensures that the transactions in the block are valid and
authorized.

5. Receipt root: The receipts root is a reference to the root of the receipt trie in the Ethereum
blockchain. The receipt trie is a data structure that stores the receipts of the transactions included
in a block. The receipt for a transaction contains information about the outcome of the
transaction, such as whether it was successful, the amount of gas used, and the contract address if
the transaction created a new contract.

The receipts root is included in the header of each block in the Ethereum blockchain. It is a
32-byte hash that serves as a summary of the receipts of all the transactions in the block. This
allows the entire receipts of the transactions in a block to be verified by only looking at the
receipt root in the block header, rather than having to download and verify the entire receipt trie.

By including the receipts root in the block header, Ethereum allows for a compact way to verify
the outcome of the transactions in a block and allows for a more efficient way to sync a node
with the Ethereum network. This ensures that the receipts in the block are valid and authorized.

6. Logs bloom: The logs bloom is a filter that is included in the header of each block in the
Ethereum blockchain. It is used to efficiently check if a log event from a contract execution is
included in the block. A log event is a record of an event that occurred during the execution of a
smart contract, such as a transfer of funds or a change in the state of the contract.

The logs bloom is a bit array that is constructed by taking the hashes of the log topics and setting
the corresponding bits in the array. The log topics are the indexed data, such as the address of the
contract that emitted the event and the event signature. The bloom filter allows for quick
checking of whether a log event is included in a block, without the need to scan through all the
logs in the block.

By including the logs bloom in the block header, Ethereum allows for efficient searching of logs
events without having to scan through all the logs in the block. This makes it easy to look up
events and improves the performance of searching.

7. Difficulty: The difficulty in the Ethereum block header refers to the difficulty level of the
proof-of-work algorithm that is used to validate new blocks in the Ethereum blockchain. The
difficulty level is a measure of how hard it is to find a valid block, and it is adjusted dynamically
based on the current state of the network.

The difficulty is a value that is adjusted to control the rate at which new blocks are added to the
Ethereum blockchain. The goal is to maintain a consistent block time of around 15 seconds. If
the block time is too fast, the difficulty is increased, making it harder to find new blocks, and if
the block time is too slow, the difficulty is decreased, making it easier to find new blocks.

The difficulty is encoded in the block header and is a 256-bit value, which represents a very large
number. Miners use this value to adjust their mining difficulty in order to find a new block.

By including the difficulty in the block header, Ethereum allows the network to automatically
adjust the mining difficulty to maintain a consistent block time and to ensure that the blockchain
remains secure and efficient.
8. Number: The number of blocks, also known as the block number, is included in the header of
each block in the Ethereum blockchain. It is a scalar value that represents the position of the
block in the blockchain. The first block in the Ethereum blockchain, also known as the Genesis
block, has a block number of 0.

The block number is a monotonically increasing value, which means that it increases with every
new block that is added to the blockchain. It is used to identify and reference specific blocks in
the Ethereum blockchain and to determine the current state of the blockchain.

By including the block number in the header, Ethereum allows for easy referencing and
identification of specific blocks in the blockchain, and it allows for determining the current state
of the blockchain. This helps to ensure that the blockchain remains secure and efficient.

9. Gas limit: The gas limit in the Ethereum block header is a scalar value that represents the
maximum amount of gas that can be used by the transactions in a block. Gas is the internal
pricing mechanism used in Ethereum to pay for the computation of smart contracts and
transactions on the Ethereum network.

Each transaction and smart contract execution requires a certain amount of gas, and the total gas
used in a block is limited by the gas limit. The gas limit is set by the miner who creates the
block, and it is included in the block header.

The gas limit is used to prevent a situation where the network becomes overwhelmed by too
many transactions, causing delays and increased fees. By including the gas limit in the block
header, Ethereum allows for a mechanism to control the rate at which new transactions are
processed and to ensure that the network remains secure and efficient.

The gas limit can be adjusted by the miner who mines the block, and it can be changed based on
the current state of the network. The Ethereum protocol also has a mechanism called block gas
limit, which is a dynamic algorithm that adjusts the gas limit based on the gas usage of recent
blocks.

10. Gas limit: The gas used in an Ethereum block header refers to the total amount of gas that
was consumed by all the transactions included in the block. Gas is the internal pricing
mechanism used in Ethereum to pay for the computation of smart contracts and transactions on
the Ethereum network.

Each transaction and smart contract execution requires a certain amount of gas, and the total gas
used in a block is limited by the gas limit. The gas used is included in the block header, and it is
a scalar value that represents the total amount of gas consumed by all the transactions included in
the block.
The gas used is an important metric because it helps to determine the state of the network. If the
gas used is approaching the gas limit, it may indicate that the network is congested and that
transactions are taking longer to be processed.

By including the gas used in the block header, Ethereum allows for a mechanism to track the
total amount of gas consumed by the transactions in a block and to ensure that the network
remains secure and efficient. This information can be used to monitor network usage and to
make decisions about adjustments to the gas limit or other network parameters.

11. Timestamp: The timestamp in an Ethereum block header is a scalar value that represents the
time at which the block was mined. It is a Unix timestamp, which is the number of seconds that
have elapsed since January 1, 1970, at 00:00:00 UTC.

The timestamp is included in the block header, and it is used to order the blocks in the Ethereum
blockchain. The timestamp is set by the miner who mines the block, and it is a consensus value,
meaning that all nodes in the network should have the same value for the timestamp.

The timestamp is an important value because it helps to ensure that the blockchain is
chronological and that blocks are added in the correct order. It also helps to prevent the
possibility of a miner creating multiple blocks at the same time, which would lead to a fork in the
blockchain.

By including the timestamp in the block header, Ethereum allows for a mechanism to order the
blocks in the blockchain and to ensure that the blockchain remains secure and efficient. This
information can be used to monitor network usage and to make decisions about adjustments to
the block time or other network parameters.

12. Extra data: The extra data field in an Ethereum block header, also known as the “extra data”
or “extra field,” is a 32-byte field that can be used to include additional data in the block header.
The extra data field is not used by the Ethereum protocol for any specific purpose and is intended
for use by miners or other users of the network. It can be used to include a message, signature, or
other data that may be useful for the miner or other users of the network.

The extra data field is not used by the Ethereum protocol for any specific purpose, and it is not
included in the consensus rules, which means that the nodes in the network do not need to
validate the contents of the extra data field. Miners can put whatever they want in this field,
usually, it’s used to put a message, or sometimes it’s used to put a miner’s address.

The extra data field is an optional field, and its usage is not required. Miners can choose to leave
it empty or to include any data they wish in it. The extra data field is included in the block
header, and it is a 32-byte value that can be used to include additional data in the block header.

By including the extra data field in the block header, Ethereum allows for a mechanism to
include additional information in the block header that may be useful for miners or other users of
the network. This information can be used for various purposes such as adding a message,
signature, or other data that may be useful for the miner or other users of the network.

Body

The body of an Ethereum block, also known as the “block payload” or “block data,” is a
collection of data that contains all the information necessary to execute the transactions included
in the block. The main components of the block body are the list of transactions and the list of
uncles (stale blocks).

The list of transactions in the block body contains all the transactions that were included in the
block. Each transaction includes information such as the sender’s address, the recipient’s address,
the amount of Ether to be transferred, and the amount of gas to be consumed.

The list of uncles in the block body contains all the stale blocks that were included in the block.
These stale blocks are included in the block as a reward for the miner who mined them, even
though they were not included in the main blockchain.

The body of the block is not included in the header of the block and is not used for the consensus
mechanism but is crucial for the execution of the block’s transactions and for the update of the
state trie. The block body contains the information necessary to execute the transactions included
in the block, and it is used to update the state of the Ethereum network.

By including the body of the block, Ethereum allows for a mechanism to include all the
information necessary to execute the transactions included in the block and to update the state of
the Ethereum network. The body of the block contains the list of transactions and the list of
uncles, which are used to update the state of the Ethereum network and to reward miners for their
work on the network.

The main fields in the Ethereum block body are:

1. Transactions: A list of transactions included in the block. Each transaction includes


information such as the sender’s address, the recipient’s address, the amount of Ether to be
transferred, and the amount of gas to be consumed.

2. Uncles: A list of stale blocks that were included in the block. These stale blocks are included
in the block as a reward for the miner who mined them, even though they were not included in
the main blockchain.

3. Transactions Root: A field that contains the Merkle root of the list of transactions in the block.
The Merkle root is a hash of all the transactions in the block, and it is used to prove that a
specific transaction is included in the block without having to include all the transactions in the
block header.
4. Uncle Root: A field that contains the Merkle root of the list of uncles in the block. The Merkle
root is a hash of all the uncles in the block, and it is used to prove that a specific uncle is
included in the block without having to include all the uncles in the block header.

5. Gas Limit: A field that contains the maximum amount of gas that can be used by the
transactions in the block. The gas limit is set by the miner who mines the block and is used to
prevent the network from being overwhelmed by too many transactions.

6. Gas used: A field that contains the amount of gas that was actually used by the transactions in
the block.

7. Block Reward: A field that contains the reward given to the miner who mined the block. This
reward is a combination of the block reward, the uncle reward, and the transaction fee rewards.

8. Value: The “value” field in a transaction within the Ethereum block body is used to specify the
amount of Ether that is being transferred from the sender to the recipient in the transaction. It is
an important field as it represents the value being transferred and it is used to calculate the total
value transferred in a block.

The value field is a 64-bit word (8 bytes) and the unit of value is wei, the smallest unit of Ether.
It’s important to note that the value field is optional in a transaction, if the value is not specified
then it is assumed to be zero.

The value field is used in combination with the “to” field, which specifies the address of the
recipient, to create a standard transaction. The value and the “to” fields are used to transfer Ether
from the sender’s address to the recipient’s address.

It is important to note that the value field is not used in contract creation transactions because
contracts do not have an address and therefore cannot receive Ether.

The value field plays a key role in the functionality of the Ethereum network, as it represents the
amount of Ether that is being transferred between addresses, which is used to facilitate various
types of transactions and smart contract execution.

9. Data: The data field in the block body contains all the transactions that were included in the
block by the miner. These transactions can include various types of transactions such as contract
creation, contract execution, and token transfer.

It’s important to note that the block body only contains the transaction data and not the
transaction results, the transaction results are stored in the “receipts” field which is included in
the block header.

The data field plays a critical role in the functionality of the Ethereum network, as it stores the
transactions that are executed on the Ethereum blockchain, which are used to transfer value,
create and execute smart contracts, and more.
10. To: The “to” field in a transaction within the Ethereum block body is used to specify the
recipient address to which the Ether is being transferred. It is an important field as it represents
the address of the recipient, and it is used to calculate the total value transferred to a particular
address in a block.

The “to” field is a 20-byte address in Ethereum, which is a unique identifier for an Ethereum
account. It can be a user account or a smart contract.

The “to” field is used in combination with the “value” field, which specifies the amount of Ether
that is being transferred, to create a standard transaction. The “to” and “value” fields are used to
transfer Ether from the sender’s address to the recipient’s address.

It is important to note that the “to” field is not used in contract creation transactions because
contracts are created by the sender and don’t have an address. In this case, the “to” field is set to
null. The “to” field plays a key role in the functionality of the Ethereum network, as it represents
the address of the recipient, and it is used to facilitate various types of transactions and smart
contract execution, including transfer of value and contract execution.

These fields in the block body are used to execute the transactions included in the block, and it is
used to update the state of the Ethereum network. The block body contains the information
necessary to execute the transactions included in the block, and it is used to update the state of
the Ethereum network.

SMART CONTRACT

A "smart contract" is simply a program that runs on the Ethereum blockchain. It's a collection of
code (its functions) and data (its state) that resides at a specific address on the Ethereum
blockchain.

Smart contracts are a type of Ethereum account. This means they have a balance and can be the
target of transactions. However they're not controlled by a user, instead they are deployed to the
network and run as programmed. User accounts can then interact with a smart contract by
submitting transactions that execute a function defined on the smart contract. Smart contracts can
define rules, like a regular contract, and automatically enforce them via the code. Smart contracts
cannot be deleted by default, and interactions with them are irreversible.

PERMISSIONLESS

Anyone can write a smart contract and deploy it to the network. You just need to learn how to
code in a smart contract language, and have enough ETH to deploy your contract. Deploying a
smart contract is technically a transaction, so you need to pay gas in the same way you need to
pay gas for a simple ETH transfer. However, gas costs for contract deployment are far higher.
Ethereum has developer-friendly languages for writing smart contracts:

Solidity

Vyper

More on languages

However, they must be compiled before they can be deployed so that Ethereum's virtual machine
can interpret and store the contract. More on compilation

COMPOSABILITY

Smart contracts are public on Ethereum and can be thought of as open APIs. This means you can
call other smart contracts in your own smart contract to greatly extend what's possible. Contracts
can even deploy other contracts.

Learn more about smart contract composability.

LIMITATIONS

Smart contracts alone cannot get information about "real-world" events because they can't
retrieve data from off-chain sources. This means they can't respond to events in the real world.
This is by design. Relying on external information could jeopardise consensus, which is
important for security and decentralization.

However, it is important for blockchain applications to be able to use off-chain data. The solution
is oracles which are tools that ingest off-chain data and make it available to smart contracts.

Another limitation of smart contracts is the maximum contract size. A smart contract can be a
maximum of 24KB or it will run out of gas. This can be circumnavigated by using The Diamond
Pattern(opens in a new tab).

MULTISIG CONTRACTS

Multisig (multiple-signature) contracts are smart contract accounts


that require multiple valid signatures to execute a transaction. This
is very useful for avoiding single points of failure for contracts
holding substantial amounts of ether or other tokens. Multisigs also
divide responsibility for contract execution and key management
between multiple parties and prevent the loss of a single private key
leading to irreversible loss of funds. For these reasons, multisig
contracts can be used for simple DAO governance. Multisigs require N
signatures out of M possible acceptable signatures (where N ≤ M, and
M > 1) in order to execute. N = 3, M = 5 and N = 4, M = 7 are commonly
used. A 4/7 multisig requires four out of seven possible valid
signatures. This means the funds are still retrievable even if three
signatures are lost. In this case, it also means that the majority of
key-holders must agree and sign in order for the contract to execute.

In blockchain technology, a block is a record of new transactions that have been added to the
blockchain. Each block contains a unique code called a “hash” that allows it to be distinguished
from every other block, as well as a “hash” of the previous block in the chain, linking the two.
This creates a chain of blocks, or a “blockchain,” that cannot be altered or tampered with because
any change to a block would also change its hash and would therefore no longer match the hash
of the previous block. This is what makes blockchain technology secure and tamper-proof.
The Ethereum blockchain is a decentralized platform for building decentralized applications, it is
a blockchain-based distributed computing platform, featuring smart contract functionality.

Making an Etherium Transfer.

During an ether transfer between parties, the amount, and target address are specified together
with the transaction fees. For example, consider the following transfer of funds between Alice
and Bob of 100 ether.

In the above transaction, we initiate two transfers, the first to the recipient's account, and the
second is to a miner's account. The first transfers a value of 100 ether to the recipient's account
while the second is gas fees or transaction fees sent as a reward to the miner for the creation and
validation of a block in the blockchain.

Gas.

Gas is used to measure work on the Ethereum blockchain. Each operation on the blockchain is
accompanied by fees. Operations that need more computational power cost more gas and those
needing fewer resources cost less.
Unlike the bitcoin transaction fee which is based on the kilobytes a transaction takes
up(transaction size), Ethereum chooses fees based on the length of a transaction or contract.

Gas is how fees on Ethereum are calculated. The cost of gas is the amount of work that goes into
something, in this case, solving a computational puzzle. The fee is to make sure that transactions
are intentionally initiated and that the smart contract code is safe.

At the writing of this article, the gas price for processing a transaction on Ethereum is 55.29
Gwei.

EIP-1559
This EIP is responsible for Ethereum's fee market mechanism. It got rid of the first-price auction
where bid a set amount of money to pay for the processing of their transactions. In such cases,
the highest bidder won.

This EIP added a discrete base fee for transactions to be included in the next block. Now for
users' transactions to be prioritized, a tip was added also referred to as a priority fee. If the
priority fee was paid, the miner is would be motivated to process the transaction faster.

In summary, Ethereum added a base fee, once this was paid, it guaranteed that a transaction
would be processed but it would have to 'wait in line', if a user wanted his/her transaction to get
processed faster, he/she includes a priority fee. The miner upon coming across such a transaction,
he/she would give it priority over the rest because it has higher fees.

An Ethereum Node.

An Ethereum node is a computational system that represents a business entity or a single


participant of the blockchain. A full node runs the program specified by the protocol, as stated on
the Ethereum site, the client downloads a copy of the Ethereum blockchain and verifies blocks
and keeps on updating itself as new blocks and transactions are created. It also assists others to
download and update their copies of the blocks. This is what makes it decentralized and
immutable.
Running a node is as simple as downloading the client and running it.

Each node on the blockchain has its own ways of data interpretation and synchronization.
Full nodes are nodes that are full of data, they hold data and can also distribute it from the
network. It also validates new blocks. They can also deploy smart contracts to the blockchain.
Such nodes are taxing on the computer hardware and bandwidth.
We also have light nodes which are lighter versions of the former, these hold less data. They only
receive data based on requests. Although they can verify the validity of the data, their
participation is limited in block validation.
There are also archive nodes, these store all data a full node has and constructs an archive of
historical states of the blockchain.
Full and light nodes use this data to rebuild but not retain it.

This client performs operations such as;

● Initiating a transaction
● Validating a transaction
● Mining
● Creation of new blocks
● Execution of smart contracts
● Running the EVM(The Etherium Virtual Machine)
● To run a node, you can visit this link and learn more.
● Deployment and Invocation of a Smart Contract.

As mentioned in previous articles, we write smart contracts using a high-level programming


language called solidity. The solidity code is compiled and deployed to the EVM which can host
and run multiple smart contracts at once.

As stated, a transaction can be an exchange of value or a smart contract, now, when the target
address in a transaction is a smart contract, The execution code that corresponds to the smart
contract is activated and executed in the EVM.
The transaction has a payload embedded in it, this payload is used as the input for the execution
of the smart contract. So in general, the transaction carries input that is used in the execution of
the smart contract.

The current state of the smart contract consists of values of the variables defined in the contract.
It is also possible to further update the state of the smart contract when it is executed.

The output of the execution is stored in a receipt just like with fiat transactions, all records are
noted and publicly accessible. A blockchain stores a hash of the state and the hash of the receipt.

Transactions are validated by checking timestamps, nounce combinations, and fees for
execution.

For decentralization and immutability, all miners have to execute the same smart contract code
triggered. Once a transaction is validated, it is broadcasted and gathered for later block creation
and validation.

Unlike bitcoin's cpu-based proof of work consensus protocol, Ethereum has a memory-based
proof of work which shall be discussed in later articles.

Ethereum smart contract

A smart contract is application code that resides at a specific address on the blockchain known as
a contract address. Applications can call the smart contract functions, change their state, and
initiate transactions. Smart contracts are written in programming languages such as Solidity and
Vyper, and are compiled by the Ethereum Virtual Machine into bytecode and executed on the
blockchain.

Ethereum account

There are two types of accounts in Ethereum: Externally Owned Accounts (EOA) and Contract
Accounts. An EOA is controlled by a private key, has no associated code, and can send
transactions. A contract account has an associated code that executes when it receives a
transaction from an EOA. A contract account cannot initiate transactions on its own.
Transactions must always originate from an EOA.

Ethereum transaction

A transaction in Ethereum is a signed data message sent from one Ethereum account to another.
It contains the transaction sender and recipient information, the option to include the amount of
Ether to be transferred, the smart contract bytecode, and the transaction fee the sender is willing
to pay to the network validators to have the transaction included in the blockchain, known as gas
price and limit.

How can I pay for transactions on Ethereum?

You can pay for transactions using Ether. Ether serves two purposes. First, it prevents bad actors
from congesting the network with unnecessary transactions. Second, it acts as an incentive for
users to contribute resources and validate transactions (mining). Each transaction in Ethereum
constitutes a series of operations to occur on the network (i.e. a transfer of Ether from one
account to another or a complex state-changing operation in a smart contract). Each of these
operations have a cost, which is measured in gas, the fee-measure in Ethereum. Gas fees are are
paid in Ether, and are often measured in a smaller denomination called gwei. [1 ether =
1,000,000,000 gwei (10^9)]

Where can I get Ether, and where do I store it?

You can buy Ether with fiat currency from a cryptocurrency exchange like Coinbase or Kraken.
Ether is associated with your Ethereum account. To access your account and Ether, you must
have your account address and the passphrase or the private key.

How does Ethereum work for applications?

When a transaction triggers a smart contract, all nodes of the network execute every instruction.
To do this, Ethereum implements an execution environment on the blockchain called the
Ethereum Virtual Machine (EVM). All nodes on the network run the EVM as part of the block
verification protocol. In block verification, each node goes through the transactions listed in the
block they are verifying and runs the code as triggered by the transactions in the EVM. All nodes
on the network do the same calculations to keep their ledgers in sync. Every transaction must
include a gas limit and a fee that the sender is willing to pay for the transaction. Miners have the
choice of including the transaction and collecting the fee or not. If the total amount of gas needed
to process the transaction is less than or equal to the gas limit, the transaction is processed. If the
gas expended reaches the gas limit before the transaction is completed, the transaction does not
go through and the fee is still lost. All gas not used by transaction execution is reimbursed to the
sender as Ether. This means that it's safe to send transactions with a gas limit above the
estimates.

What does signing a transaction mean?

Signing a transaction generates a signature on a transaction using the private key of the
transaction sender's account. Transactions need to be signed before they are submitted to the
network.

How can I deploy a smart contract on Ethereum?

Transactions can also be used to publish smart contract code to the Ethereum blockchain. You
can follow the transaction status with the method eth_getTransactionReceipt, which will also
return the newly created smart contract address once it’s included on the blockchain. The
resulting smart contract address cannot be chosen, as they are calculated using a hash function
and can’t be easily predicted.

A hard fork in Ethereum

A hard fork is a change to the underlying Ethereum protocol, creating new rules to improve the
protocol that are not backwards compatible. All Ethereum clients need to upgrade; otherwise,
they will be stuck on an incompatible chain following the old rules.

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.

A CONSENSUS MECHANISM
The term consensus mechanism refers to the entire stack of protocols, incentives and ideas that
allow a network of nodes to agree on the state of a blockchain.

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.

TYPES OF CONSENSUS MECHANISMS

Proof-of-work based

Like Bitcoin, Ethereum once used a proof-of-work (PoW) based consensus protocol.

Block creation

Miners compete to create new blocks filled with processed transactions. The winner shares the
new block with the rest of the network and earns some freshly minted ETH. The race is won by
the computer which is able to solve a math puzzle fastest. This produces the cryptographic link
between the current block and the block that went before. Solving this puzzle is the work in
"proof-of-work". The canonical chain is then determined by a fork-choice rule that selects the set
of blocks that have had the most work done to mine them.

Security

The network is kept secure by the fact that you'd need 51% of the network's computing power to
defraud the chain. This would require such huge investments in equipment and energy; you're
likely to spend more than you'd gain.

Proof-of-stake based

Ethereum now uses a proof-of-stake (PoS) based consensus protocol.

Block creation
Validators create blocks. One validator is randomly selected in each slot to be the block proposer.
Their consensus client requests a bundle of transactions as an 'execution payload' from their
paired execution client. They wrap this in consensus data to form a block, which they send to
other nodes on the Ethereum network. This block production is rewarded in ETH. In rare cases
when multiple possible blocks exist for a single slot, or nodes hear about blocks at different
times, the fork choice algorithm picks the block that forms the chain with the greatest weight of
attestations (where weight is the number of validators attesting scaled by their ETH balance).

Security

A proof-of-stake system is secure crypto-economically because an attacker attempting to take


control of the chain must destroy a massive amount of ETH. A system of rewards incentivizes
individual stakers to behave honestly, and penalties disincentivize stakers from acting
maliciously.

Introduction

Mining for example bitcoin or Ethereum mining is how new crypto coins are added into
circulation. At the time of writing this, we have 19,043,450 bitcoins in
circulation, 1,956,550.0 that are remaining to be mined, that is 90.683% of bitcoins issued
meaning an average of 900 bitcoins are being mined per day. Bitcoin is a limited resource and
this is enough to guarantee resistance to inflation.

Mining is also how a blockchain network confirms transactions that are gathered into blocks and
chained to form the immutable distributed ledger. The first computer that solves a
computationally taxing problem specified by the network is awarded a specific amount of coins
as a reward. For bitcoin, it is currently 6.25 bitcoins and for Ethereum, it is 2 ether.

This reward is important as it motivates participants to make sure transactions and validated, it
also attracts more people and grows the network, and the more the nodes, the more the
immutability, security but this also means more power needed, slow network, etc.

Miners prevent the double-spending problem whereby a bitcoin holder spends the same bitcoin
twice.

Mining ensures the network is secure by validating transactions, gathering them in blocks,
verifying the blocks, and finally broadcasting them to the whole blockchain.

The Etherium Incentive Model.


All actions on the Ethereum blockchain have gas fees, as discussed in the previous article, fees
make sure that all transactions are intentionally initiated and that smart contract code is safe, also
we avoid infinite loops of computational wastage in code.

Gas points specify the fees in standard values. They allow for independent cryptocurrency
valuation and computation of transaction and computational fees. Just like fiat currency in stock
markets, cryptocurrency also has market highs and lows. This however does not apply to gas
fees, gas points don't change with the financial markets.

Gas fees are paid in eth although can be denoted in gwei(Giga-Wei) which is a denomination of
eth. Wei is the smallest denomination of eth.

Operations on the blockchain such as loading from memory, storing to memory, transaction base
fee, and creation of contracts all have varying gas costs. It is a fee structure. If fees specified in
the fee structure are not met by a transaction, the transaction is rejected. This can be compared to
sending a text without sufficient airtime. The text will not be delivered because of insufficient
funds.
The following image from the Ethereum yellow paper summarizes the gas fees for different
operations on the Ethereum blockchain.

From the image we have a set of operations namely;

Wzero = {STOP, RETURN}

Wbase = {ADDRESS, ORIGIN, CALLER, CALLVALUE, CALLDATASIZE, CODESIZE,


GASPRICE, COINBASE, TIMESTAMP, NUMBER, DIFFICULTY, GASLIMIT, POP, PC,
MSIZE, GAS}
Wverylow = {ADD, SUB, NOT, LT, GT, SLT, SGT, EQ, ISZERO, AND, OR, XOR, BYTE,
CALLDATALOAD, MLOAD, MSTORE, MSTORE8, PUSH*, DUP*, SWAP*}

Wlow = {MUL, DIV, SDIV, MOD, SMOD, SIGNEXTEND}

Wmid = {ADDMOD, MULMOD, JUMP}

Whigh = {JUMPI}

The remaining amounts after execution of a transaction are returned to the source account.

Gas in blocks
A gas limit is the maximum amount of gas a block is willing to spend on a transaction.
Transactions and smart contract execution have varying gas limits, the latter is more
computationally demanding compared to a simple transaction.
For example, a block could have the following specification;

Gas Limit = 1,500,000 Units

Ether Transaction fee = 21,000

Gas Limit Per Transaction = 70 transactions per block

The above block specifies a limit of 1.5M units of gas and 21K ether transaction fees, therefore it
fits around 70 ether plain transactions. Note that these are plain ether exchange of value
transactions. Not including smart contract code execution since it will require more gas.
In this case, the number of transactions including smart contracts decreases since the gas is not
sufficient.

On the other has GasSpent is the actual amount that is spent at the end of block-creation.

The Mining Incentive Model.

The miner who solves the specified puzzle - the 'PoW winner' creates a new block and is
awarded 2 ETH at the writing of this article. The miner also gets gas points for the execution of
smart contract transactions.

Other miners who successfully solve the puzzle later ommers are also awarded an incentive
although lower than that of the winner. This ensures network security. Blocks created
by ommer participants are referred to as ommer blocks. They are also added to the chain.

Remember PoW was created for Bitcoin to make sure nobody could trick the system. For
example, for a block to be valid, it took a specific amount of time and computational
resources(10 minutes) before the computer presented a valid solution. This is a form of upfront
investment miners make with hopes of getting rewarded. In Bitcoin, this investment was
hardware whereby miners could invest millions in hardware equipment and electricity costs to
mine blocks. This has led to server farms being built around the world by the financially able for
this purpose since finding the nonce meant making trillions of guesses and the more powerful a
computer is, the higher the number of guesses it could make. Also, the larger the mining setup,
the more the cost savings which translates to a greater market share by these miners. This
although effective, works against the core principles of a blockchain - decentralization. In other
words, any system that uses a proof of work consensus mechanism such as Bitcoin is bound to
centralize at some point as the difficulty increases. In Bitcoin, mining is handled by a specific
few who have the resources leaving other miners unable to compete.

PoS(Proof of Stake) was proposed as a solution in 2011. This form of consensus mechanism
does not need costly investments in mining hardware rather mining blocks are done
by validators. In this case, instead of using costly hardware, miners invest in the native coins of
the blockchain. That is, for a validator to mine a block, he/she is required to lock coins(32 eth) or
stake them in a smart contract. Here the miner will send coins to his/her wallet address and the
smart contract holds these coins in the wallet.

Some of the benefits of such a consensus mechanism include;

Decentralization, now miners will not be the small few with huge amounts of mining resources.

Incentivised participation because now no energy will be used in mining eth.

Energy efficiency - no need for using high amounts of power to find a nonce to solve the
cryptographic puzzle.

Lower barriers of entry, unlike Bitcoin mining where one had to have a substantial amount of
computational power to participate.

The penalties for misbehavior on the network discourage malicious parties since if found out
could lose their entire stake.

More on this can be found on the Ethereum website, the link is provided in the reference section.

Summary

Stopping and operation and returning costs zero gas fees.


Every Ethereum participant on the Ethereum blockchain pays a minimum of 21000 gas for any
transaction and 32000 gas for contract creation.

Miners receive an incentive for verifying new blocks or transactions which are later added to the
blockchain, distributed ledger. The probability of solving the specified computationally taxing
puzzle specified by the network is related to the network's total mining power.
All transactions on Ethereum require fees, fees are incentives to miners. This includes smart
contract execution. Miners secure, validate, execute smart contracts, and create new blocks. This
is what they are paid for.

A GasLimit is the amount of gas spent at the end of block-creation.


Miners who solve the puzzle but don't win block creation rights are referred to as ommers.

You might also like