Unit 5 - Ethereum
From Bitcoin to Ethereum Ethereum as a Next-Gen Blockchain,
Design Philosophy of Ethereum
Enter the Ethereum Blockchain,
Ethereum Accounts,
Trie Usage, Merkle Patricia Tree,
RLP Encoding,
Ethereum Transaction and Message Structure.
Ethereum Smart Contracts,
Contract Creation
Ethereum as a Next-Gen Blockchain
• Today, it is possible to build blockchain applications with minimal knowledge of
cryptography, game theory, mathematics or complex coding, and computer science
fundamentals, thanks to Ethereum.
• With Bitcoins, decentralized peer-to-peer transaction of cryptocurrency was
possible. People realized that blockchain could be used to transact and keep track
of anything of value, not just cryptocurrency. People started exploring if the same
Bitcoin network could be used for any other use case.
• example, “proof of existence” is one such use case where the hash of a document
was injected in the Bitcoin blockchain network so that anyone could later verify
that such a document was present in so and so point in time.
Ethereum as a Next-Gen Blockchain
• Vitalik Buterin introduced the Ethereum blockchain platform that could facilitate
transactions of not just money, but also shares, lands, digital content, vehicles,
and many others that have some intrinsic value.
Ethereum as a Next-Gen Blockchain
• Like Bitcoin, Ethereum is a public blockchain platform with a different design
philosophy. The most innovative approach was to build an abstraction layer so that
transactions from different applications are generalized to the program code that
can run on all the Ethereum nodes.
• Even in Ethereum, the miners generate Ether, a tradeable cryptocurrency because
of which the public blockchain network is self-sustainable.
• Any application that is running on Ethereum has to pay transaction fees that
eventually the miners get for running the nodes and sustaining the whole
network.
Bitcoin vs Ethereum
have many similarities but there are some long-term different visions and limitations that make them two
different blockchain networks that have their pros and cons and are suitable for varying user
requirements
Basis Bitcoin Ethereum
Bitcoin (abbreviation: BTC; sign: ₿) is a decentralized Ethereum is a decentralized global software platform powered
Definition digital currency that can be transferred on the peer-to- by blockchain technology. It is most commonly known for its
peer bitcoin network. native cryptocurrency, ether (ETH).
The word bitcoin was defined in a white paper published Ethereum was conceived in 2013 by programmer Vitalik Buterin,
History on 31 October 2008. The currency began use in 2009. and then went live on 30 July 2015.
The purpose of Ethereum was to utilize blockchain technology
The purpose of bitcoin was to replace national currencies
Purpose during the financial crisis of 2008.
for maintaining a decentralized payment network and storing
computer code.
smart contracts are present, but they are not flexible
Smart Smart contracts. Bitcoin does not have all the Ethereum allows us to create smart contracts. Smart contracts
are computer codes that is stored on a blockchain and executed
Contracts functionality that a programming language would give
when the predetermined terms and conditions are met.
them.
Basis Bitcoin Ethereum
Transactions
Generally, bitcoin transactions are only for keeping Ethereum transactions may contain some executable
notes. code.
Transaction Fee Has a static transaction fee independent of any Transaction fees are based on the gas price.
data being sent
Hash Algorithm Bitcoin runs on the SHA-256 hash algorithm. Ethereum runs on the Ethash algorithm (Keccak-256)
Consensus The Proof-of-Work (PoW) is the consensus The Proof-of-Stake is the consensus mechanism used
Mechanism mechanism used by the Bitcoin network. by Ethereum.
Block Time The block time of bitcoin is 10 minutes. The block time of Ethereum is 14 to 15 seconds.
Block Limit The bitcoin blockchain has a block limit of 1 MB. The Ethereum blockchain does not have a block limit.
Popularity
Bitcoin is the most popular digital currency in the Ether, native currency of Ethereum is the second-
market to date. largest cryptocurrency after bitcoin to date.
Energy Energy consumption is very low as compared to
Energy consumption is very high.
Consumption bitcoin
Structure Structure of bitcoin is simple and robust. Structure of Ethereum is complex and feature rich
DESIGN PHILOSOPHY OF ETHEREUM
Many concepts from bitcoin but have different design philosophy. Ethereum development has been
done following certain principles as follows
Simplistic design: The Ethereum blockchain is designed to be as simple as possible so that it is easy to
understand and develop decentralized applications on.
• The complexities in the implementation are kept to a bare minimum at the consensus level and are
managed at a level above it.
• As a result, high-level language compilation or serialization/deserialization of arguments, etc. are
not a concern for the developers.
Freedom of development: The Ethereum platform is designed to encourage any sort of
decentralization on its blockchain platform and does not discriminate or favor any specific kinds of
use cases.
• This freedom is given to an extent that a developer can code up an infinite loop in a smart contract
and deploy it. Obviously, the loop will run as long as they are paying the transaction fee (gas Price),
and the loop eventually terminates when it runs out of gas.
DESIGN PHILOSOPHY OF ETHEREUM
No notion of features:
• In an effort to make the system more generalized, Ethereum does not have built-in features for
the developers to use
• Instead, Ethereum provides support for Turing-complete language and lets the users develop
their own features the way they want to
• Starting from basic features such as “lock time,” as in Bitcoin till full blown use cases, everything
can be coded up in Ethereum
Enter the Ethereum Blockchain / Core components of Ethereum
Ethereum data structure is lot more similar to BTC, but lot more information contained in the block
header to make it more robust
In Ethereum, there are three Merkle roots in total as follows
StateRoot: It helps maintain the global state.
TransactionsRoot: It is to track and ensure integrity of all the transactions in a block, similar to
Bitcoin’s Merkle root.
ReceiptsRoot: It is the root hash of the receipts trie corresponding to the transactions in a block
Please note - there could be slight variants of these names in different books, or the order in
which they are presented could be different in different places. Important is to build a proper
understanding of these fields
Section-1: Block metadata
• parentHash: Keccak 256-bit hash of the parent block’s header, similar to Bitcoin’s
• timestamp: The timestamp of current block
• number: Block number of the current block
• Beneficiary: The 160-bit address of “author” account responsible for creating the
current block to which all the fees of successfully mining a block are collected
Section-2: Data references
• transactionsRoot: The Keccak 256-bit root hash (Merkle root) of the transactions trie
populated with all the transactions in this block
• ommersHash: It is otherwise known as “uncleHash.” It is the hash of the uncles
segment of the block, i.e., Keccak 256-bit hash of the ommers list portion of this block
(blocks that are known to have a parent equal to the present block’s parent’s parent).
• extraData: Arbitrary byte array containing data relevant to this block. May become
“extraDataHash”, which will point to the “extraData” contained inside the block.
• extraData could be raw data, charged at the same amount of gas as that of
transaction data
Section-3: Transaction execution information
• stateRoot: The Keccak 256-bit root hash (Merkle root) of the final state after validating
and executing all transactions of this block
• receiptsRoot: The Keccak 256-bit root hash (Merkle root) of the receipts trie populated
with the recipients of each transaction in this block
• logBloom: The accumulated Bloom filter for each of the transactions’ receipts’ Blooms,
i.e., the “OR” of all of the Blooms for the transactions in the block
• gasUsed: The total amount of gas used through each of the transactions in this block
• gasLimit: The maximum amount of gas that this block may utilize (dynamic value
depending on the activity in the network)
Section-4: Consensus-subsystem information
• difficulty: The difficulty limit for this block calculated from the previous block’s difficulty
and timestamp
• mixHash: The 256-bits mix hash combined with the ‘nonce’ for the PoW of this block
• nonce: The nonce is a 64-bit hash that is combined with mixHash and can be used as a
ETHEREUM ACCOUNTS
• The initiation of the transaction of digital money/crypto, informs the network who is
initiating the transaction, how much value is being transferred, and to whom the value is
being transferred.
• Blockchains primarily use two types of record-keeping models, the first method is the
UTXO model (Unspent Transaction Output) model, and the second is the accounts-based
model.
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 ACCOUNTS
Ethereum uses the account-based transaction model. It represents balances
within accounts, similar to what you would see in a regular bank account.
There are two types of accounts which are
• Externally Owned Account (EOA) - An Externally Owned Account is controlled
through private keys.
• We must remember two types of keys: public and private keys. Your public key
acts just as your bank account number.
• You can share this key with other users and receive payments. The private key
is similar to your card PIN and is used to access your funds. It would be best if
you never share your private keys with anyone.
• Contract Account. - Smart contract codes control Contract Accounts. These
accounts cannot initiate transactions because private keys do not control them.
• When a user creates an Ether wallet and receives their first transaction, an
Externally Owned Account (EOA) account is created and added to the global
state, with copies of the state stored on nodes across the network.
• When a user deploys a smart contract, then a Contract Account is created. A
smart contract can hold funds that it can distribute based on the conditions
defined in the contract.
• All Ethereum accounts have a balance, storage, and code space to call other
addresses and accounts
Advantages of UTXOs and Accounts
• Better privacy: In Bitcoins, it is advisable to use a new address while receiving transactions, which helps
reinforce anonymity.
• Even with statistical or machine learning techniques, it is difficult to link the accounts together, (not
impossible)
• Potentially more scalable: scalability is usually very subjective, and depends on the context, use case at hand,
and many other factors, but UTXO’s inherent potential to scale
• It is very easy to execute the transactions in parallel. Merkle proof of ownership data makes it very robust
Advantages of Accounts: Even though Ethereum in a way is an extension to Bitcoin, new design has its own pros
and cons
• Significant space saving: In Bitcoins, multiple transactions are clubbed together to make one transaction,
hence many references to those individual transactions must be made. As many transactions as many
addresses.
• In Ethereum accounts, however, just one reference to an account is good enough.
• Ethereum uses Merkle Patricia tree (MPT) , which is a bit more space intensive than Merkle tree, helps to save
significant amount of space for complex transactions
Advantages of UTXOs and Accounts
Simple to code:
• With UTXOs and scripts that are not Turing-complete, it is difficult to design complex systems.
• UTXOs can either be spent or unspent; there is no other state possible in between. Which
makes it difficult to code up complex business logics.
• Since the objective of Ethereum is to go beyond cryptocurrency and accommodate different
kinds of use cases (through DApps), an accounts-based system is helpful
Lightweight client reference:
• Unlike Bitcoin clients, Ethereum client applications can easily and quickly access all the data
related to an account by scanning down the state tree in a specific direction.
• In the UTXO model, there are multiple references to multiple transactions associated to any
specific transaction under consideration
TRIE USAGE
• EOA or CA, Every account has a state associated with it.
• Regardless of the account type, they are tracked by the “stateRoot” Merkle root in the block
header
(Reference diagram below).
• These accounts has following four components: Accont Balance, Code Hash, Storage Root, Nonce
• So, it is the “state” trie that is responsible to keep track of the state changes of Ethereum
blockchain
• State trie: It represents the entire state (the global state) after accessing the block.
• Transaction trie: It represents all the transactions in a block keyed by index
• Receipt trie: It represents the "receipts" corresponding to each transaction. In Receipt trie’s
contains, medstate, gas_used, logs, Logbloom.
MERKLE PATRICIA TREE